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) +}