Chore: Update alerting to commit 518e63bb07c5 (#65488)
* update alerting module to 518e63bb07c5 * update slack test to cover json and text response content-type cases
This commit is contained in:
@@ -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-20230209203114-508391225cd4
|
||||
github.com/grafana/alerting v0.0.0-20230328192025-518e63bb07c5
|
||||
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
|
||||
|
||||
@@ -1396,6 +1396,8 @@ github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWm
|
||||
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||
github.com/grafana/alerting v0.0.0-20230209203114-508391225cd4 h1:5/+He0gIt2Rr2EVijLEj+E2T6lhbEYsDoOP61qyBwM8=
|
||||
github.com/grafana/alerting v0.0.0-20230209203114-508391225cd4/go.mod h1:NoSLbfmUwE+omWFReFrLtbtOItmvTbuQERJ6XFYp9ME=
|
||||
github.com/grafana/alerting v0.0.0-20230328192025-518e63bb07c5 h1:mGAFon+7Vq5a/eiGIUBSzvbMyUJuY0qr3YFHVsOGNb8=
|
||||
github.com/grafana/alerting v0.0.0-20230328192025-518e63bb07c5/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=
|
||||
|
||||
@@ -17,11 +17,12 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/grafana/alerting/alerting/notifier/channels"
|
||||
"github.com/grafana/grafana/pkg/expr"
|
||||
"github.com/prometheus/alertmanager/template"
|
||||
"github.com/prometheus/common/model"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/grafana/grafana/pkg/expr"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/db"
|
||||
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
||||
ngmodels "github.com/grafana/grafana/pkg/services/ngalert/models"
|
||||
@@ -716,8 +717,13 @@ func TestIntegrationNotificationChannels(t *testing.T) {
|
||||
mockEmail := &mockEmailHandler{}
|
||||
|
||||
// Set up responses
|
||||
mockChannel.responses["slack_recv1"] = `{"ok": true}`
|
||||
mockChannel.responses["slack_recvX"] = `{"ok": true}`
|
||||
mockChannel.responses["slack_recv1"] = func(res http.ResponseWriter) {
|
||||
res.Header().Set("Content-Type", "application/json")
|
||||
fmt.Fprint(res, `{"ok": true}`)
|
||||
}
|
||||
mockChannel.responses["slack_recvX"] = func(res http.ResponseWriter) {
|
||||
fmt.Fprint(res, `ok`)
|
||||
}
|
||||
|
||||
// Overriding some URLs to send to the mock channel.
|
||||
os, opa, ot, opu, ogb, ol, oth := channels.SlackAPIEndpoint, channels.PagerdutyEventAPIURL,
|
||||
@@ -1002,7 +1008,7 @@ type mockNotificationChannel struct {
|
||||
server *http.Server
|
||||
|
||||
receivedNotifications map[string][]string
|
||||
responses map[string]string
|
||||
responses map[string]func(res http.ResponseWriter)
|
||||
notificationErrorCount int
|
||||
notificationsMtx sync.RWMutex
|
||||
}
|
||||
@@ -1020,7 +1026,7 @@ func newMockNotificationChannel(t *testing.T, grafanaListedAddr string) *mockNot
|
||||
Addr: listener.Addr().String(),
|
||||
},
|
||||
receivedNotifications: make(map[string][]string),
|
||||
responses: make(map[string]string),
|
||||
responses: make(map[string]func(res http.ResponseWriter)),
|
||||
t: t,
|
||||
}
|
||||
|
||||
@@ -1049,8 +1055,11 @@ func (nc *mockNotificationChannel) ServeHTTP(res http.ResponseWriter, req *http.
|
||||
body := getBody(nc.t, req.Body)
|
||||
|
||||
nc.receivedNotifications[key] = append(nc.receivedNotifications[key], body)
|
||||
res.WriteHeader(http.StatusOK)
|
||||
fmt.Fprint(res, nc.responses[paths[0]])
|
||||
if f, ok := nc.responses[paths[0]]; ok {
|
||||
f(res)
|
||||
} else {
|
||||
res.WriteHeader(http.StatusOK)
|
||||
}
|
||||
}
|
||||
|
||||
func (nc *mockNotificationChannel) totalNotifications() int {
|
||||
|
||||
Reference in New Issue
Block a user