diff --git a/metrics/metrics.go b/metrics/metrics.go index 1ec2c1b46..ec4776cbf 100644 --- a/metrics/metrics.go +++ b/metrics/metrics.go @@ -83,10 +83,11 @@ func init() { } } -// report converts and reports collected metrics via OTel metrics -func report() { +// report converts and reports collected metrics via OTel metrics. +// Allow for report to be overridden in the test. +var report = func() { ctx := context.Background() - for i := 0; i < nMetrics; i++ { + for i := range nMetrics { metric := metricsBuffer[i] switch typ := metricTypes[metric.ID]; typ { case MetricTypeCounter: diff --git a/metrics/metrics_test.go b/metrics/metrics_test.go index b8be5a225..dde648c53 100644 --- a/metrics/metrics_test.go +++ b/metrics/metrics_test.go @@ -11,6 +11,9 @@ import ( // TestMetrics func TestMetrics(t *testing.T) { + // NOP report to avoid timing-based interference. + report = func() {} + inputMetrics := []Metric{ {IDELFInfoCacheHit, MetricValue(33)}, {IDELFInfoCacheMiss, MetricValue(55)},