From 0bfe150928284bebd3208b9387651499cc8b7667 Mon Sep 17 00:00:00 2001 From: gotjosh Date: Thu, 26 Jan 2023 12:54:03 +0000 Subject: [PATCH] Alerting: Fix Test Receivers when settings are non-strings (#62156) * Alerting: Fix Test Receivers when settings are non-strings As part of the Alerting extraction, we want to make sure we don't have circular depedencies. As such, I had to move `PostableGrafanaReceiver` to a new struct in `grafana/alerting` called `GrafanaReceiver`. `PostableGrafanaReceiver` has an attribute called `Settings` that uses a Grafana-propietary struct called `RawMessage`, this struct shadows `json.RawMessage`. When I created `GrafanaReceiver`, I turned settings into a `map[string]string` thinking all settings would end up as strings. This was a mistake, and this test proves that it doesn't work, and breaks the API. --- go.mod | 2 +- go.sum | 4 ++-- pkg/services/ngalert/notifier/receivers.go | 2 +- pkg/tests/api/alerting/api_notification_channel_test.go | 3 ++- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 7595bdc6861..108a98b42c1 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-20230124145916-c6a7791d037e + github.com/grafana/alerting v0.0.0-20230125210216-facc6b27b9e0 github.com/grafana/cuetsy v0.1.5 github.com/grafana/grafana-aws-sdk v0.12.0 github.com/grafana/grafana-azure-sdk-go v1.5.1 diff --git a/go.sum b/go.sum index 7c6fb1c4d0f..7e2c44649b6 100644 --- a/go.sum +++ b/go.sum @@ -1394,8 +1394,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-20230124145916-c6a7791d037e h1:YCxvmaPXHGiaQdWy6qeQExivxWzpwUyM0sh73vudWhw= -github.com/grafana/alerting v0.0.0-20230124145916-c6a7791d037e/go.mod h1:NoSLbfmUwE+omWFReFrLtbtOItmvTbuQERJ6XFYp9ME= +github.com/grafana/alerting v0.0.0-20230125210216-facc6b27b9e0 h1:BzkQNnj+eevX30EMqJiUS1w3CPoGc8kp7pDf/ari/4Y= +github.com/grafana/alerting v0.0.0-20230125210216-facc6b27b9e0/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= diff --git a/pkg/services/ngalert/notifier/receivers.go b/pkg/services/ngalert/notifier/receivers.go index 02478c589bd..2a964b1e5d0 100644 --- a/pkg/services/ngalert/notifier/receivers.go +++ b/pkg/services/ngalert/notifier/receivers.go @@ -60,7 +60,7 @@ func (am *Alertmanager) TestReceivers(ctx context.Context, c apimodels.TestRecei for _, r := range c.Receivers { greceivers := make([]*alerting.GrafanaReceiver, 0, len(r.GrafanaManagedReceivers)) for _, gr := range r.PostableGrafanaReceivers.GrafanaManagedReceivers { - var settings map[string]string + var settings map[string]interface{} //TODO: We shouldn't need to do this marshalling. j, err := gr.Settings.MarshalJSON() if err != nil { diff --git a/pkg/tests/api/alerting/api_notification_channel_test.go b/pkg/tests/api/alerting/api_notification_channel_test.go index 7396e24dbaf..ce6323085c5 100644 --- a/pkg/tests/api/alerting/api_notification_channel_test.go +++ b/pkg/tests/api/alerting/api_notification_channel_test.go @@ -98,7 +98,8 @@ func TestIntegrationTestReceivers(t *testing.T) { "type": "email", "disableResolveMessage": false, "settings": { - "addresses":"example@email.com" + "addresses":"example@email.com", + "singleEmail": true }, "secureFields": {} }