Skip to content

Commit

Permalink
Merge pull request #1164 from flanksource/alertman-exlclude-labels
Browse files Browse the repository at this point in the history
feat: add option to exclude alerts via labels
  • Loading branch information
moshloop authored Jul 20, 2023
2 parents 18b21dd + 6dd6060 commit 5ab2298
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 6 deletions.
13 changes: 7 additions & 6 deletions api/v1/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions api/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions checks/alertmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
4 changes: 4 additions & 0 deletions config/deploy/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ spec:
template:
type: string
type: object
exclude_filters:
additionalProperties:
type: string
type: object
filters:
additionalProperties:
type: string
Expand Down
4 changes: 4 additions & 0 deletions config/deploy/manifests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ spec:
template:
type: string
type: object
exclude_filters:
additionalProperties:
type: string
type: object
filters:
additionalProperties:
type: string
Expand Down
8 changes: 8 additions & 0 deletions config/schemas/canary.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@
},
"type": "object"
},
"exclude_filters": {
"patternProperties": {
".*": {
"type": "string"
}
},
"type": "object"
},
"ignore": {
"items": {
"type": "string"
Expand Down
8 changes: 8 additions & 0 deletions config/schemas/component.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@
},
"type": "object"
},
"exclude_filters": {
"patternProperties": {
".*": {
"type": "string"
}
},
"type": "object"
},
"ignore": {
"items": {
"type": "string"
Expand Down
8 changes: 8 additions & 0 deletions config/schemas/health_alertmanager.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@
},
"type": "object"
},
"exclude_filters": {
"patternProperties": {
".*": {
"type": "string"
}
},
"type": "object"
},
"ignore": {
"items": {
"type": "string"
Expand Down
8 changes: 8 additions & 0 deletions config/schemas/topology.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@
},
"type": "object"
},
"exclude_filters": {
"patternProperties": {
".*": {
"type": "string"
}
},
"type": "object"
},
"ignore": {
"items": {
"type": "string"
Expand Down
2 changes: 2 additions & 0 deletions fixtures/datasources/alertmanager_fail.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ spec:
- .*
ignore:
- KubeScheduler.*
exclude_filters:
namespace: elastic-system
transform:
javascript: |
var out = _.map(results, function(r) {
Expand Down

0 comments on commit 5ab2298

Please sign in to comment.