Skip to content

Commit

Permalink
fix(receivers): use v2 of the alertmanager api (grafana#159)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnnyQQQQ authored Feb 13, 2024
1 parent b1d7d5f commit 92f64f0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion receivers/alertmanager/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func NewConfig(jsonData json.RawMessage, decryptFn receivers.DecryptFunc) (Confi
if uS == "" {
continue
}
uS = strings.TrimSuffix(uS, "/") + "/api/v1/alerts"
uS = strings.TrimSuffix(uS, "/") + "/api/v2/alerts"
u, err := url.Parse(uS)
if err != nil {
return Config{}, fmt.Errorf("invalid url property in settings: %w", err)
Expand Down
16 changes: 8 additions & 8 deletions receivers/alertmanager/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestNewConfig(t *testing.T) {
settings: `{
"url": "://alertmanager.com"
}`,
expectedInitError: `invalid url property in settings: parse "://alertmanager.com/api/v1/alerts": missing protocol scheme`,
expectedInitError: `invalid url property in settings: parse "://alertmanager.com/api/v2/alerts": missing protocol scheme`,
},
{
name: "Error in initing: empty URL",
Expand All @@ -48,15 +48,15 @@ func TestNewConfig(t *testing.T) {
settings: `{
"url": "https://alertmanager-01.com,://url"
}`,
expectedInitError: "invalid url property in settings: parse \"://url/api/v1/alerts\": missing protocol scheme",
expectedInitError: "invalid url property in settings: parse \"://url/api/v2/alerts\": missing protocol scheme",
}, {
name: "Single URL",
settings: `{
"url": "https://alertmanager-01.com"
}`,
expectedConfig: Config{
URLs: []*url.URL{
receiversTesting.ParseURLUnsafe("https://alertmanager-01.com/api/v1/alerts"),
receiversTesting.ParseURLUnsafe("https://alertmanager-01.com/api/v2/alerts"),
},
User: "",
Password: "",
Expand All @@ -69,9 +69,9 @@ func TestNewConfig(t *testing.T) {
}`,
expectedConfig: Config{
URLs: []*url.URL{
receiversTesting.ParseURLUnsafe("https://alertmanager-01.com/api/v1/alerts"),
receiversTesting.ParseURLUnsafe("https://alertmanager-02.com/api/v1/alerts"),
receiversTesting.ParseURLUnsafe("https://alertmanager-03.com/api/v1/alerts"),
receiversTesting.ParseURLUnsafe("https://alertmanager-01.com/api/v2/alerts"),
receiversTesting.ParseURLUnsafe("https://alertmanager-02.com/api/v2/alerts"),
receiversTesting.ParseURLUnsafe("https://alertmanager-03.com/api/v2/alerts"),
},
User: "",
Password: "",
Expand All @@ -86,7 +86,7 @@ func TestNewConfig(t *testing.T) {
}`,
expectedConfig: Config{
URLs: []*url.URL{
receiversTesting.ParseURLUnsafe("https://alertmanager-01.com/api/v1/alerts"),
receiversTesting.ParseURLUnsafe("https://alertmanager-01.com/api/v2/alerts"),
},
User: "grafana",
Password: "admin",
Expand All @@ -98,7 +98,7 @@ func TestNewConfig(t *testing.T) {
secrets: receiversTesting.ReadSecretsJSONForTesting(FullValidSecretsForTesting),
expectedConfig: Config{
URLs: []*url.URL{
receiversTesting.ParseURLUnsafe("https://alertmanager-01.com/api/v1/alerts"),
receiversTesting.ParseURLUnsafe("https://alertmanager-01.com/api/v2/alerts"),
},
User: "grafana",
Password: "grafana-admin",
Expand Down

0 comments on commit 92f64f0

Please sign in to comment.