Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/karma/tests/testscript/059_log_full_config_env.txt
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ level=info msg=" - keep2"
level=info msg=" strip:"
level=info msg=" - strip1"
level=info msg=" - strip2"
level=info msg=" stripIfDuplicated: []"
level=info msg="silences:"
level=info msg=" expired: 1s"
level=info msg=" comments:"
Expand Down
1 change: 1 addition & 0 deletions cmd/karma/tests/testscript/060_log_full_config_file.txt
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ level=info msg=" - keep2"
level=info msg=" strip:"
level=info msg=" - strip1"
level=info msg=" - strip2"
level=info msg=" stripIfDuplicated: []"
level=info msg="silences:"
level=info msg=" expired: 5m0s"
level=info msg=" comments:"
Expand Down
1 change: 1 addition & 0 deletions cmd/karma/tests/testscript/065_proxy-with-readonly.txt
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ level=info msg=" timestamp: false"
level=info msg="receivers:"
level=info msg=" keep: []"
level=info msg=" strip: []"
level=info msg=" stripIfDuplicated: []"
level=info msg="silences:"
level=info msg=" expired: 10m0s"
level=info msg=" comments:"
Expand Down
1 change: 1 addition & 0 deletions cmd/karma/tests/testscript/066_proxy.txt
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ level=info msg=" timestamp: false"
level=info msg="receivers:"
level=info msg=" keep: []"
level=info msg=" strip: []"
level=info msg=" stripIfDuplicated: []"
level=info msg="silences:"
level=info msg=" expired: 10m0s"
level=info msg=" comments:"
Expand Down
1 change: 1 addition & 0 deletions cmd/karma/tests/testscript/067_readonly.txt
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ level=info msg=" timestamp: false"
level=info msg="receivers:"
level=info msg=" keep: []"
level=info msg=" strip: []"
level=info msg=" stripIfDuplicated: []"
level=info msg="silences:"
level=info msg=" expired: 10m0s"
level=info msg=" comments:"
Expand Down
1 change: 1 addition & 0 deletions cmd/karma/tests/testscript/070_upper_case_keys.txt
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ level=info msg=" timestamp: false"
level=info msg="receivers:"
level=info msg=" keep: []"
level=info msg=" strip: []"
level=info msg=" stripIfDuplicated: []"
level=info msg="silences:"
level=info msg=" expired: 10m0s"
level=info msg=" comments:"
Expand Down
1 change: 1 addition & 0 deletions cmd/karma/tests/testscript/097_proxy_url_config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ level=info msg=" timestamp: false"
level=info msg="receivers:"
level=info msg=" keep: []"
level=info msg=" strip: []"
level=info msg=" stripIfDuplicated: []"
level=info msg="silences:"
level=info msg=" expired: 10m0s"
level=info msg=" comments:"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ level=info msg=" timestamp: false"
level=info msg="receivers:"
level=info msg=" keep: []"
level=info msg=" strip: []"
level=info msg=" stripIfDuplicated: []"
level=info msg="silences:"
level=info msg=" expired: 10m0s"
level=info msg=" comments:"
Expand Down
6 changes: 5 additions & 1 deletion docs/CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -1211,18 +1211,22 @@ silences:

`receivers` section allows configuring how alerts from different receivers are
handled by karma. If alerts are routed to multiple receivers they can be
duplicated in the UI, each instance will have different value for `@receiver`.
duplicated in the UI unless the receiver is listed in `stripIfDuplicated`. Each
instance will have different value for `@receiver`.
Syntax:

```YAML
receivers:
keep: list of strings
strip: list of strings
stripIfDuplicated: list of strings
```

- `keep` - list of receivers name that are allowed, if empty all receivers are
allowed.
- `strip` - list of receiver names that will not be shown in the UI.
- `stripIfDuplicated` - list of receiver names to consider when hiding
duplicated alerts.

Example where alerts that are routed to the `alertmanage2es` receiver are
ignored by karma.
Expand Down
1 change: 1 addition & 0 deletions docs/example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ silences:
receivers:
keep: []
strip: []
stripIfDuplicated: []
silenceForm:
strip:
labels:
Expand Down
28 changes: 28 additions & 0 deletions internal/alertmanager/dedup.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,25 @@
}
}

// map of alerts fingerprints to list of receivers, taking into account strip/keep configuration
receiversMap := map[string][]string{}
for _, agList := range uniqueGroups {
for _, ag := range agList {
for _, alert := range ag.Alerts {
lfp := alert.LabelsFingerprint()
a, found := receiversMap[lfp]
if transform.StripReceivers(config.Config.Receivers.Keep, config.Config.Receivers.Strip, alert.Receiver) {
continue
}
if found && !slices.StringInSlice(a, alert.Receiver) {
receiversMap[lfp] = append(a, alert.Receiver)
} else {
receiversMap[lfp] = []string{alert.Receiver}
}
}
}
}

dedupedGroups := []models.AlertGroup{}
alertStates := map[string][]string{}
for _, agList := range uniqueGroups {
Expand All @@ -41,6 +60,15 @@
continue
}

// skip alert if its receiver is duplicated
d, receiverFound := receiversMap[alert.LabelsFingerprint()]
if receiverFound {
if slices.StringInSlice(config.Config.Receivers.StripIfDuplicated, alert.Receiver) && len(d) > 1 {
log.Debug().Str("fingerprint", alert.Fingerprint).Strs("receivers", d).Msg("Skipping alert with duplicated receiver")
continue

Check warning on line 68 in internal/alertmanager/dedup.go

View check run for this annotation

Codecov / codecov/patch

internal/alertmanager/dedup.go#L67-L68

Added lines #L67 - L68 were not covered by tests
}
}

keep := true
for _, am := range upstreams {
if !am.healthchecksVisible {
Expand Down
2 changes: 2 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ func SetupFlags(f *pflag.FlagSet) {
"List of receivers to keep, all alerts with different receivers will be ignored")
f.StringSlice("receivers.strip", []string{},
"List of receivers to not display alerts for")
f.StringSlice("receivers.stripIfDuplicated", []string{},
"List of receivers to not display alerts for if they are duplicated for the same alert")

f.Duration("silences.expired", time.Minute*10, "Maximum age of expired silences to show on active alerts")
f.StringSlice("silenceForm.strip.labels", []string{}, "List of labels to ignore when auto-filling silence form from alerts")
Expand Down
2 changes: 2 additions & 0 deletions internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ log:
receivers:
keep: []
strip: []
stripIfDuplicated: []
silences:
expired: 10m0s
comments:
Expand Down Expand Up @@ -395,6 +396,7 @@ func TestDefaultConfig(t *testing.T) {
expectedConfig.Grid.Auto.Order = []string{}
expectedConfig.Receivers.Keep = []string{}
expectedConfig.Receivers.Strip = []string{}
expectedConfig.Receivers.StripIfDuplicated = []string{}
expectedConfig.SilenceForm.Strip.Labels = []string{}
expectedConfig.SilenceForm.DefaultAlertmanagers = []string{}

Expand Down
5 changes: 3 additions & 2 deletions internal/config/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,9 @@ type configSchema struct {
Timestamp bool
}
Receivers struct {
Keep []string
Strip []string
Keep []string
Strip []string
StripIfDuplicated []string `yaml:"stripIfDuplicated" koanf:"stripIfDuplicated"`
}
Silences struct {
Expired time.Duration
Expand Down
Loading