From 7bac3d89c0ea926a1c560c3d24daf17470ae85fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Mierzwa?= Date: Sat, 3 Jun 2017 18:29:38 -0700 Subject: [PATCH] Deduplicate groups --- timer.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/timer.go b/timer.go index 127b6a0cc..42e7a467e 100644 --- a/timer.go +++ b/timer.go @@ -66,8 +66,17 @@ func PullFromAlertmanager() { metricAlerts.With(prometheus.Labels{"state": state}).Set(0) } - log.Infof("Processing alert groups (%d)", len(alertGroups)) + log.Infof("Deduplicating alert groups (%d)", len(alertGroups)) + uniqueGroups := map[string]models.AlertGroup{} for _, ag := range alertGroups { + agID := fmt.Sprintf("%x", structhash.Sha1(ag.Labels, 1)) + if _, found := uniqueGroups[agID]; !found { + uniqueGroups[agID] = ag + } + } + + log.Infof("Processing unique alert groups (%d)", len(uniqueGroups)) + for _, ag := range uniqueGroups { // used to generate group content hash agHasher := sha1.New()