From 7010ea7ba40c15c91c28265abb7fb0d200df0500 Mon Sep 17 00:00:00 2001 From: Anthony Casagrande Date: Fri, 12 May 2023 16:11:27 -0700 Subject: [PATCH] fix(metrics): do not use shared DefaultRegistry and fix wg.Done call Signed-off-by: Anthony Casagrande --- bootstrap/metrics/manager.go | 7 ++++--- bootstrap/metrics/reporter_test.go | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/bootstrap/metrics/manager.go b/bootstrap/metrics/manager.go index fc76d769..50c31632 100644 --- a/bootstrap/metrics/manager.go +++ b/bootstrap/metrics/manager.go @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright 2022 Intel Corp. + * Copyright 2022-2023 Intel Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at @@ -51,7 +51,7 @@ func (m *manager) ResetInterval(interval time.Duration) { func NewManager(lc logger.LoggingClient, interval time.Duration, reporter interfaces.MetricsReporter) interfaces.MetricsManager { m := &manager{ lc: lc, - registry: gometrics.DefaultRegistry, + registry: gometrics.NewRegistry(), reporter: reporter, interval: interval, metricTags: make(map[string]map[string]string), @@ -100,9 +100,10 @@ func (m *manager) Run(ctx context.Context, wg *sync.WaitGroup) { m.ticker = time.NewTicker(m.interval) wg.Add(1) - defer wg.Done() go func() { + defer wg.Done() + for { select { case <-ctx.Done(): diff --git a/bootstrap/metrics/reporter_test.go b/bootstrap/metrics/reporter_test.go index bf879b4e..57cccbc3 100644 --- a/bootstrap/metrics/reporter_test.go +++ b/bootstrap/metrics/reporter_test.go @@ -113,7 +113,7 @@ func TestMessageBusReporter_Report(t *testing.T) { expectedTags) require.NoError(t, err) - reg := gometrics.DefaultRegistry + reg := gometrics.NewRegistry() counter := gometrics.NewCounter() counter.Inc(intValue)