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: One Alertmanager Config failing blocks all others. #6585

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

codeknight03
Copy link
Contributor

Description

We need to validate the urls passed as secrets in AlertManagerConfig receivers ( Slack and Discord in particular) to ensure we discard the faulty config early and don't create a hang up at the conversion stage.
Closes #6532

Type of change

What type of changes does your code introduce to the Prometheus operator? Put an x in the box that apply.

  • CHANGE (fix or feature that would cause existing functionality to not work as expected)
  • FEATURE (non-breaking change which adds functionality)
  • BUGFIX (non-breaking change which fixes an issue)
  • ENHANCEMENT (non-breaking change which improves existing functionality)
  • NONE (if none of the other choices apply. Example, tooling, build system, CI, docs, etc.)

Verification

Build the image and try passing a malformed url in slack config for which the operator logs show error.

Changelog entry

Please put a one-line changelog entry below. This will be copied to the changelog file during the release process.

   Fix one alertmanagerconfig failing to sync blocks all others

@yp969803
Copy link
Contributor

yp969803 commented May 16, 2024

@codeknight03 seen youe commits, i think this will resolve the issue, as the invalid URLs can be detected now before generating configFile, Can you write the unit tests for this, for confirmation.
You can also merge your commits into a single commit.

return err
}
if _, err := validation.ValidateURL(strings.TrimSpace(url)); err != nil {
return fmt.Errorf("discord webhook 'url' %s invalid: %w", url, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

The error from ValidateURL() already contains the URL value. Also since we treat the URL as a secret, we shouldn't log it and we'd need a ValidateSecretURL() function.

Suggested change
return fmt.Errorf("discord webhook 'url' %s invalid: %w", url, err)
return err

Copy link
Contributor

Choose a reason for hiding this comment

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

we'd need a ValidateSecretURL() function

You mean we'd need to define a new ValidateSecretURL() function? Why? I thought we already got the URL string from GetSecretKey() in the previous line, so ValidateURL() is enough? 🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

It's because ValidateURL() would return the URL value in the error which isn't something you want for a "secret" URL.

@haanhvu
Copy link
Contributor

haanhvu commented May 19, 2024

I took a look at this. Here's what I see:

  • Have you reproduced this issue before the fix? Have you reproduced this issue again with the fix to see if it works?
  • I haven't reproduced. But from what I see in the codebase this change seems working. Besides Discord and Slack, do we need validation for other receivers too?
  • I think we need a new test case for each receiver's invalid url in TestProvisionAlertmanagerConfiguration in pkg/alertmanager/operator_test.go (need @simonpasquier or other maintainers to confirm though)

@simonpasquier
Copy link
Contributor

Thanks @haanhvu for the comments. Yes I agree that we'd need unit tests to validate the fix.

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

Successfully merging this pull request may close these issues.

One AlertmanagerConfig failing to sync, blocks all others
4 participants