Skip to content

Commit

Permalink
feat: Adability to disable metric reporting with interval of 0 (#328)
Browse files Browse the repository at this point in the history
Signed-off-by: Leonard Goodell <[email protected]>
  • Loading branch information
Lenny Goodell authored Apr 26, 2022
1 parent a90d46a commit 010839c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
6 changes: 6 additions & 0 deletions bootstrap/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"errors"
"fmt"
"io/ioutil"
"math"
"reflect"
"sync"
"time"
Expand Down Expand Up @@ -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")
Expand Down
6 changes: 6 additions & 0 deletions bootstrap/handlers/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package handlers

import (
"context"
"math"
"sync"
"time"

Expand Down Expand Up @@ -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)

Expand Down
15 changes: 15 additions & 0 deletions bootstrap/metrics/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 010839c

Please sign in to comment.