Skip to content

Commit

Permalink
Merge pull request #171 from K-Phoen/alert-manager-group-by
Browse files Browse the repository at this point in the history
Support defining default group by strategy for alertmanager
  • Loading branch information
K-Phoen authored Jul 20, 2022
2 parents ac27990 + 1b995a3 commit 22d05cc
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 8 deletions.
3 changes: 3 additions & 0 deletions api/v1alpha1/alertmanager_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ type AlertManagerSpec struct {
// +kubebuilder:validation:Required
DefaultContactPoint string `json:"default_contact_point,omitempty"`

// DefaultGroupBy is the default list of labels to group alerts by.
DefaultGroupBy []string `json:"default_group_by,omitempty"`

ContactPoints []ContactPoint `json:"contact_points,omitempty"`
Routing []RoutingPolicy `json:"routing,omitempty"`
MessageTemplates map[string]string `json:"message_templates,omitempty"`
Expand Down
6 changes: 6 additions & 0 deletions config/crd/bases/k8s.kevingomez.fr_alertmanagers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,12 @@ spec:
type: array
default_contact_point:
type: string
default_group_by:
description: DefaultGroupBy is the default list of labels to group
alerts by.
items:
type: string
type: array
message_templates:
additionalProperties:
type: string
Expand Down
4 changes: 4 additions & 0 deletions docs/usage/alerting-configuration-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ spec:
# Required.
default_contact_point: 'Contact point name'

# Default list of labels to group alerts by.
# Optional.
default_group_by: [priority, service_name]

# List of known contact points
# Required.
contact_points:
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module github.com/K-Phoen/dark
go 1.17

require (
github.com/K-Phoen/grabana v0.21.9
github.com/K-Phoen/sdk v0.11.0
github.com/K-Phoen/grabana v0.21.10
github.com/K-Phoen/sdk v0.11.1
github.com/go-logr/logr v1.2.2
github.com/onsi/ginkgo v1.16.5
github.com/onsi/gomega v1.17.0
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ github.com/Azure/go-autorest/tracing v0.6.0/go.mod h1:+vhtPC754Xsa23ID7GlGsrdKBp
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
github.com/K-Phoen/grabana v0.21.9 h1:sL0/9985lZZVfbXTyWQcxrKyNRVSe98KUc8BiTrS8V0=
github.com/K-Phoen/grabana v0.21.9/go.mod h1:sfiy/xyVZaEV6B8ePS621pLQKxy37rWMYEsfgM1qt/k=
github.com/K-Phoen/sdk v0.11.0 h1:2tf7uZYhdojMMsd1fRQu6pN7UJDobtoNDD43CemxupE=
github.com/K-Phoen/sdk v0.11.0/go.mod h1:wp7qXARaIhCYktmoOjRZ+TDMlek5nbayC+waN7vigxI=
github.com/K-Phoen/grabana v0.21.10 h1:K+ud1HHUEJqkuIptLtHzSUoWGBrY525UVmGaABZ8brE=
github.com/K-Phoen/grabana v0.21.10/go.mod h1:6uqhrx00CKcGuD26aJMA1vvfytyworzLcVLmVnHltrg=
github.com/K-Phoen/sdk v0.11.1 h1:kzuOW7AzDLdI2rghGyqTiv01czadrzeL4m96TQrRC2A=
github.com/K-Phoen/sdk v0.11.1/go.mod h1:wp7qXARaIhCYktmoOjRZ+TDMlek5nbayC+waN7vigxI=
github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ=
github.com/NYTimes/gziphandler v1.1.1/go.mod h1:n/CVRwUEOgIxrgPvAQhUUr9oeUtvrhMomdKFjzJNB0c=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
Expand Down
5 changes: 5 additions & 0 deletions internal/pkg/grafana/alertmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ func (manager *AlertManager) Configure(ctx context.Context, manifest v1alpha1.Al
managerOpts = append(managerOpts, alertmanager.DefaultContactPoint(manifest.Spec.DefaultContactPoint))
}

// default grouping labels
if len(manifest.Spec.DefaultGroupBy) != 0 {
managerOpts = append(managerOpts, alertmanager.DefaultGroupBys(manifest.Spec.DefaultGroupBy...))
}

return manager.grabanaClient.ConfigureAlertManager(ctx, alertmanager.New(managerOpts...))
}

Expand Down
1 change: 1 addition & 0 deletions vendor/github.com/K-Phoen/grabana/.goreleaser.yml

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

2 changes: 2 additions & 0 deletions vendor/github.com/K-Phoen/grabana/README.md

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

7 changes: 7 additions & 0 deletions vendor/github.com/K-Phoen/grabana/alertmanager/manager.go

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

4 changes: 4 additions & 0 deletions vendor/github.com/K-Phoen/sdk/alert-manager.go

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

4 changes: 2 additions & 2 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ github.com/Azure/go-autorest/logger
# github.com/Azure/go-autorest/tracing v0.6.0
## explicit; go 1.12
github.com/Azure/go-autorest/tracing
# github.com/K-Phoen/grabana v0.21.9
# github.com/K-Phoen/grabana v0.21.10
## explicit; go 1.16
github.com/K-Phoen/grabana
github.com/K-Phoen/grabana/alert
Expand Down Expand Up @@ -69,7 +69,7 @@ github.com/K-Phoen/grabana/variable/custom
github.com/K-Phoen/grabana/variable/datasource
github.com/K-Phoen/grabana/variable/interval
github.com/K-Phoen/grabana/variable/query
# github.com/K-Phoen/sdk v0.11.0
# github.com/K-Phoen/sdk v0.11.1
## explicit; go 1.16
github.com/K-Phoen/sdk
# github.com/PuerkitoBio/purell v1.1.1
Expand Down

0 comments on commit 22d05cc

Please sign in to comment.