feat(alerting): Implement alert-level provider overrides (#929)

* feat(alerting): Implement alert-level provider overrides

Fixes #96

* Fix tests

* Add missing test cases for alerting providers

* feat(alerting): Implement alert-level overrides on all providers

* chore: Add config.yaml to .gitignore

* fix typo in discord provider

* test: Start fixing tests for alerting providers

* test: Fix GitLab tests

* Fix all tests

* test: Improve coverage

* test: Improve coverage

* Rename override to provider-override

* docs: Mention new provider-override config

* test: Improve coverage

* test: Improve coverage

* chore: Rename Alert.OverrideAsBytes to Alert.ProviderOverrideAsBytes
This commit is contained in:
TwiN
2024-12-16 20:32:13 -05:00
committed by GitHub
parent be9ae6f55d
commit 79c9f24c15
54 changed files with 4623 additions and 2109 deletions

View File

@ -30,8 +30,10 @@ func TestHandleAlerting(t *testing.T) {
cfg := &config.Config{
Alerting: &alerting.Config{
Custom: &custom.AlertProvider{
URL: "https://twin.sh/health",
Method: "GET",
DefaultConfig: custom.Config{
URL: "https://twin.sh/health",
Method: "GET",
},
},
},
}
@ -108,8 +110,10 @@ func TestHandleAlertingWhenTriggeredAlertIsAlmostResolvedButendpointStartFailing
cfg := &config.Config{
Alerting: &alerting.Config{
Custom: &custom.AlertProvider{
URL: "https://twin.sh/health",
Method: "GET",
DefaultConfig: custom.Config{
URL: "https://twin.sh/health",
Method: "GET",
},
},
},
}
@ -141,8 +145,10 @@ func TestHandleAlertingWhenTriggeredAlertIsResolvedButSendOnResolvedIsFalse(t *t
cfg := &config.Config{
Alerting: &alerting.Config{
Custom: &custom.AlertProvider{
URL: "https://twin.sh/health",
Method: "GET",
DefaultConfig: custom.Config{
URL: "https://twin.sh/health",
Method: "GET",
},
},
},
}
@ -174,7 +180,9 @@ func TestHandleAlertingWhenTriggeredAlertIsResolvedPagerDuty(t *testing.T) {
cfg := &config.Config{
Alerting: &alerting.Config{
PagerDuty: &pagerduty.AlertProvider{
IntegrationKey: "00000000000000000000000000000000",
DefaultConfig: pagerduty.Config{
IntegrationKey: "00000000000000000000000000000000",
},
},
},
}
@ -208,8 +216,10 @@ func TestHandleAlertingWhenTriggeredAlertIsResolvedPushover(t *testing.T) {
cfg := &config.Config{
Alerting: &alerting.Config{
Pushover: &pushover.AlertProvider{
ApplicationToken: "000000000000000000000000000000",
UserKey: "000000000000000000000000000000",
DefaultConfig: pushover.Config{
ApplicationToken: "000000000000000000000000000000",
UserKey: "000000000000000000000000000000",
},
},
},
}
@ -250,8 +260,10 @@ func TestHandleAlertingWithProviderThatReturnsAnError(t *testing.T) {
AlertType: alert.TypeCustom,
AlertingConfig: &alerting.Config{
Custom: &custom.AlertProvider{
URL: "https://twin.sh/health",
Method: "GET",
DefaultConfig: custom.Config{
URL: "https://twin.sh/health",
Method: "GET",
},
},
},
},
@ -260,7 +272,9 @@ func TestHandleAlertingWithProviderThatReturnsAnError(t *testing.T) {
AlertType: alert.TypeDiscord,
AlertingConfig: &alerting.Config{
Discord: &discord.AlertProvider{
WebhookURL: "https://example.com",
DefaultConfig: discord.Config{
WebhookURL: "https://example.com",
},
},
},
},
@ -269,11 +283,13 @@ func TestHandleAlertingWithProviderThatReturnsAnError(t *testing.T) {
AlertType: alert.TypeEmail,
AlertingConfig: &alerting.Config{
Email: &email.AlertProvider{
From: "from@example.com",
Password: "hunter2",
Host: "mail.example.com",
Port: 587,
To: "to@example.com",
DefaultConfig: email.Config{
From: "from@example.com",
Password: "hunter2",
Host: "mail.example.com",
Port: 587,
To: "to@example.com",
},
},
},
},
@ -282,9 +298,11 @@ func TestHandleAlertingWithProviderThatReturnsAnError(t *testing.T) {
AlertType: alert.TypeJetBrainsSpace,
AlertingConfig: &alerting.Config{
JetBrainsSpace: &jetbrainsspace.AlertProvider{
Project: "foo",
ChannelID: "bar",
Token: "baz",
DefaultConfig: jetbrainsspace.Config{
Project: "foo",
ChannelID: "bar",
Token: "baz",
},
},
},
},
@ -293,7 +311,9 @@ func TestHandleAlertingWithProviderThatReturnsAnError(t *testing.T) {
AlertType: alert.TypeMattermost,
AlertingConfig: &alerting.Config{
Mattermost: &mattermost.AlertProvider{
WebhookURL: "https://example.com",
DefaultConfig: mattermost.Config{
WebhookURL: "https://example.com",
},
},
},
},
@ -302,9 +322,11 @@ func TestHandleAlertingWithProviderThatReturnsAnError(t *testing.T) {
AlertType: alert.TypeMessagebird,
AlertingConfig: &alerting.Config{
Messagebird: &messagebird.AlertProvider{
AccessKey: "1",
Originator: "2",
Recipients: "3",
DefaultConfig: messagebird.Config{
AccessKey: "1",
Originator: "2",
Recipients: "3",
},
},
},
},
@ -313,7 +335,9 @@ func TestHandleAlertingWithProviderThatReturnsAnError(t *testing.T) {
AlertType: alert.TypePagerDuty,
AlertingConfig: &alerting.Config{
PagerDuty: &pagerduty.AlertProvider{
IntegrationKey: "00000000000000000000000000000000",
DefaultConfig: pagerduty.Config{
IntegrationKey: "00000000000000000000000000000000",
},
},
},
},
@ -322,8 +346,10 @@ func TestHandleAlertingWithProviderThatReturnsAnError(t *testing.T) {
AlertType: alert.TypePushover,
AlertingConfig: &alerting.Config{
Pushover: &pushover.AlertProvider{
ApplicationToken: "000000000000000000000000000000",
UserKey: "000000000000000000000000000000",
DefaultConfig: pushover.Config{
ApplicationToken: "000000000000000000000000000000",
UserKey: "000000000000000000000000000000",
},
},
},
},
@ -332,7 +358,9 @@ func TestHandleAlertingWithProviderThatReturnsAnError(t *testing.T) {
AlertType: alert.TypeSlack,
AlertingConfig: &alerting.Config{
Slack: &slack.AlertProvider{
WebhookURL: "https://example.com",
DefaultConfig: slack.Config{
WebhookURL: "https://example.com",
},
},
},
},
@ -341,7 +369,9 @@ func TestHandleAlertingWithProviderThatReturnsAnError(t *testing.T) {
AlertType: alert.TypeTeams,
AlertingConfig: &alerting.Config{
Teams: &teams.AlertProvider{
WebhookURL: "https://example.com",
DefaultConfig: teams.Config{
WebhookURL: "https://example.com",
},
},
},
},
@ -350,8 +380,10 @@ func TestHandleAlertingWithProviderThatReturnsAnError(t *testing.T) {
AlertType: alert.TypeTelegram,
AlertingConfig: &alerting.Config{
Telegram: &telegram.AlertProvider{
Token: "1",
ID: "2",
DefaultConfig: telegram.Config{
Token: "1",
ID: "2",
},
},
},
},
@ -360,10 +392,12 @@ func TestHandleAlertingWithProviderThatReturnsAnError(t *testing.T) {
AlertType: alert.TypeTwilio,
AlertingConfig: &alerting.Config{
Twilio: &twilio.AlertProvider{
SID: "1",
Token: "2",
From: "3",
To: "4",
DefaultConfig: twilio.Config{
SID: "1",
Token: "2",
From: "3",
To: "4",
},
},
},
},
@ -372,7 +406,7 @@ func TestHandleAlertingWithProviderThatReturnsAnError(t *testing.T) {
AlertType: alert.TypeMatrix,
AlertingConfig: &alerting.Config{
Matrix: &matrix.AlertProvider{
ProviderConfig: matrix.ProviderConfig{
DefaultConfig: matrix.Config{
ServerURL: "https://example.com",
AccessToken: "1",
InternalRoomID: "!a:example.com",
@ -437,8 +471,10 @@ func TestHandleAlertingWithProviderThatOnlyReturnsErrorOnResolve(t *testing.T) {
cfg := &config.Config{
Alerting: &alerting.Config{
Custom: &custom.AlertProvider{
URL: "https://twin.sh/health",
Method: "GET",
DefaultConfig: custom.Config{
URL: "https://twin.sh/health",
Method: "GET",
},
},
},
}