From 202335bafd7eccce35e0ced4e9b942b36b2526b2 Mon Sep 17 00:00:00 2001 From: Yash Mehrotra Date: Wed, 19 Jul 2023 17:59:52 +0530 Subject: [PATCH 1/2] feat: add option to exclude alerts via labels --- api/v1/checks.go | 13 +++++++------ checks/alertmanager.go | 3 +++ fixtures/datasources/alertmanager_fail.yaml | 2 ++ 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/api/v1/checks.go b/api/v1/checks.go index 5db0c512b..c4931d62d 100644 --- a/api/v1/checks.go +++ b/api/v1/checks.go @@ -466,12 +466,13 @@ type AlertManager struct { } type AlertManagerCheck struct { - Description `yaml:",inline" json:",inline"` - Templatable `yaml:",inline" json:",inline"` - Connection `yaml:",inline" json:",inline"` - Alerts []string `yaml:"alerts" json:"alerts,omitempty" template:"true"` - Filters map[string]string `yaml:"filters" json:"filters,omitempty" template:"true"` - Ignore []string `yaml:"ignore" json:"ignore,omitempty" template:"true"` + Description `yaml:",inline" json:",inline"` + Templatable `yaml:",inline" json:",inline"` + Connection `yaml:",inline" json:",inline"` + Alerts []string `yaml:"alerts" json:"alerts,omitempty" template:"true"` + Filters map[string]string `yaml:"filters" json:"filters,omitempty" template:"true"` + ExcludeFilters map[string]string `yaml:"exclude_filters" json:"exclude_filters,omitempty" template:"true"` + Ignore []string `yaml:"ignore" json:"ignore,omitempty" template:"true"` } func (c AlertManagerCheck) GetType() string { diff --git a/checks/alertmanager.go b/checks/alertmanager.go index 6042ba29b..8b08694d9 100644 --- a/checks/alertmanager.go +++ b/checks/alertmanager.go @@ -58,6 +58,9 @@ func (c *AlertManagerChecker) Check(ctx *context.Context, extConfig external.Che for _, ignore := range check.Ignore { filters = append(filters, fmt.Sprintf("alertname!~%s", ignore)) } + for k, v := range check.ExcludeFilters { + filters = append(filters, fmt.Sprintf("%s!=%s", k, v)) + } alerts, err := client.Alert.GetAlerts(&alertmanagerAlert.GetAlertsParams{ Context: gocontext.Background(), diff --git a/fixtures/datasources/alertmanager_fail.yaml b/fixtures/datasources/alertmanager_fail.yaml index 53135591e..07f4c9ee0 100644 --- a/fixtures/datasources/alertmanager_fail.yaml +++ b/fixtures/datasources/alertmanager_fail.yaml @@ -13,6 +13,8 @@ spec: - .* ignore: - KubeScheduler.* + exclude_filters: + namespace: elastic-system transform: javascript: | var out = _.map(results, function(r) { From 6dd6060496ada8982e412fea0219c27ed0977068 Mon Sep 17 00:00:00 2001 From: Yash Mehrotra Date: Wed, 19 Jul 2023 21:41:15 +0530 Subject: [PATCH 2/2] chore: make resources --- api/v1/zz_generated.deepcopy.go | 7 +++++++ config/deploy/crd.yaml | 4 ++++ config/deploy/manifests.yaml | 4 ++++ config/schemas/canary.schema.json | 8 ++++++++ config/schemas/component.schema.json | 8 ++++++++ config/schemas/health_alertmanager.schema.json | 8 ++++++++ config/schemas/topology.schema.json | 8 ++++++++ 7 files changed, 47 insertions(+) diff --git a/api/v1/zz_generated.deepcopy.go b/api/v1/zz_generated.deepcopy.go index ced6151af..06ea04266 100644 --- a/api/v1/zz_generated.deepcopy.go +++ b/api/v1/zz_generated.deepcopy.go @@ -79,6 +79,13 @@ func (in *AlertManagerCheck) DeepCopyInto(out *AlertManagerCheck) { (*out)[key] = val } } + if in.ExcludeFilters != nil { + in, out := &in.ExcludeFilters, &out.ExcludeFilters + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } if in.Ignore != nil { in, out := &in.Ignore, &out.Ignore *out = make([]string, len(*in)) diff --git a/config/deploy/crd.yaml b/config/deploy/crd.yaml index f7011d872..8025cc621 100644 --- a/config/deploy/crd.yaml +++ b/config/deploy/crd.yaml @@ -81,6 +81,10 @@ spec: template: type: string type: object + exclude_filters: + additionalProperties: + type: string + type: object filters: additionalProperties: type: string diff --git a/config/deploy/manifests.yaml b/config/deploy/manifests.yaml index aa16e94ab..9bf34c478 100644 --- a/config/deploy/manifests.yaml +++ b/config/deploy/manifests.yaml @@ -81,6 +81,10 @@ spec: template: type: string type: object + exclude_filters: + additionalProperties: + type: string + type: object filters: additionalProperties: type: string diff --git a/config/schemas/canary.schema.json b/config/schemas/canary.schema.json index b22f5c0b7..6e3c7f41e 100644 --- a/config/schemas/canary.schema.json +++ b/config/schemas/canary.schema.json @@ -85,6 +85,14 @@ }, "type": "object" }, + "exclude_filters": { + "patternProperties": { + ".*": { + "type": "string" + } + }, + "type": "object" + }, "ignore": { "items": { "type": "string" diff --git a/config/schemas/component.schema.json b/config/schemas/component.schema.json index b93d262b2..0da815655 100644 --- a/config/schemas/component.schema.json +++ b/config/schemas/component.schema.json @@ -85,6 +85,14 @@ }, "type": "object" }, + "exclude_filters": { + "patternProperties": { + ".*": { + "type": "string" + } + }, + "type": "object" + }, "ignore": { "items": { "type": "string" diff --git a/config/schemas/health_alertmanager.schema.json b/config/schemas/health_alertmanager.schema.json index 0750a9f58..f188b6627 100644 --- a/config/schemas/health_alertmanager.schema.json +++ b/config/schemas/health_alertmanager.schema.json @@ -55,6 +55,14 @@ }, "type": "object" }, + "exclude_filters": { + "patternProperties": { + ".*": { + "type": "string" + } + }, + "type": "object" + }, "ignore": { "items": { "type": "string" diff --git a/config/schemas/topology.schema.json b/config/schemas/topology.schema.json index 2dd823626..914ab67dd 100644 --- a/config/schemas/topology.schema.json +++ b/config/schemas/topology.schema.json @@ -85,6 +85,14 @@ }, "type": "object" }, + "exclude_filters": { + "patternProperties": { + ".*": { + "type": "string" + } + }, + "type": "object" + }, "ignore": { "items": { "type": "string"