From 511dab3b4b638fdcd7a38f79aa7ac860bdb19712 Mon Sep 17 00:00:00 2001 From: gotjosh Date: Thu, 19 Jan 2023 20:44:49 +0000 Subject: [PATCH] Update `grafana/alerting` to the latest main (#61810) * Update `grafana/alerting` to the latest main Also updates prometheus-alertmanager since we use that one directly for some structs. --- go.mod | 4 +- go.sum | 8 +-- .../api/tooling/definitions/alertmanager.go | 2 +- pkg/services/ngalert/notifier/config.go | 2 +- .../ngalert/notifier/receivers_test.go | 54 +++++-------------- 5 files changed, 22 insertions(+), 48 deletions(-) diff --git a/go.mod b/go.mod index 2f1afac365b..8d752d302a8 100644 --- a/go.mod +++ b/go.mod @@ -59,7 +59,7 @@ require ( github.com/google/uuid v1.3.0 github.com/google/wire v0.5.0 github.com/gorilla/websocket v1.5.0 - github.com/grafana/alerting v0.0.0-20230113220341-b9b3de89bca2 + github.com/grafana/alerting v0.0.0-20230119191910-5ebb70a85264 github.com/grafana/cuetsy v0.1.5 github.com/grafana/grafana-aws-sdk v0.11.0 github.com/grafana/grafana-azure-sdk-go v1.5.1 @@ -422,7 +422,7 @@ replace xorm.io/xorm => github.com/grafana/xorm v0.8.3-0.20220614223926-2fcda756 // Use our fork of the upstream alertmanagers. // This is required in order to get notification delivery errors from the receivers API. -replace github.com/prometheus/alertmanager => github.com/grafana/prometheus-alertmanager v0.25.1-0.20230109182643-002d8ba820f6 +replace github.com/prometheus/alertmanager => github.com/grafana/prometheus-alertmanager v0.25.1-0.20230119183635-ec19b0a443b7 // grpc v1.46.0 removed "WithBalancerName()" API, still in use by weaveworks/commons. replace google.golang.org/grpc => google.golang.org/grpc v1.45.0 diff --git a/go.sum b/go.sum index 2d4bcc832f3..d8e1550e5f3 100644 --- a/go.sum +++ b/go.sum @@ -1393,8 +1393,8 @@ github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/ad github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= -github.com/grafana/alerting v0.0.0-20230113220341-b9b3de89bca2 h1:XkzN0dBir+oso3XjGOV2HLGSCjyyYHLL5AuUqI/LIXY= -github.com/grafana/alerting v0.0.0-20230113220341-b9b3de89bca2/go.mod h1:w5jcmHYPAfju/QcI69SwFs0+qMcm8jvW6fsqSc2tJtc= +github.com/grafana/alerting v0.0.0-20230119191910-5ebb70a85264 h1:ApQsGfr05Yma0dpd1+ib11cJQcpmet+E/Ke/aQkdT1Y= +github.com/grafana/alerting v0.0.0-20230119191910-5ebb70a85264/go.mod h1:NoSLbfmUwE+omWFReFrLtbtOItmvTbuQERJ6XFYp9ME= github.com/grafana/codejen v0.0.3 h1:tAWxoTUuhgmEqxJPOLtJoxlPBbMULFwKFOcRsPRPXDw= github.com/grafana/codejen v0.0.3/go.mod h1:zmwwM/DRyQB7pfuBjTWII3CWtxcXh8LTwAYGfDfpR6s= github.com/grafana/cuetsy v0.1.5 h1:mnFwAXdbqCsyL8r7kkdUMJ4kOAR26cxIPmrZj7JzTeY= @@ -1414,8 +1414,8 @@ github.com/grafana/grafana-plugin-sdk-go v0.147.0 h1:VavvJOa/Ubs+wzalzWIl+FQmdaD github.com/grafana/grafana-plugin-sdk-go v0.147.0/go.mod h1:NMgO3t2gR5wyLx8bWZ9CTmpDk5Txp4wYFccFLHdYn3Q= github.com/grafana/phlare/api v0.1.2 h1:1jrwd3KnsXMzj/tJih9likx5EvbY3pbvLbDqAAYem30= github.com/grafana/phlare/api v0.1.2/go.mod h1:29vcLwFDmZBDce2jwFIMtzvof7fzPadT8VMKw9ks7FU= -github.com/grafana/prometheus-alertmanager v0.25.1-0.20230109182643-002d8ba820f6 h1:teookZDfQHNJWhsXujYZLhIeLFWzZZtqeqqfkQwOcLI= -github.com/grafana/prometheus-alertmanager v0.25.1-0.20230109182643-002d8ba820f6/go.mod h1:MnBfDPXJqXmmfPwQlCLvVUdqfnvrAw+hSPtDeaaFwj4= +github.com/grafana/prometheus-alertmanager v0.25.1-0.20230119183635-ec19b0a443b7 h1:ma1CfisUaAXQzL24tCao9yMleZYsFJ853m2l0rgahyE= +github.com/grafana/prometheus-alertmanager v0.25.1-0.20230119183635-ec19b0a443b7/go.mod h1:MnBfDPXJqXmmfPwQlCLvVUdqfnvrAw+hSPtDeaaFwj4= github.com/grafana/saml v0.4.9-0.20220727151557-61cd9c9353fc h1:1PY8n+rXuBNr3r1JQhoytWDCpc+pq+BibxV0SZv+Cr4= github.com/grafana/saml v0.4.9-0.20220727151557-61cd9c9353fc/go.mod h1:9Zh6dWPtB3MSzTRt8fIFH60Z351QQ+s7hCU3J/tTlA4= github.com/grafana/thema v0.0.0-20230113164405-e0e8893756cf h1:jl1iWUlJt5GJWaafOqtaEp46MDFBCni7bmv75VGFkq0= diff --git a/pkg/services/ngalert/api/tooling/definitions/alertmanager.go b/pkg/services/ngalert/api/tooling/definitions/alertmanager.go index cb2d12c08f3..ce0ddc37285 100644 --- a/pkg/services/ngalert/api/tooling/definitions/alertmanager.go +++ b/pkg/services/ngalert/api/tooling/definitions/alertmanager.go @@ -695,7 +695,7 @@ func (c *GettableApiAlertingConfig) validate() error { type Config struct { Global *config.GlobalConfig `yaml:"global,omitempty" json:"global,omitempty"` Route *Route `yaml:"route,omitempty" json:"route,omitempty"` - InhibitRules []*config.InhibitRule `yaml:"inhibit_rules,omitempty" json:"inhibit_rules,omitempty"` + InhibitRules []config.InhibitRule `yaml:"inhibit_rules,omitempty" json:"inhibit_rules,omitempty"` MuteTimeIntervals []config.MuteTimeInterval `yaml:"mute_time_intervals,omitempty" json:"mute_time_intervals,omitempty"` Templates []string `yaml:"templates" json:"templates"` } diff --git a/pkg/services/ngalert/notifier/config.go b/pkg/services/ngalert/notifier/config.go index 53497b2c6c4..c8fcc99f2e9 100644 --- a/pkg/services/ngalert/notifier/config.go +++ b/pkg/services/ngalert/notifier/config.go @@ -130,7 +130,7 @@ func (a AlertingConfiguration) DispatcherLimits() alerting.DispatcherLimits { return &nilLimits{} } -func (a AlertingConfiguration) InhibitRules() []*alerting.InhibitRule { +func (a AlertingConfiguration) InhibitRules() []alerting.InhibitRule { return a.AlertmanagerConfig.InhibitRules } diff --git a/pkg/services/ngalert/notifier/receivers_test.go b/pkg/services/ngalert/notifier/receivers_test.go index 10fb8186d5a..25d3195b2af 100644 --- a/pkg/services/ngalert/notifier/receivers_test.go +++ b/pkg/services/ngalert/notifier/receivers_test.go @@ -6,14 +6,14 @@ import ( "net/url" "testing" - "github.com/stretchr/testify/require" + "github.com/grafana/alerting/alerting" - "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" + "github.com/stretchr/testify/require" ) func TestInvalidReceiverError_Error(t *testing.T) { - e := InvalidReceiverError{ - Receiver: &definitions.PostableGrafanaReceiver{ + e := alerting.InvalidReceiverError{ + Receiver: &alerting.GrafanaReceiver{ Name: "test", UID: "uid", }, @@ -23,8 +23,8 @@ func TestInvalidReceiverError_Error(t *testing.T) { } func TestReceiverTimeoutError_Error(t *testing.T) { - e := ReceiverTimeoutError{ - Receiver: &definitions.PostableGrafanaReceiver{ + e := alerting.ReceiverTimeoutError{ + Receiver: &alerting.GrafanaReceiver{ Name: "test", UID: "uid", }, @@ -45,18 +45,18 @@ func (e timeoutError) Timeout() bool { func TestProcessNotifierError(t *testing.T) { t.Run("assert ReceiverTimeoutError is returned for context deadline exceeded", func(t *testing.T) { - r := &definitions.PostableGrafanaReceiver{ + r := &alerting.GrafanaReceiver{ Name: "test", UID: "uid", } - require.Equal(t, ReceiverTimeoutError{ + require.Equal(t, alerting.ReceiverTimeoutError{ Receiver: r, Err: context.DeadlineExceeded, - }, processNotifierError(r, context.DeadlineExceeded)) + }, alerting.ProcessNotifierError(r, context.DeadlineExceeded)) }) t.Run("assert ReceiverTimeoutError is returned for *url.Error timeout", func(t *testing.T) { - r := &definitions.PostableGrafanaReceiver{ + r := &alerting.GrafanaReceiver{ Name: "test", UID: "uid", } @@ -65,44 +65,18 @@ func TestProcessNotifierError(t *testing.T) { URL: "https://grafana.net", Err: timeoutError{}, } - require.Equal(t, ReceiverTimeoutError{ + require.Equal(t, alerting.ReceiverTimeoutError{ Receiver: r, Err: urlError, - }, processNotifierError(r, urlError)) + }, alerting.ProcessNotifierError(r, urlError)) }) t.Run("assert unknown error is returned unmodified", func(t *testing.T) { - r := &definitions.PostableGrafanaReceiver{ + r := &alerting.GrafanaReceiver{ Name: "test", UID: "uid", } err := errors.New("this is an error") - require.Equal(t, err, processNotifierError(r, err)) + require.Equal(t, err, alerting.ProcessNotifierError(r, err)) }) } - -// TODO: Copied from Alerting, needs to be made public. -func processNotifierError(config *definitions.PostableGrafanaReceiver, err error) error { - if err == nil { - return nil - } - - var urlError *url.Error - if errors.As(err, &urlError) { - if urlError.Timeout() { - return ReceiverTimeoutError{ - Receiver: config, - Err: err, - } - } - } - - if errors.Is(err, context.DeadlineExceeded) { - return ReceiverTimeoutError{ - Receiver: config, - Err: err, - } - } - - return err -}