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

Commit

Permalink
Added option to aggregate request names (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
dHofstede authored Aug 13, 2020
1 parent 18f825e commit d024612
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@ const url = require('url');

module.exports = { Plugin: MetricsByEndpoint };

let useOnlyRequestNames;

// NOTE: Will not work with `parallel` - need request UIDs for that
function MetricsByEndpoint(script, events) {
if (!script.config.processor) {
script.config.processor = {};
}

useOnlyRequestNames = script.config.plugins["metrics-by-endpoint-test"].useOnlyRequestNames || false;

script.config.processor.metricsByEndpoint_beforeRequest = metricsByEndpoint_beforeRequest;
script.config.processor.metricsByEndpoint_afterResponse = metricsByEndpoint_afterResponse;

Expand All @@ -33,9 +37,16 @@ function metricsByEndpoint_afterResponse(req, res, userContext, events, done) {
// TODO: If hostname is not target, keep it.
const baseUrl = url.parse(req.url).path;

let histoName = req.name ?
`${baseUrl} (${req.name})` :
`${baseUrl}`;
let histoName;

if (useOnlyRequestNames && req.name) {
histoName = req.name;
} else if (req.name) {
histoName = `${baseUrl} (${req.name})`;
} else {
histoName = baseUrl;
}

let counterName = histoName;

if (res.headers['server-timing']) {
Expand Down

0 comments on commit d024612

Please sign in to comment.