mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: Update grafana/alerting (#88363)
* Alerting: Update grafana/alerting * make tests pass by implementing yaml unmarshallers and deleting fields with omitempty in their yaml tags * go mod tidy * fix tests by implementing not calling GettableApiAlertingConfig.UnmarshalYAML from GettableApiAlertingConfig.UnmarshalJSON * cleanup, reduce diff * fix more tests * update grafana/alerting to latest commit, delete global section from configs in tests * bring back YAML unmarshaller for GettableApiAlertingConfig * update alerting package dependency to point to main * skip test for sns notifier
This commit is contained in:
@@ -53,6 +53,11 @@ func TestContactPointFromContactPointExports(t *testing.T) {
|
||||
// use the configs for testing because they have all fields supported by integrations
|
||||
for integrationType, cfg := range notify.AllKnownConfigsForTesting {
|
||||
t.Run(integrationType, func(t *testing.T) {
|
||||
if integrationType == "sns" {
|
||||
// TODO: Add code for SNS in grafana/grafana.
|
||||
// Related grafana/alerting PR: https://github.com/grafana/alerting/pull/173
|
||||
t.Skip("sns not supported yet")
|
||||
}
|
||||
recCfg := ¬ify.APIReceiver{
|
||||
ConfigReceiver: notify.ConfigReceiver{Name: "test-receiver"},
|
||||
GrafanaIntegrations: notify.GrafanaIntegrations{
|
||||
|
||||
@@ -877,6 +877,26 @@ func (c *GettableApiAlertingConfig) UnmarshalJSON(b []byte) error {
|
||||
return c.validate()
|
||||
}
|
||||
|
||||
func (c *GettableApiAlertingConfig) UnmarshalYAML(value *yaml.Node) error {
|
||||
type plain GettableApiAlertingConfig
|
||||
if err := value.Decode((*plain)(c)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Since Config implements yaml.Unmarshaler, we must handle _all_ other fields independently.
|
||||
// Otherwise, the yaml decoder will detect this and only use the embedded type.
|
||||
// Additionally, we'll use pointers to slices in order to reference the intended target.
|
||||
type overrides struct {
|
||||
Receivers *[]*GettableApiReceiver `yaml:"receivers,omitempty"`
|
||||
}
|
||||
|
||||
if err := value.Decode(&overrides{Receivers: &c.Receivers}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return c.validate()
|
||||
}
|
||||
|
||||
// validate ensures that the two routing trees use the correct receiver types.
|
||||
func (c *GettableApiAlertingConfig) validate() error {
|
||||
receivers := make(map[string]struct{}, len(c.Receivers))
|
||||
|
||||
@@ -253,7 +253,7 @@ func TestMultiOrgAlertmanager_ActivateHistoricalConfiguration(t *testing.T) {
|
||||
require.Equal(t, defaultConfig, cfgs[3].AlertmanagerConfiguration)
|
||||
|
||||
// Now let's save a new config for org 2.
|
||||
newConfig := `{"template_files":null,"alertmanager_config":{"route":{"receiver":"grafana-default-email","group_by":["grafana_folder","alertname"]},"templates":null,"receivers":[{"name":"grafana-default-email","grafana_managed_receiver_configs":[{"uid":"","name":"some other name","type":"email","disableResolveMessage":false,"settings":{"addresses":"\u003cexample@email.com\u003e"},"secureSettings":null}]}]}}`
|
||||
newConfig := `{"template_files":null,"alertmanager_config":{"route":{"receiver":"grafana-default-email","group_by":["grafana_folder","alertname"]},"receivers":[{"name":"grafana-default-email","grafana_managed_receiver_configs":[{"uid":"","name":"some other name","type":"email","disableResolveMessage":false,"settings":{"addresses":"\u003cexample@email.com\u003e"}}]}]}}`
|
||||
am, err := mam.alertmanagerForOrg(2)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -399,7 +399,6 @@ var defaultConfig = `
|
||||
"alertname"
|
||||
]
|
||||
},
|
||||
"templates": null,
|
||||
"receivers": [
|
||||
{
|
||||
"name": "grafana-default-email",
|
||||
@@ -410,8 +409,8 @@ var defaultConfig = `
|
||||
"type": "email",
|
||||
"disableResolveMessage": false,
|
||||
"settings": {
|
||||
"addresses": "\u003cexample@email.com\u003e"},
|
||||
"secureSettings": null
|
||||
"addresses": "\u003cexample@email.com\u003e"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -39,8 +39,8 @@ import (
|
||||
|
||||
const (
|
||||
// Valid Grafana Alertmanager configurations.
|
||||
testGrafanaConfig = `{"template_files":{},"alertmanager_config":{"route":{"receiver":"grafana-default-email","group_by":["grafana_folder","alertname"]},"templates":null,"receivers":[{"name":"grafana-default-email","grafana_managed_receiver_configs":[{"uid":"","name":"some other name","type":"email","disableResolveMessage":false,"settings":{"addresses":"\u003cexample@email.com\u003e"},"secureSettings":null}]}]}}`
|
||||
testGrafanaConfigWithSecret = `{"template_files":{},"alertmanager_config":{"route":{"receiver":"grafana-default-email","group_by":["grafana_folder","alertname"]},"templates":null,"receivers":[{"name":"grafana-default-email","grafana_managed_receiver_configs":[{"uid":"dde6ntuob69dtf","name":"WH","type":"webhook","disableResolveMessage":false,"settings":{"url":"http://localhost:8080","username":"test"},"secureSettings":{"password":"test"}}]}]}}`
|
||||
testGrafanaConfig = `{"template_files":{},"alertmanager_config":{"route":{"receiver":"grafana-default-email","group_by":["grafana_folder","alertname"]},"receivers":[{"name":"grafana-default-email","grafana_managed_receiver_configs":[{"uid":"","name":"some other name","type":"email","disableResolveMessage":false,"settings":{"addresses":"\u003cexample@email.com\u003e"}}]}]}}`
|
||||
testGrafanaConfigWithSecret = `{"template_files":{},"alertmanager_config":{"route":{"receiver":"grafana-default-email","group_by":["grafana_folder","alertname"]},"receivers":[{"name":"grafana-default-email","grafana_managed_receiver_configs":[{"uid":"dde6ntuob69dtf","name":"WH","type":"webhook","disableResolveMessage":false,"settings":{"url":"http://localhost:8080","username":"test"},"secureSettings":{"password":"test"}}]}]}}`
|
||||
|
||||
// Valid Alertmanager state base64 encoded.
|
||||
testSilence1 = "lwEKhgEKATESFxIJYWxlcnRuYW1lGgp0ZXN0X2FsZXJ0EiMSDmdyYWZhbmFfZm9sZGVyGhF0ZXN0X2FsZXJ0X2ZvbGRlchoMCN2CkbAGEJbKrMsDIgwI7Z6RsAYQlsqsywMqCwiAkrjDmP7///8BQgxHcmFmYW5hIFRlc3RKDFRlc3QgU2lsZW5jZRIMCO2ekbAGEJbKrMsD"
|
||||
@@ -699,7 +699,6 @@ global:
|
||||
route:
|
||||
receiver: empty-receiver
|
||||
continue: false
|
||||
templates: []
|
||||
receivers:
|
||||
- name: empty-receiver
|
||||
`
|
||||
|
||||
Reference in New Issue
Block a user