Skip to content
This repository has been archived by the owner on May 2, 2023. It is now read-only.

Commit

Permalink
feat: introduce metrics namespace for naming compatibility with artil…
Browse files Browse the repository at this point in the history
…lery plugin ensure
  • Loading branch information
Joern Fornfeist authored and hassy committed May 2, 2023
1 parent 82e38bb commit d67cfd9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,30 @@ scenarios:
count: 100
```

In order to ensure the latency metrics by [artillery-plugin-ensure](https://github.com/artilleryio/artillery-plugin-ensure) you have to specify a custom namespace for the latency metrics like this:

```yaml
config:
target: "https://my-app.acme-corp.internal"
plugins:
metrics-by-endpoint:
useOnlyRequestNames: true
metricsNamespace: "latency_metrics"
ensure: {}
ensure:
thresholds:
- "latency_metrics.response_time.orders.p95": 150
scenarios:
- flow:
- loop:
- get:
url: "/foos/{{ $loopElement }}"
name: "orders"
count: 100
```

This is due to different naming patterns for metrics in both plugins.

# License

MPL 2.0
8 changes: 5 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module.exports = { Plugin: MetricsByEndpoint };
const debug = require('debug')('plugin:metrics-by-endpoint');

let useOnlyRequestNames;
let metricsPrefix;

// NOTE: Will not work with `parallel` - need request UIDs for that
function MetricsByEndpoint(script, events) {
Expand All @@ -30,6 +31,7 @@ function MetricsByEndpoint(script, events) {
}

useOnlyRequestNames = script.config.plugins['metrics-by-endpoint'].useOnlyRequestNames || false;
metricsPrefix = script.config.plugins['metrics-by-endpoint'].metricsNamespace || 'plugins.metrics-by-endpoint';

script.config.processor.metricsByEndpoint_afterResponse = metricsByEndpoint_afterResponse;

Expand Down Expand Up @@ -61,14 +63,14 @@ function metricsByEndpoint_afterResponse(req, res, userContext, events, done) {
reqName += baseUrl;
}

const histoName = `plugins.metrics-by-endpoint.response_time.${reqName}`;
const histoName = `${metricsPrefix}.response_time.${reqName}`;

if (res.headers['server-timing']) {
const timing = getServerTimingTotal(res.headers['server-timing']);
events.emit('histogram', `plugins.metrics-by-endpoint.server-timing.${reqName}`, timing);
events.emit('histogram', `${metricsPrefix}.server-timing.${reqName}`, timing);
}

events.emit('counter', `plugins.metrics-by-endpoint.${reqName}.codes.${res.statusCode}`, 1);
events.emit('counter', `${metricsPrefix}.${reqName}.codes.${res.statusCode}`, 1);
events.emit('histogram', histoName, res.timings.phases.firstByte);
return done();
}
Expand Down

0 comments on commit d67cfd9

Please sign in to comment.