Skip to content

Commit f41ce81

Browse files
authored
Merge pull request #1607 from cortexproject/fix-alertmanager-notifications
Fix duplicate alertmanager notifications
2 parents 9b50718 + 3c5b442 commit f41ce81

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

pkg/alertmanager/alertmanager.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,30 +65,31 @@ func New(cfg *Config) (*Alertmanager, error) {
6565
stop: make(chan struct{}),
6666
}
6767

68+
// TODO(cortex): Build a registry that can merge metrics from multiple users.
69+
// For now, these metrics are ignored, as we can't register the same
70+
// metric twice with a single registry.
71+
localRegistry := prometheus.NewRegistry()
72+
6873
am.wg.Add(1)
6974
nflogID := fmt.Sprintf("nflog:%s", cfg.UserID)
7075
var err error
7176
am.nflog, err = nflog.New(
7277
nflog.WithRetention(cfg.Retention),
7378
nflog.WithSnapshot(filepath.Join(cfg.DataDir, nflogID)),
7479
nflog.WithMaintenance(notificationLogMaintenancePeriod, am.stop, am.wg.Done),
75-
// TODO(cortex): Build a registry that can merge metrics from multiple users.
76-
// For now, these metrics are ignored, as we can't register the same
77-
// metric twice with a single registry.
78-
nflog.WithMetrics(prometheus.NewRegistry()),
80+
nflog.WithMetrics(localRegistry),
7981
nflog.WithLogger(log.With(am.logger, "component", "nflog")),
8082
)
8183
if err != nil {
8284
return nil, fmt.Errorf("failed to create notification log: %v", err)
8385
}
86+
if cfg.Peer != nil {
87+
c := cfg.Peer.AddState("nfl:"+cfg.UserID, am.nflog, localRegistry)
88+
am.nflog.SetBroadcast(c.Broadcast)
89+
}
8490

8591
am.marker = types.NewMarker()
8692

87-
// TODO(cortex): Build a registry that can merge metrics from multiple users.
88-
// For now, these metrics are ignored, as we can't register the same
89-
// metric twice with a single registry.
90-
localRegistry := prometheus.NewRegistry()
91-
9293
silencesID := fmt.Sprintf("silences:%s", cfg.UserID)
9394
am.silences, err = silence.New(silence.Options{
9495
SnapshotFile: filepath.Join(cfg.DataDir, silencesID),

0 commit comments

Comments
 (0)