diff --git a/alertmanager/manager.go b/alertmanager/manager.go index 1b9f9c99..90b8ebea 100644 --- a/alertmanager/manager.go +++ b/alertmanager/manager.go @@ -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/ diff --git a/alertmanager/manager_test.go b/alertmanager/manager_test.go index 4e3438d2..f06ab20c 100644 --- a/alertmanager/manager_test.go +++ b/alertmanager/manager_test.go @@ -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) diff --git a/go.mod b/go.mod index d84127c0..e2b96f9d 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index c4ddd52e..7b0d89ac 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/vendor/github.com/K-Phoen/sdk/alert-manager.go b/vendor/github.com/K-Phoen/sdk/alert-manager.go index fbb15752..56b5bb76 100644 --- a/vendor/github.com/K-Phoen/sdk/alert-manager.go +++ b/vendor/github.com/K-Phoen/sdk/alert-manager.go @@ -50,6 +50,10 @@ type MessageTemplate map[string]string type NotificationPolicies struct { // Default alert receiver Receiver string `json:"receiver"` + + // Default group bys + GroupBy []string `json:"group_by,omitempty"` + // Default timing settings GroupInterval string `json:"group_interval,omitempty"` GroupWait string `json:"group_wait,omitempty"` diff --git a/vendor/modules.txt b/vendor/modules.txt index be23e065..12cc88da 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -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