From d024612678cdaf6de2db425e856076fc34594454 Mon Sep 17 00:00:00 2001 From: Dan Hofstede Date: Thu, 13 Aug 2020 02:19:24 -0400 Subject: [PATCH] Added option to aggregate request names (#3) --- index.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 11a43a9..6bce111 100644 --- a/index.js +++ b/index.js @@ -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; @@ -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']) {