mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: Pass logger into NewAnnotationBackend. (#87812)
* Alerting: Pass logger into NewAnnotationBackend. Make it possible to pass loggers into more places for code reuse. * Mistake in passing logger
This commit is contained in:
parent
5678012f0f
commit
67fa96f88d
@ -472,7 +472,8 @@ func configureHistorianBackend(ctx context.Context, cfg setting.UnifiedAlertingS
|
|||||||
}
|
}
|
||||||
if backend == historian.BackendTypeAnnotations {
|
if backend == historian.BackendTypeAnnotations {
|
||||||
store := historian.NewAnnotationStore(ar, ds, met)
|
store := historian.NewAnnotationStore(ar, ds, met)
|
||||||
return historian.NewAnnotationBackend(store, rs, met), nil
|
annotationBackendLogger := log.New("ngalert.state.historian", "backend", "annotations")
|
||||||
|
return historian.NewAnnotationBackend(annotationBackendLogger, store, rs, met), nil
|
||||||
}
|
}
|
||||||
if backend == historian.BackendTypeLoki {
|
if backend == historian.BackendTypeLoki {
|
||||||
lcfg, err := historian.NewLokiConfig(cfg)
|
lcfg, err := historian.NewLokiConfig(cfg)
|
||||||
|
@ -41,8 +41,7 @@ type AnnotationStore interface {
|
|||||||
Save(ctx context.Context, panel *PanelKey, annotations []annotations.Item, orgID int64, logger log.Logger) error
|
Save(ctx context.Context, panel *PanelKey, annotations []annotations.Item, orgID int64, logger log.Logger) error
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAnnotationBackend(annotations AnnotationStore, rules RuleStore, metrics *metrics.Historian) *AnnotationBackend {
|
func NewAnnotationBackend(logger log.Logger, annotations AnnotationStore, rules RuleStore, metrics *metrics.Historian) *AnnotationBackend {
|
||||||
logger := log.New("ngalert.state.historian", "backend", "annotations")
|
|
||||||
return &AnnotationBackend{
|
return &AnnotationBackend{
|
||||||
store: annotations,
|
store: annotations,
|
||||||
rules: rules,
|
rules: rules,
|
||||||
|
@ -131,7 +131,8 @@ func createTestAnnotationSutWithStore(t *testing.T, annotations AnnotationStore)
|
|||||||
rules.Rules[1] = []*models.AlertRule{
|
rules.Rules[1] = []*models.AlertRule{
|
||||||
models.RuleGen.With(models.RuleMuts.WithOrgID(1), withUID("my-rule")).GenerateRef(),
|
models.RuleGen.With(models.RuleMuts.WithOrgID(1), withUID("my-rule")).GenerateRef(),
|
||||||
}
|
}
|
||||||
return NewAnnotationBackend(annotations, rules, met)
|
annotationBackendLogger := log.New("ngalert.state.historian", "backend", "annotations")
|
||||||
|
return NewAnnotationBackend(annotationBackendLogger, annotations, rules, met)
|
||||||
}
|
}
|
||||||
|
|
||||||
func createTestAnnotationBackendSutWithMetrics(t *testing.T, met *metrics.Historian) *AnnotationBackend {
|
func createTestAnnotationBackendSutWithMetrics(t *testing.T, met *metrics.Historian) *AnnotationBackend {
|
||||||
@ -144,7 +145,8 @@ func createTestAnnotationBackendSutWithMetrics(t *testing.T, met *metrics.Histor
|
|||||||
dbs := &dashboards.FakeDashboardService{}
|
dbs := &dashboards.FakeDashboardService{}
|
||||||
dbs.On("GetDashboard", mock.Anything, mock.Anything).Return(&dashboards.Dashboard{}, nil)
|
dbs.On("GetDashboard", mock.Anything, mock.Anything).Return(&dashboards.Dashboard{}, nil)
|
||||||
store := NewAnnotationStore(fakeAnnoRepo, dbs, met)
|
store := NewAnnotationStore(fakeAnnoRepo, dbs, met)
|
||||||
return NewAnnotationBackend(store, rules, met)
|
annotationBackendLogger := log.New("ngalert.state.historian", "backend", "annotations")
|
||||||
|
return NewAnnotationBackend(annotationBackendLogger, store, rules, met)
|
||||||
}
|
}
|
||||||
|
|
||||||
func createFailingAnnotationSut(t *testing.T, met *metrics.Historian) *AnnotationBackend {
|
func createFailingAnnotationSut(t *testing.T, met *metrics.Historian) *AnnotationBackend {
|
||||||
@ -155,8 +157,9 @@ func createFailingAnnotationSut(t *testing.T, met *metrics.Historian) *Annotatio
|
|||||||
}
|
}
|
||||||
dbs := &dashboards.FakeDashboardService{}
|
dbs := &dashboards.FakeDashboardService{}
|
||||||
dbs.On("GetDashboard", mock.Anything, mock.Anything).Return(&dashboards.Dashboard{}, nil)
|
dbs.On("GetDashboard", mock.Anything, mock.Anything).Return(&dashboards.Dashboard{}, nil)
|
||||||
|
annotationBackendLogger := log.New("ngalert.state.historian", "backend", "annotations")
|
||||||
store := NewAnnotationStore(fakeAnnoRepo, dbs, met)
|
store := NewAnnotationStore(fakeAnnoRepo, dbs, met)
|
||||||
return NewAnnotationBackend(store, rules, met)
|
return NewAnnotationBackend(annotationBackendLogger, store, rules, met)
|
||||||
}
|
}
|
||||||
|
|
||||||
func createAnnotation() annotations.Item {
|
func createAnnotation() annotations.Item {
|
||||||
|
@ -24,7 +24,8 @@ func BenchmarkProcessEvalResults(b *testing.B) {
|
|||||||
as.On("SaveMany", mock.Anything, mock.Anything).Return(nil)
|
as.On("SaveMany", mock.Anything, mock.Anything).Return(nil)
|
||||||
metrics := metrics.NewHistorianMetrics(prometheus.NewRegistry(), metrics.Subsystem)
|
metrics := metrics.NewHistorianMetrics(prometheus.NewRegistry(), metrics.Subsystem)
|
||||||
store := historian.NewAnnotationStore(&as, nil, metrics)
|
store := historian.NewAnnotationStore(&as, nil, metrics)
|
||||||
hist := historian.NewAnnotationBackend(store, nil, metrics)
|
annotationBackendLogger := log.New("ngalert.state.historian", "backend", "annotations")
|
||||||
|
hist := historian.NewAnnotationBackend(annotationBackendLogger, store, nil, metrics)
|
||||||
cfg := state.ManagerCfg{
|
cfg := state.ManagerCfg{
|
||||||
Historian: hist,
|
Historian: hist,
|
||||||
Tracer: tracing.InitializeTracerForTest(),
|
Tracer: tracing.InitializeTracerForTest(),
|
||||||
|
@ -234,7 +234,8 @@ func TestDashboardAnnotations(t *testing.T) {
|
|||||||
fakeAnnoRepo := annotationstest.NewFakeAnnotationsRepo()
|
fakeAnnoRepo := annotationstest.NewFakeAnnotationsRepo()
|
||||||
historianMetrics := metrics.NewHistorianMetrics(prometheus.NewRegistry(), metrics.Subsystem)
|
historianMetrics := metrics.NewHistorianMetrics(prometheus.NewRegistry(), metrics.Subsystem)
|
||||||
store := historian.NewAnnotationStore(fakeAnnoRepo, &dashboards.FakeDashboardService{}, historianMetrics)
|
store := historian.NewAnnotationStore(fakeAnnoRepo, &dashboards.FakeDashboardService{}, historianMetrics)
|
||||||
hist := historian.NewAnnotationBackend(store, nil, historianMetrics)
|
annotationBackendLogger := log.New("ngalert.state.historian", "backend", "annotations")
|
||||||
|
hist := historian.NewAnnotationBackend(annotationBackendLogger, store, nil, historianMetrics)
|
||||||
cfg := state.ManagerCfg{
|
cfg := state.ManagerCfg{
|
||||||
Metrics: metrics.NewNGAlert(prometheus.NewPedanticRegistry()).GetStateMetrics(),
|
Metrics: metrics.NewNGAlert(prometheus.NewPedanticRegistry()).GetStateMetrics(),
|
||||||
ExternalURL: nil,
|
ExternalURL: nil,
|
||||||
@ -1280,7 +1281,8 @@ func TestProcessEvalResults(t *testing.T) {
|
|||||||
stateMetrics := metrics.NewStateMetrics(reg)
|
stateMetrics := metrics.NewStateMetrics(reg)
|
||||||
m := metrics.NewHistorianMetrics(prometheus.NewRegistry(), metrics.Subsystem)
|
m := metrics.NewHistorianMetrics(prometheus.NewRegistry(), metrics.Subsystem)
|
||||||
store := historian.NewAnnotationStore(fakeAnnoRepo, &dashboards.FakeDashboardService{}, m)
|
store := historian.NewAnnotationStore(fakeAnnoRepo, &dashboards.FakeDashboardService{}, m)
|
||||||
hist := historian.NewAnnotationBackend(store, nil, m)
|
annotationBackendLogger := log.New("ngalert.state.historian", "backend", "annotations")
|
||||||
|
hist := historian.NewAnnotationBackend(annotationBackendLogger, store, nil, m)
|
||||||
clk := clock.NewMock()
|
clk := clock.NewMock()
|
||||||
cfg := state.ManagerCfg{
|
cfg := state.ManagerCfg{
|
||||||
Metrics: stateMetrics,
|
Metrics: stateMetrics,
|
||||||
|
Loading…
Reference in New Issue
Block a user