From f1811c57e9e1fadb761e9e40643eab9ad56c9bfc Mon Sep 17 00:00:00 2001 From: achingbrain Date: Sat, 26 Oct 2024 08:35:21 +0100 Subject: [PATCH] fix: fix metric group timers We need to pass the metric label as the object key, otherwise trying to stop a group timer throws. --- .../metrics-prometheus/src/metric-group.ts | 2 +- .../test/metric-groups.spec.ts | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/metrics-prometheus/src/metric-group.ts b/packages/metrics-prometheus/src/metric-group.ts index 9909ffdd70..fc3cb6a496 100644 --- a/packages/metrics-prometheus/src/metric-group.ts +++ b/packages/metrics-prometheus/src/metric-group.ts @@ -72,7 +72,7 @@ export class PrometheusMetricGroup implements MetricGroup, CalculatedMetric { expect(reportedMetrics).to.include(`${metricName}{${metricLabel}="${metricKey1}"} ${metricValue1}`, 'did not include updated metric') expect(reportedMetrics).to.include(`${metricName}{${metricLabel}="${metricKey2}"} ${metricValue2}`, 'did not include updated metric') }) + + it('should allow grouped timers', async () => { + const metricName = randomMetricName() + const metricLabel = randomMetricName('label_') + const metricKey = randomMetricName('key_') + const metrics = prometheusMetrics()({ + logger: defaultLogger() + }) + const metric1 = metrics.registerMetricGroup(metricName, { + label: metricLabel + }) + + const timer = metric1.timer(metricKey) + + timer() + + const reportedMetrics = await client.register.metrics() + + expect(reportedMetrics).to.include(`${metricName}{${metricLabel}="${metricKey}"}`, 'did not include updated metric') + }) })