-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
gotjosh
merged 2 commits into
prometheus:main
from
grobinson-grafana:grobinson/fix-webhook-configs
Sep 5, 2023
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -658,6 +658,28 @@ func (am *Alertmanager) UpdateConfig(conf string) { | |
} | ||
} | ||
|
||
func (am *Alertmanager) ShowRoute() ([]byte, error) { | ||
return am.showRouteCommand() | ||
} | ||
|
||
func (am *Alertmanager) showRouteCommand() ([]byte, error) { | ||
amURLFlag := "--alertmanager.url=" + am.getURL("/") | ||
args := []string{amURLFlag, "config", "routes", "show"} | ||
cmd := exec.Command(amtool, args...) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we also add one for |
||
return cmd.CombinedOutput() | ||
} | ||
|
||
func (am *Alertmanager) TestRoute() ([]byte, error) { | ||
return am.testRouteCommand() | ||
} | ||
|
||
func (am *Alertmanager) testRouteCommand() ([]byte, error) { | ||
amURLFlag := "--alertmanager.url=" + am.getURL("/") | ||
args := []string{amURLFlag, "config", "routes", "test"} | ||
cmd := exec.Command(amtool, args...) | ||
return cmd.CombinedOutput() | ||
} | ||
|
||
func (am *Alertmanager) getURL(path string) string { | ||
return fmt.Sprintf("http://%s%s%s", am.apiAddr, am.opts.RoutePrefix, path) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -168,3 +168,69 @@ receivers: | |
t.Errorf("Incorrect number of silences queried, expected: %v, actual: %v", expectedSils, len(sils)) | ||
} | ||
} | ||
|
||
func TestRoutesShow(t *testing.T) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Revert the fix and this test fails:
|
||
t.Parallel() | ||
|
||
conf := ` | ||
route: | ||
receiver: "default" | ||
group_by: [alertname] | ||
group_wait: 1s | ||
group_interval: 1s | ||
repeat_interval: 1ms | ||
|
||
receivers: | ||
- name: "default" | ||
webhook_configs: | ||
- url: 'http://%s' | ||
send_resolved: true | ||
` | ||
|
||
at := NewAcceptanceTest(t, &AcceptanceOpts{ | ||
Tolerance: 1 * time.Second, | ||
}) | ||
co := at.Collector("webhook") | ||
wh := NewWebhook(co) | ||
|
||
amc := at.AlertmanagerCluster(fmt.Sprintf(conf, wh.Address()), 1) | ||
require.NoError(t, amc.Start()) | ||
defer amc.Terminate() | ||
|
||
am := amc.Members()[0] | ||
_, err := am.ShowRoute() | ||
require.NoError(t, err) | ||
} | ||
|
||
func TestRoutesTest(t *testing.T) { | ||
t.Parallel() | ||
|
||
conf := ` | ||
route: | ||
receiver: "default" | ||
group_by: [alertname] | ||
group_wait: 1s | ||
group_interval: 1s | ||
repeat_interval: 1ms | ||
|
||
receivers: | ||
- name: "default" | ||
webhook_configs: | ||
- url: 'http://%s' | ||
send_resolved: true | ||
` | ||
|
||
at := NewAcceptanceTest(t, &AcceptanceOpts{ | ||
Tolerance: 1 * time.Second, | ||
}) | ||
co := at.Collector("webhook") | ||
wh := NewWebhook(co) | ||
|
||
amc := at.AlertmanagerCluster(fmt.Sprintf(conf, wh.Address()), 1) | ||
require.NoError(t, amc.Start()) | ||
defer amc.Terminate() | ||
|
||
am := amc.Members()[0] | ||
_, err := am.TestRoute() | ||
require.NoError(t, err) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 aURL
, whoseUnmarshalYaml
function also callsparseURL
which contains the same check.