Skip to content

Commit

Permalink
Merge pull request #191 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 committed Jul 20, 2022
2 parents aeda318 + 9b30c18 commit ceff5f0
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 4 deletions.
7 changes: 7 additions & 0 deletions alertmanager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ func DefaultContactPoint(contactPoint string) Option {
}
}

// DefaultGroupBys sets the default labels that alerts should be grouped by.
func DefaultGroupBys(labels ...string) Option {
return func(manager *Manager) {
manager.builder.Config.Route.GroupBy = labels
}
}

// Templates defines templates that can be used when sending messages to
// contact points.
// See https://prometheus.io/blog/2016/03/03/custom-alertmanager-templates/
Expand Down
10 changes: 10 additions & 0 deletions alertmanager/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ func TestDefaultContactPoint(t *testing.T) {
req.Equal("team-a", manager.builder.Config.Route.Receiver)
}

func TestDefaultGroupBy(t *testing.T) {
req := require.New(t)

manager := New(
DefaultGroupBys("priority", "service"),
)

req.ElementsMatch([]string{"priority", "service"}, manager.builder.Config.Route.GroupBy)
}

func TestDefaultContactPointCanBeImplicit(t *testing.T) {
req := require.New(t)

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/K-Phoen/grabana
go 1.16

require (
github.com/K-Phoen/sdk v0.11.0
github.com/K-Phoen/sdk v0.11.1
github.com/blang/semver v3.5.1+incompatible
github.com/prometheus/common v0.34.0
github.com/rhysd/go-github-selfupdate v1.2.3
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
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/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/sdk v0.11.1 h1:kzuOW7AzDLdI2rghGyqTiv01czadrzeL4m96TQrRC2A=
github.com/K-Phoen/sdk v0.11.1/go.mod h1:wp7qXARaIhCYktmoOjRZ+TDMlek5nbayC+waN7vigxI=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
Expand Down
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.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# github.com/K-Phoen/sdk v0.11.0
# github.com/K-Phoen/sdk v0.11.1
## explicit
github.com/K-Phoen/sdk
# github.com/blang/semver v3.5.1+incompatible
Expand Down

0 comments on commit ceff5f0

Please sign in to comment.