From 3608ccba216adef113208532789f8cfa59a2a599 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Mierzwa?= Date: Thu, 10 Aug 2017 22:23:47 -0700 Subject: [PATCH] Strip labels in dedup, not on pull Strippling labels should be done after alerts are deduplicated, when user requests some alerts with a filter, not during data collection from Alertmanager. When labels are stripped before dedup then they are merged into one, because labels are needed to calculate uniqueness, which means we will return wrong data --- internal/alertmanager/dedup.go | 4 ++++ internal/alertmanager/models.go | 2 -- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/internal/alertmanager/dedup.go b/internal/alertmanager/dedup.go index b20a1545a..8b2c55b32 100644 --- a/internal/alertmanager/dedup.go +++ b/internal/alertmanager/dedup.go @@ -3,8 +3,10 @@ package alertmanager import ( "sort" + "github.com/cloudflare/unsee/internal/config" "github.com/cloudflare/unsee/internal/models" "github.com/cloudflare/unsee/internal/slices" + "github.com/cloudflare/unsee/internal/transform" ) // DedupAlerts will collect alert groups from all defined Alertmanager @@ -61,6 +63,8 @@ func DedupAlerts() []models.AlertGroup { ag := models.AlertGroup(agList[0]) ag.Alerts = models.AlertList{} for _, alert := range alerts { + // strip labels user doesn't want to see in the UI + alert.Labels = transform.StripLables(config.Config.KeepLabels, config.Config.StripLabels, alert.Labels) // calculate final alert state based on the most important value found // in the list of states from all instances alertLFP := alert.LabelsFingerprint() diff --git a/internal/alertmanager/models.go b/internal/alertmanager/models.go index 65b638e6a..c1714d4a9 100644 --- a/internal/alertmanager/models.go +++ b/internal/alertmanager/models.go @@ -6,7 +6,6 @@ import ( "sync" "time" - "github.com/cloudflare/unsee/internal/config" "github.com/cloudflare/unsee/internal/mapper" "github.com/cloudflare/unsee/internal/models" "github.com/cloudflare/unsee/internal/transform" @@ -174,7 +173,6 @@ func (am *Alertmanager) pullAlerts(version string) error { } alert.Annotations, alert.Links = transform.DetectLinks(alert.Annotations) - alert.Labels = transform.StripLables(config.Config.KeepLabels, config.Config.StripLabels, alert.Labels) transform.ColorLabel(colors, "@receiver", alert.Receiver) for k, v := range alert.Labels {