diff --git a/alerting/grafana_alertmanager.go b/alerting/grafana_alertmanager.go index a948c044..3375a065 100644 --- a/alerting/grafana_alertmanager.go +++ b/alerting/grafana_alertmanager.go @@ -138,7 +138,7 @@ type NotifyReceiver = notify.Receiver // Configuration is an interface for accessing Alertmanager configuration. type Configuration interface { DispatcherLimits() DispatcherLimits - InhibitRules() []*InhibitRule + InhibitRules() []InhibitRule MuteTimeIntervals() []MuteTimeInterval ReceiverIntegrations() (map[string][]*Integration, error) BuildReceiverIntegrationsFunc() func(next *GrafanaReceiver, tmpl *Template) (Notifier, error) @@ -203,15 +203,12 @@ func NewGrafanaAlertmanager(tenantKey string, tenantID int64, config *GrafanaAle } // Initialize the notification log - am.wg.Add(1) - am.notificationLog, err = nflog.New( - nflog.WithRetention(config.Nflog.Retention()), - nflog.WithSnapshot(config.Nflog.Filepath()), - nflog.WithMaintenance(config.Nflog.MaintenanceFrequency(), am.stopc, am.wg.Done, func() (int64, error) { - //TODO: There's a bug here, we need to call GC to ensure we cleanup old entries: https://github.com/grafana/alerting/issues/3 - return config.Nflog.MaintenanceFunc(am.silences) // this is wrong, we need the notification log. - }), - ) + am.notificationLog, err = nflog.New(nflog.Options{ + SnapshotFile: config.Nflog.Filepath(), + Retention: config.Nflog.Retention(), + Logger: logger, + }) + if err != nil { return nil, fmt.Errorf("unable to initialize the notification log component of alerting: %w", err) } @@ -221,6 +218,18 @@ func NewGrafanaAlertmanager(tenantKey string, tenantID int64, config *GrafanaAle c = am.peer.AddState(fmt.Sprintf("silences:%d", am.tenantID), am.silences, m.Registerer) am.silences.SetBroadcast(c.Broadcast) + am.wg.Add(1) + go func() { + am.notificationLog.Maintenance(config.Nflog.MaintenanceFrequency(), config.Silences.Filepath(), am.stopc, func() (int64, error) { + if _, err := am.notificationLog.GC(); err != nil { + level.Error(am.logger).Log("notification log garbage collection", "err", err) + } + + return config.Nflog.MaintenanceFunc(am.silences) + }) + am.wg.Done() + }() + am.wg.Add(1) go func() { am.silences.Maintenance(config.Silences.MaintenanceFrequency(), config.Silences.Filepath(), am.stopc, func() (int64, error) { diff --git a/go.mod b/go.mod index c4e62c4a..0ea12b48 100644 --- a/go.mod +++ b/go.mod @@ -83,7 +83,7 @@ require ( gopkg.in/yaml.v2 v2.4.0 // indirect ) -replace github.com/prometheus/alertmanager => github.com/grafana/prometheus-alertmanager v0.25.1-0.20230109182643-002d8ba820f6 +replace github.com/prometheus/alertmanager => github.com/grafana/prometheus-alertmanager v0.25.1-0.20230119183635-ec19b0a443b7 replace github.com/Unknwon/com v1.0.1 => github.com/unknwon/com v1.0.1 diff --git a/go.sum b/go.sum index e88469e0..982e965f 100644 --- a/go.sum +++ b/go.sum @@ -222,8 +222,8 @@ github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= -github.com/grafana/prometheus-alertmanager v0.25.1-0.20230109182643-002d8ba820f6 h1:teookZDfQHNJWhsXujYZLhIeLFWzZZtqeqqfkQwOcLI= -github.com/grafana/prometheus-alertmanager v0.25.1-0.20230109182643-002d8ba820f6/go.mod h1:MnBfDPXJqXmmfPwQlCLvVUdqfnvrAw+hSPtDeaaFwj4= +github.com/grafana/prometheus-alertmanager v0.25.1-0.20230119183635-ec19b0a443b7 h1:ma1CfisUaAXQzL24tCao9yMleZYsFJ853m2l0rgahyE= +github.com/grafana/prometheus-alertmanager v0.25.1-0.20230119183635-ec19b0a443b7/go.mod h1:MnBfDPXJqXmmfPwQlCLvVUdqfnvrAw+hSPtDeaaFwj4= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I= github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=