mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: Allow state history to be disabled through configuration (#61006)
* Add configuration option for if state history should be enabled * Inject no-op when history is disabled
This commit is contained in:
@@ -200,8 +200,13 @@ func (ng *AlertNG) init() error {
|
||||
AlertSender: alertsRouter,
|
||||
}
|
||||
|
||||
historian := historian.NewAnnotationHistorian(ng.annotationsRepo, ng.dashboardService)
|
||||
stateManager := state.NewManager(ng.Metrics.GetStateMetrics(), appUrl, store, ng.imageService, clk, historian)
|
||||
var history state.Historian
|
||||
if ng.Cfg.UnifiedAlerting.StateHistory.Enabled {
|
||||
history = historian.NewAnnotationHistorian(ng.annotationsRepo, ng.dashboardService)
|
||||
} else {
|
||||
history = historian.NewNopHistorian()
|
||||
}
|
||||
stateManager := state.NewManager(ng.Metrics.GetStateMetrics(), appUrl, store, ng.imageService, clk, history)
|
||||
scheduler := schedule.NewScheduler(schedCfg, stateManager)
|
||||
|
||||
// if it is required to include folder title to the alerts, we need to subscribe to changes of alert title
|
||||
|
||||
18
pkg/services/ngalert/state/historian/noop.go
Normal file
18
pkg/services/ngalert/state/historian/noop.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package historian
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/grafana/grafana/pkg/services/ngalert/models"
|
||||
"github.com/grafana/grafana/pkg/services/ngalert/state"
|
||||
)
|
||||
|
||||
// NoOpHistorian is a state.Historian that does nothing with the resulting data, to be used in contexts where history is not needed.
|
||||
type NoOpHistorian struct{}
|
||||
|
||||
func NewNopHistorian() *NoOpHistorian {
|
||||
return &NoOpHistorian{}
|
||||
}
|
||||
|
||||
func (f *NoOpHistorian) RecordStatesAsync(ctx context.Context, _ *models.AlertRule, _ []state.StateTransition) {
|
||||
}
|
||||
Reference in New Issue
Block a user