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

Alerting: Fix configuration of both incoming webhooks and bot tokens #69

Closed
wants to merge 1 commit into from

Conversation

grobinson-grafana
Copy link
Contributor

@grobinson-grafana grobinson-grafana commented Mar 16, 2023

This commit fixes a bug in Slack where it was possible to configure both incoming webhooks and bot tokens at the same time. This is a bug as the intended behaviour is that users configure one or the other, but not both.

Fixes #68

Support escalation: https://github.com/grafana/support-escalations/issues/5309

This commit fixes a bug in Slack where it was possible to configure
both incoming webhooks and bot tokens at the same time. This is a
bug as the intended behaviour is that users configure one or the other,
but not both.
@grobinson-grafana grobinson-grafana added the bug Something isn't working label Mar 16, 2023
@grobinson-grafana grobinson-grafana self-assigned this Mar 16, 2023
@@ -3,7 +3,6 @@ package slack
// FullValidConfigForTesting is a string representation of a JSON object that contains all fields supported by the notifier Config. It can be used without secrets.
const FullValidConfigForTesting = `{
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure what to do with these Yuri. Should I create one for incoming webhooks and another for bot tokens?

Copy link
Contributor

Choose a reason for hiding this comment

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

I would suggest to update this one and create another test with another combination of fields

@@ -256,7 +255,7 @@ func TestNewConfig(t *testing.T) {
settings: FullValidConfigForTesting,
expectedConfig: Config{
EndpointURL: "http://localhost/endpoint_url",
URL: "http://localhost/url",
URL: "http://localhost/endpoint_url",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was changed to make the tests pass, but I think these tests need to be changed as they are based on the assumption you can configure both incoming webhooks and bot tokens at the same time.

@grobinson-grafana grobinson-grafana requested a review from a team March 16, 2023 11:04
@JacobsonMT
Copy link
Member

I'm not certain this is the way to go here, we have all the necessary information to send a notification correctly. Instead of erroring when both a URL and a token are provided, we could instead log a warning and use either the token or the webhook url (author's choice).

This is obviously niche since UI validation should prevent this in the first place, but if they do happen to get into this state (like in the escalation) maybe warning + continue as normal is better than error. What do you think?

@grobinson-grafana
Copy link
Contributor Author

I'm not certain this is the way to go here, we have all the necessary information to send a notification correctly. Instead of erroring when both a URL and a token are provided, we could instead log a warning and use either the token or the webhook url (author's choice).

Once Slack is configured we don't know if its a token or a webhook because the URL field is re-used when using a webhook and the bot token. For example, when using an incoming webhook the URL is https://hooks.slack.com/abc and the token is "", but when using a bot token the URL is https://api.slack.com and the token is "abc".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Slack allows configuration of both incoming webhooks and bot tokens at the same time
3 participants