Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression in 0.26.0 when using amtool config rules with webhook_configs #3505

Open
czenker opened this issue Sep 4, 2023 · 13 comments
Open

Comments

@czenker
Copy link

czenker commented Sep 4, 2023

What did you do?

Update from version 0.25.0 to 0.26.0.

What did you expect to see?

We use amtool config routes test alertname=Foobar severity=panic in an automated test to ensure there is no misconfiguration that would not route alerts into on-call. We expected the command to work as before in the sense, that it would tell us which receivers would receive that alert.

What did you see instead? Under which circumstances?

With amtool 0.26.0:

error: scheme required for webhook url

With amtool 0.25.0 (error message is different, but the problem is the same):

Warning: amtool version (0.25.0) and alertmanager version (0.26.0) are different.
amtool: error: unsupported scheme "" for URL

amtool exits with status code 1 regardless and does not print the matched routes.

This is very likely a regression from #3228 as the API does not output the url anymore, but amtool seems to be unaware of it and detects an error.

It also affects the amtool config routes show command.

Alertmanager configuration file

This probably only happens when using a webhook_configs with a url:

global: { } # ...
route: { } # ...
receivers:
- name: oncall-alerts
  webhook_configs:
  - url: http://example.com/webhook
templates: [] # ...

As a workaround the new url_file could be used as this does not seem to validate any scheme.

@grobinson-grafana
Copy link
Contributor

Looks like this is an issue when using amtool with --alertmanager.url. It does not affect amtool when using --config.file.

@grobinson-grafana
Copy link
Contributor

I think the issue is as @czenker explained.

For example, the command amtool config routes show fails on Line 65 of cli/routing.go. This command seems to use the /api/v2/status API which returns the Alertmanager configuration but with the URL field for each webhook_configs as <secret>. However, if I revert the URL field for WebhookConfig from *SecretURL back to *URL then it works as the URL is now returned in the /api/v2/status API:

./amtool config routes show --alertmanager.url=http://127.0.0.1:9093
Routing tree:
.
└── default-route  receiver: example

That said, I don't think we should revert the change from *URL to *SecretURL. Instead, I think the actual bug is in UnmarshalYAML for WebhookConfig.

The reason for this is that the UnmarshalYAML function for *SecretURL has special code to detect <secret> and return nil, but UnmarshalYAML for WebhookConfig ignores this when instead it should be a special case.

However, looking further into how UnmarshalYAML works for SecretURL, I don't think this check is even needed as there is an existing check in parseURL for the scheme. Perhaps we can delete the duplicate check from UnmarshalYaml then?

diff --git a/config/notifiers.go b/config/notifiers.go
index db86b1a2..2650db5f 100644
--- a/config/notifiers.go
+++ b/config/notifiers.go
@@ -503,11 +503,6 @@ func (c *WebhookConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
        if c.URL != nil && c.URLFile != "" {
                return fmt.Errorf("at most one of url & url_file must be configured")
        }
-       if c.URL != nil {
-               if c.URL.Scheme != "https" && c.URL.Scheme != "http" {
-                       return fmt.Errorf("scheme required for webhook url")
-               }
-       }
        return nil
 }

@gotjosh
Copy link
Member

gotjosh commented Sep 5, 2023

Ah, I get it now -- I think it's because SecretURL is actually an URL

type SecretURL URL

and the UnmarshalYAML of SecretURL uses the original unmarshalling function

func (s *SecretURL) UnmarshalYAML(unmarshal func(interface{}) error) error {
var str string
if err := unmarshal(&str); err != nil {
return err
}
// In order to deserialize a previously serialized configuration (eg from
// the Alertmanager API with amtool), `<secret>` needs to be treated
// specially, as it isn't a valid URL.
if str == secretToken {
s.URL = &url.URL{}
return nil
}
return unmarshal((*URL)(s))
}

which means, SecretURL actually does:

func (u *URL) UnmarshalYAML(unmarshal func(interface{}) error) error {
var s string
if err := unmarshal(&s); err != nil {
return err
}
urlp, err := parseURL(s)
if err != nil {
return err
}
u.URL = urlp.URL
return nil
}

and ends up validating the URL on unmarshalling anyway.

I think the patch above makes sense and we should be safe to remove that check from UnmarshalYAML of WebhookConfig. The hard part is probably testing the CLI to cover both scenarios of with a config and with a fake remote Alertmanager.

grobinson-grafana added a commit to grobinson-grafana/alertmanager that referenced this issue Sep 5, 2023
This commit fixes issue prometheus#3505 where amtool would fail with
"error: scheme required for webhook url" when using amtool
with --alertmanager.url.

The issue here is that UnmarshalYaml for WebhookConfig checks
if the scheme is present when c.URL is non-nil. However,
UnmarshalYaml for SecretURL returns a non-nil, default value
url.URL{} if the response from api/v2/status contains <secret>
as the webhook URL.

Signed-off-by: George Robinson <george.robinson@grafana.com>
grobinson-grafana added a commit to grobinson-grafana/alertmanager that referenced this issue Sep 5, 2023
This commit fixes issue prometheus#3505 where amtool would fail with
"error: scheme required for webhook url" when using amtool
with --alertmanager.url.

The issue here is that UnmarshalYaml for WebhookConfig checks
if the scheme is present when c.URL is non-nil. However,
UnmarshalYaml for SecretURL returns a non-nil, default value
url.URL{} if the response from api/v2/status contains <secret>
as the webhook URL.

Signed-off-by: George Robinson <george.robinson@grafana.com>
gotjosh pushed a commit that referenced this issue Sep 5, 2023
* Fix scheme required for webhook url in amtool

This commit fixes issue #3505 where amtool would fail with
"error: scheme required for webhook url" when using amtool
with --alertmanager.url.

The issue here is that UnmarshalYaml for WebhookConfig checks
if the scheme is present when c.URL is non-nil. However,
UnmarshalYaml for SecretURL returns a non-nil, default value
url.URL{} if the response from api/v2/status contains <secret>
as the webhook URL.

Signed-off-by: George Robinson <george.robinson@grafana.com>

* Add test for config routes test

Signed-off-by: George Robinson <george.robinson@grafana.com>

---------

Signed-off-by: George Robinson <george.robinson@grafana.com>
@gotjosh
Copy link
Member

gotjosh commented Sep 5, 2023

@czenker, we've just merged #3509 and I'll be releasing 0.26.1 tomorrow. Apologies for the disruption.

@czenker
Copy link
Author

czenker commented Sep 13, 2023

@gotjosh Thanks for the quick fix. This is a quick reminder that v0.26.1 is not released yet.

gotjosh pushed a commit that referenced this issue Sep 13, 2023
* Fix scheme required for webhook url in amtool

This commit fixes issue #3505 where amtool would fail with
"error: scheme required for webhook url" when using amtool
with --alertmanager.url.

The issue here is that UnmarshalYaml for WebhookConfig checks
if the scheme is present when c.URL is non-nil. However,
UnmarshalYaml for SecretURL returns a non-nil, default value
url.URL{} if the response from api/v2/status contains <secret>
as the webhook URL.

Signed-off-by: George Robinson <george.robinson@grafana.com>

* Add test for config routes test

Signed-off-by: George Robinson <george.robinson@grafana.com>

---------

Signed-off-by: George Robinson <george.robinson@grafana.com>
gotjosh pushed a commit that referenced this issue Sep 13, 2023
* Fix scheme required for webhook url in amtool

This commit fixes issue #3505 where amtool would fail with
"error: scheme required for webhook url" when using amtool
with --alertmanager.url.

The issue here is that UnmarshalYaml for WebhookConfig checks
if the scheme is present when c.URL is non-nil. However,
UnmarshalYaml for SecretURL returns a non-nil, default value
url.URL{} if the response from api/v2/status contains <secret>
as the webhook URL.

Signed-off-by: George Robinson <george.robinson@grafana.com>

* Add test for config routes test

Signed-off-by: George Robinson <george.robinson@grafana.com>

---------

Signed-off-by: George Robinson <george.robinson@grafana.com>
Signed-off-by: gotjosh <josue.abreu@gmail.com>
@rajatvig
Copy link

Is 0.26.1 planned?

@xbglowx
Copy link

xbglowx commented Nov 3, 2023

@czenker, we've just merged #3509 and I'll be releasing 0.26.1 tomorrow. Apologies for the disruption.

Any ETA on this?

@KevinGimbel
Copy link

What's missing to get this released? Any way we can support?

@k0ste
Copy link

k0ste commented Nov 18, 2023

@czenker, we've just merged #3509 and I'll be releasing 0.26.1 tomorrow. Apologies for the disruption.

Can you be more specific about what is meant by tomorrow?

@bmgante
Copy link

bmgante commented Nov 26, 2023

I am also having this error in grafana when checking alert manager 0.26 contact points. When can we expect this to be fixed?

error: scheme required for webhook url

@k0ste
Copy link

k0ste commented Dec 13, 2023

@SuperQ please take a look, seems something prevents for a bugfix release .1

@timmow
Copy link

timmow commented Jan 23, 2024

I have also just hit this issue when upgrading alertmanager, and it has broken our automated test suite

@TheMeier
Copy link
Contributor

Should be fixed now?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants