From a4b2db1e286052fbd0383cdb7be430590502c5dc Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Mon, 28 Oct 2024 08:07:27 +0000 Subject: [PATCH] fix: fix metric group timers (#2789) 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') + }) })