Alerting: Change logging in Alertmanager (#105704)
* change logger to ngalert.notifier and use component label * update alerting module --------- Signed-off-by: Yuri Tseretyan <yuriy.tseretyan@grafana.com>
This commit is contained in:
@@ -78,7 +78,7 @@ require (
|
||||
github.com/googleapis/go-sql-spanner v1.11.1 // @grafana/grafana-search-and-storage
|
||||
github.com/gorilla/mux v1.8.1 // @grafana/grafana-backend-group
|
||||
github.com/gorilla/websocket v1.5.4-0.20250319132907-e064f32e3674 // @grafana/grafana-app-platform-squad
|
||||
github.com/grafana/alerting v0.0.0-20250519195027-0ce55e7a1d00 // @grafana/alerting-backend
|
||||
github.com/grafana/alerting v0.0.0-20250521131632-6e476b0b04c3 // @grafana/alerting-backend
|
||||
github.com/grafana/authlib v0.0.0-20250515162837-2f4a8263eabb // @grafana/identity-access-team
|
||||
github.com/grafana/authlib/types v0.0.0-20250325095148-d6da9c164a7d // @grafana/identity-access-team
|
||||
github.com/grafana/dataplane/examples v0.0.1 // @grafana/observability-metrics
|
||||
|
||||
@@ -1569,8 +1569,8 @@ github.com/gorilla/sessions v1.2.1 h1:DHd3rPN5lE3Ts3D8rKkQ8x/0kqfeNmBAaiSi+o7Fsg
|
||||
github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM=
|
||||
github.com/gorilla/websocket v1.5.4-0.20250319132907-e064f32e3674 h1:JeSE6pjso5THxAzdVpqr6/geYxZytqFMBCOtn/ujyeo=
|
||||
github.com/gorilla/websocket v1.5.4-0.20250319132907-e064f32e3674/go.mod h1:r4w70xmWCQKmi1ONH4KIaBptdivuRPyosB9RmPlGEwA=
|
||||
github.com/grafana/alerting v0.0.0-20250519195027-0ce55e7a1d00 h1:i0IpxkT1bX96F5D/oIxDdXLu+Nz/pU4rHlmnswpVLF0=
|
||||
github.com/grafana/alerting v0.0.0-20250519195027-0ce55e7a1d00/go.mod h1:pMfhRxL2LZ3Pm8iy7VcVsb9CLYuBtjFYbf1oxgx7yFA=
|
||||
github.com/grafana/alerting v0.0.0-20250521131632-6e476b0b04c3 h1:QgV6JOePZeVOqIu0yVrjuryctEpVBvlPI04Zq25PV3c=
|
||||
github.com/grafana/alerting v0.0.0-20250521131632-6e476b0b04c3/go.mod h1:pMfhRxL2LZ3Pm8iy7VcVsb9CLYuBtjFYbf1oxgx7yFA=
|
||||
github.com/grafana/authlib v0.0.0-20250515162837-2f4a8263eabb h1:oTl2j6/4miQUYmXANp2pBuYCWA5f8NVYFfCWpczpFso=
|
||||
github.com/grafana/authlib v0.0.0-20250515162837-2f4a8263eabb/go.mod h1:PBtQaXwkFu4BAt2aXsR7w8p8NVpdjV5aJYhqRDei9Us=
|
||||
github.com/grafana/authlib/types v0.0.0-20250325095148-d6da9c164a7d h1:34E6btDAhdDOiSEyrMaYaHwnJpM8w9QKzVQZIBzLNmM=
|
||||
|
||||
@@ -114,7 +114,7 @@ func NewAlertmanager(ctx context.Context, orgID int64, cfg *setting.Cfg, store A
|
||||
return stateStore.SaveNotificationLog(context.Background(), state)
|
||||
},
|
||||
}
|
||||
l := log.New("ngalert.notifier.alertmanager", "org", orgID)
|
||||
l := log.New("ngalert.notifier")
|
||||
|
||||
opts := alertingNotify.GrafanaAlertmanagerOpts{
|
||||
ExternalURL: cfg.AppURL,
|
||||
@@ -127,9 +127,8 @@ func NewAlertmanager(ctx context.Context, orgID int64, cfg *setting.Cfg, store A
|
||||
MaxSilenceSizeBytes: cfg.UnifiedAlerting.AlertmanagerMaxSilenceSizeBytes,
|
||||
},
|
||||
EmailSender: &emailSender{ns},
|
||||
ImageProvider: newImageProvider(store, log.New("ngalert.notifier.image-provider")),
|
||||
ImageProvider: newImageProvider(store, l.New("component", "image-provider")),
|
||||
Decrypter: decryptFn,
|
||||
LoggerFactory: LoggerFactory,
|
||||
Version: setting.BuildVersion,
|
||||
TenantKey: "orgID",
|
||||
TenantID: orgID,
|
||||
@@ -149,7 +148,7 @@ func NewAlertmanager(ctx context.Context, orgID int64, cfg *setting.Cfg, store A
|
||||
DefaultConfiguration: cfg.UnifiedAlerting.DefaultConfiguration,
|
||||
Store: store,
|
||||
stateStore: stateStore,
|
||||
logger: l,
|
||||
logger: l.New("component", "alertmanager", opts.TenantKey, opts.TenantID), // similar to what the base does
|
||||
}
|
||||
|
||||
return am, nil
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"testing"
|
||||
|
||||
alertingImages "github.com/grafana/alerting/images"
|
||||
alertingLogging "github.com/grafana/alerting/logging"
|
||||
"github.com/grafana/alerting/receivers"
|
||||
alertingEmail "github.com/grafana/alerting/receivers/email"
|
||||
alertingTemplates "github.com/grafana/alerting/templates"
|
||||
@@ -17,6 +16,7 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/grafana/grafana/pkg/bus"
|
||||
"github.com/grafana/grafana/pkg/infra/log/logtest"
|
||||
"github.com/grafana/grafana/pkg/infra/tracing"
|
||||
"github.com/grafana/grafana/pkg/services/notifications"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
@@ -200,7 +200,7 @@ func createSut(t *testing.T, messageTmpl string, subjectTmpl string, emailTmpl *
|
||||
},
|
||||
Message: messageTmpl,
|
||||
Subject: subjectTmpl,
|
||||
}, receivers.Metadata{}, emailTmpl, ns, &alertingImages.UnavailableProvider{}, &alertingLogging.FakeLogger{})
|
||||
}, receivers.Metadata{}, emailTmpl, ns, &alertingImages.UnavailableProvider{}, &logtest.Fake{})
|
||||
}
|
||||
|
||||
func getSingleSentMessage(t *testing.T, ns *emailSender) *notifications.Message {
|
||||
|
||||
@@ -25,7 +25,7 @@ func newImageProvider(store store.ImageStore, logger log.Logger) alertingImages.
|
||||
return alertingImages.NewTokenProvider(&tokenStore{
|
||||
store: store,
|
||||
logger: logger,
|
||||
}, newLogWrapper(logger))
|
||||
}, logger)
|
||||
}
|
||||
|
||||
func (t tokenStore) GetImage(ctx context.Context, token string) (*alertingImages.Image, error) {
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
package notifier
|
||||
|
||||
import (
|
||||
alertingLogging "github.com/grafana/alerting/logging"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
)
|
||||
|
||||
var LoggerFactory alertingLogging.LoggerFactory = func(logger string, ctx ...any) alertingLogging.Logger {
|
||||
return &logWrapper{log.New(append([]any{logger}, ctx...)...)}
|
||||
}
|
||||
|
||||
func newLogWrapper(logger log.Logger, ctx ...any) alertingLogging.Logger {
|
||||
return &logWrapper{logger.New(ctx...)}
|
||||
}
|
||||
|
||||
type logWrapper struct {
|
||||
*log.ConcreteLogger
|
||||
}
|
||||
|
||||
func (l logWrapper) New(ctx ...any) alertingLogging.Logger {
|
||||
return logWrapper{l.ConcreteLogger.New(ctx...)}
|
||||
}
|
||||
Reference in New Issue
Block a user