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

Fix scheme required for webhook url in amtool #3509

Merged

Conversation

grobinson-grafana
Copy link
Contributor

@grobinson-grafana grobinson-grafana commented Sep 5, 2023

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.

@@ -168,3 +168,36 @@ receivers:
t.Errorf("Incorrect number of silences queried, expected: %v, actual: %v", expectedSils, len(sils))
}
}

func TestRoutesShow(t *testing.T) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert the fix and this test fails:

--- FAIL: TestRoutesShow (1.09s)
    cli_test.go:202: amtool: error: scheme required for webhook url

    cli_test.go:203:
        	Error Trace:	/Users/grobinson/go/src/github.com/prometheus/alertmanager/test/cli/acceptance/cli_test.go:203
        	Error:      	Received unexpected error:
        	            	exit status 1
        	Test:       	TestRoutesShow
FAIL

@@ -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 {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We think this is duplicate code as SecretURL is just a URL, whose UnmarshalYaml function also calls parseURL which contains the same check.

@simonpasquier
Copy link
Member

Thanks! I'd be inclined to have the fix in the release-0.26 branch.

@grobinson-grafana grobinson-grafana changed the title Fix scheme requireed for webhook url in amtool Fix scheme required for webhook url in amtool 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 <[email protected]>
@grobinson-grafana
Copy link
Contributor Author

Apologies for the force push, there was a spelling mistake in the commit message.

@gotjosh
Copy link
Member

gotjosh commented Sep 5, 2023

Thanks! I'd be inclined to have the fix in the release-0.26 branch.

I believe this warrants a 0.26.1.

func (am *Alertmanager) showRouteCommand() ([]byte, error) {
amURLFlag := "--alertmanager.url=" + am.getURL("/")
args := []string{amURLFlag, "config", "routes", "show"}
cmd := exec.Command(amtool, args...)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also add one for config routes test?

Signed-off-by: George Robinson <[email protected]>
Copy link
Member

@gotjosh gotjosh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Thank you very much for your contribution.

@gotjosh gotjosh merged commit 6ce841c into prometheus:main Sep 5, 2023
1 check passed
gotjosh pushed a commit that referenced this pull request 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 <[email protected]>

* Add test for config routes test

Signed-off-by: George Robinson <[email protected]>

---------

Signed-off-by: George Robinson <[email protected]>
gotjosh pushed a commit that referenced this pull request 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 <[email protected]>

* Add test for config routes test

Signed-off-by: George Robinson <[email protected]>

---------

Signed-off-by: George Robinson <[email protected]>
Signed-off-by: gotjosh <[email protected]>
@grobinson-grafana grobinson-grafana deleted the grobinson/fix-webhook-configs branch April 16, 2024 14:44
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

Successfully merging this pull request may close these issues.

3 participants