diff --git a/cmd/alertmanager/main.go b/cmd/alertmanager/main.go index 8b2757de..1fc321fc 100644 --- a/cmd/alertmanager/main.go +++ b/cmd/alertmanager/main.go @@ -383,7 +383,7 @@ func run() int { tmpl *template.Template ) - dispMetrics := dispatch.NewDispatcherMetrics(prometheus.DefaultRegisterer) + dispMetrics := dispatch.NewDispatcherMetrics(false, prometheus.DefaultRegisterer) pipelineBuilder := notify.NewPipelineBuilder(prometheus.DefaultRegisterer) configLogger := log.With(logger, "component", "configuration") configCoordinator := config.NewCoordinator( diff --git a/dispatch/dispatch.go b/dispatch/dispatch.go index 65e4dda8..a31b869b 100644 --- a/dispatch/dispatch.go +++ b/dispatch/dispatch.go @@ -39,7 +39,7 @@ type DispatcherMetrics struct { } // NewDispatcherMetrics returns a new registered DispatchMetrics. -func NewDispatcherMetrics(r prometheus.Registerer) *DispatcherMetrics { +func NewDispatcherMetrics(registerLimitMetrics bool, r prometheus.Registerer) *DispatcherMetrics { m := DispatcherMetrics{ aggrGroups: prometheus.NewGauge( prometheus.GaugeOpts{ @@ -62,7 +62,10 @@ func NewDispatcherMetrics(r prometheus.Registerer) *DispatcherMetrics { } if r != nil { - r.MustRegister(m.aggrGroups, m.processingDuration, m.aggrGroupLimitReached) + r.MustRegister(m.aggrGroups, m.processingDuration) + if registerLimitMetrics { + r.MustRegister(m.aggrGroupLimitReached) + } } return &m diff --git a/dispatch/dispatch_test.go b/dispatch/dispatch_test.go index b2dd5bb5..39575b36 100644 --- a/dispatch/dispatch_test.go +++ b/dispatch/dispatch_test.go @@ -375,7 +375,7 @@ route: timeout := func(d time.Duration) time.Duration { return time.Duration(0) } recorder := &recordStage{alerts: make(map[string]map[model.Fingerprint]*types.Alert)} lim := limits{groups: 6} - m := NewDispatcherMetrics(prometheus.NewRegistry()) + m := NewDispatcherMetrics(true, prometheus.NewRegistry()) dispatcher := NewDispatcher(alerts, route, recorder, marker, timeout, lim, logger, m) go dispatcher.Run() defer dispatcher.Stop() @@ -564,7 +564,7 @@ func TestDispatcherRace(t *testing.T) { defer alerts.Close() timeout := func(d time.Duration) time.Duration { return time.Duration(0) } - dispatcher := NewDispatcher(alerts, nil, nil, marker, timeout, nil, logger, NewDispatcherMetrics(prometheus.NewRegistry())) + dispatcher := NewDispatcher(alerts, nil, nil, marker, timeout, nil, logger, NewDispatcherMetrics(false, prometheus.NewRegistry())) go dispatcher.Run() dispatcher.Stop() } @@ -592,7 +592,7 @@ func TestDispatcherRaceOnFirstAlertNotDeliveredWhenGroupWaitIsZero(t *testing.T) timeout := func(d time.Duration) time.Duration { return d } recorder := &recordStage{alerts: make(map[string]map[model.Fingerprint]*types.Alert)} - dispatcher := NewDispatcher(alerts, route, recorder, marker, timeout, nil, logger, NewDispatcherMetrics(prometheus.NewRegistry())) + dispatcher := NewDispatcher(alerts, route, recorder, marker, timeout, nil, logger, NewDispatcherMetrics(false, prometheus.NewRegistry())) go dispatcher.Run() defer dispatcher.Stop()