From d392df90fe4e616c2c89a7cf274911d148cf9c5a Mon Sep 17 00:00:00 2001 From: Lenny Goodell Date: Mon, 25 Apr 2022 17:11:21 -0700 Subject: [PATCH] feat: Adability to disable metric reporting with interval of 0 (#328) Signed-off-by: Leonard Goodell --- bootstrap/config/config.go | 6 ++++++ bootstrap/handlers/metrics.go | 6 ++++++ bootstrap/metrics/manager_test.go | 15 +++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/bootstrap/config/config.go b/bootstrap/config/config.go index 90f2f853..f56f6f4d 100644 --- a/bootstrap/config/config.go +++ b/bootstrap/config/config.go @@ -20,6 +20,7 @@ import ( "errors" "fmt" "io/ioutil" + "math" "reflect" "sync" "time" @@ -521,6 +522,11 @@ func (cp *Processor) listenForChanges(serviceConfig interfaces.Configuration, co break } + if interval == 0 { + lc.Infof("0 specified for metrics reporting interval. Setting to max duration to effectively disable reporting.") + interval = math.MaxInt64 + } + metricsManager := container.MetricsManagerFrom(cp.dic.Get) if metricsManager == nil { lc.Error("metrics manager not available while updating telemetry interval") diff --git a/bootstrap/handlers/metrics.go b/bootstrap/handlers/metrics.go index b3d60542..ed489c01 100644 --- a/bootstrap/handlers/metrics.go +++ b/bootstrap/handlers/metrics.go @@ -17,6 +17,7 @@ package handlers import ( "context" + "math" "sync" "time" @@ -55,6 +56,11 @@ func (s *ServiceMetrics) BootstrapHandler(ctx context.Context, wg *sync.WaitGrou return false } + if interval == 0 { + lc.Infof("0 specified for metrics reporting interval. Setting to max duration to effectively disable reporting.") + interval = math.MaxInt64 + } + reporter := metrics.NewMessageBusReporter(lc, s.serviceName, dic, telemetryConfig) manager := metrics.NewManager(lc, interval, reporter) diff --git a/bootstrap/metrics/manager_test.go b/bootstrap/metrics/manager_test.go index 71e47eac..20049e46 100644 --- a/bootstrap/metrics/manager_test.go +++ b/bootstrap/metrics/manager_test.go @@ -188,3 +188,18 @@ func TestManager_Run_Error(t *testing.T) { mockReporter.AssertExpectations(t) mockLogger.AssertExpectations(t) } + +func TestManager_ResetInterval(t *testing.T) { + mockReporter := &mocks.MetricsReporter{} + mockLogger := &mocks2.LoggingClient{} + + expected := time.Millisecond * 1 + + m := NewManager(mockLogger, expected, mockReporter) + target := m.(*manager) + assert.Equal(t, expected, target.interval) + + expected = time.Millisecond * 5 + target.ResetInterval(expected) + assert.Equal(t, expected, target.interval) +}