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

Add Telegram Receiver type to AlertmanagerConfig CRD #4726

Merged
merged 11 commits into from May 16, 2022

Conversation

angelbarrera92
Copy link
Contributor

@angelbarrera92 angelbarrera92 commented Apr 18, 2022

Description

Add Telegram Receiver type to AlertmanagerConfig CRD
Fixes #4703

There are a few things to consider while using this new feature:

Type of change

  • 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.)

Changelog entry

Add Telegram Receiver type to AlertmanagerConfig CRD

- Add Telegram Receiver type to AlertmanagerConfig CRD

@angelbarrera92 angelbarrera92 force-pushed the issues/4703 branch 6 times, most recently from 20d8a02 to 432aaaa Compare April 19, 2022 15:53
@angelbarrera92 angelbarrera92 changed the title WIP: Add Telegram Receiver type to AlertmanagerConfig CRD Add Telegram Receiver type to AlertmanagerConfig CRD Apr 19, 2022
@angelbarrera92 angelbarrera92 marked this pull request as ready for review April 19, 2022 16:49
@angelbarrera92 angelbarrera92 requested a review from a team as a code owner April 19, 2022 16:49
@angelbarrera92 angelbarrera92 force-pushed the issues/4703 branch 6 times, most recently from 6783b9f to 7ef6c27 Compare April 23, 2022 06:49
@angelbarrera92
Copy link
Contributor Author

@philipgough i did the changes mentioned above :)
let me know if everything is fine or if there are something else missing

// +optional
DisableNotifications *bool `json:"disableNotifications,omitempty"`
// Parse mode for telegram message
//+kubebuilder:validation:Enum="";MarkdownV2;Markdown;HTML
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: since this is marked as optional, I don't believe we need to include the empty string in the enum

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ye! I was having doubts with the enum, I looked for examples in the project and I found:
https://github.com/prometheus-operator/prometheus-operator/blob/main/pkg/apis/monitoring/v1/thanos_types.go#L145
So I decided to leave it with the empty value as it is a valid value documented: https://prometheus.io/docs/alerting/latest/configuration/#telegram_config

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Still, if you think it could be better to remove it... let me know and I'll do it

Copy link
Contributor

Choose a reason for hiding this comment

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

I did a quick test and indeed the Kube API makes a distinction between

  • "the field is not present in the submitted request" ✔️
  • "the field is present and the value is empty" 🚫
  • "the field is present and the value is in the enums list" ✔️

From an API perspective, it's probably better to remove "" from the allowed values but we can tackle in a follow-up PR and globally.

Copy link
Contributor

@philipgough philipgough left a comment

Choose a reason for hiding this comment

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

/lgtm

thanks @angelbarrera92 for the contribution.

@simonpasquier - do you want to take a look before we merge?

pkg/apis/monitoring/v1alpha1/alertmanager_config_types.go Outdated Show resolved Hide resolved
// +optional
DisableNotifications *bool `json:"disableNotifications,omitempty"`
// Parse mode for telegram message
//+kubebuilder:validation:Enum="";MarkdownV2;Markdown;HTML
Copy link
Contributor

Choose a reason for hiding this comment

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

I did a quick test and indeed the Kube API makes a distinction between

  • "the field is not present in the submitted request" ✔️
  • "the field is present and the value is empty" 🚫
  • "the field is present and the value is in the enums list" ✔️

From an API perspective, it's probably better to remove "" from the allowed values but we can tackle in a follow-up PR and globally.

pkg/alertmanager/validation.go Outdated Show resolved Hide resolved
pkg/alertmanager/validation.go Outdated Show resolved Hide resolved
pkg/alertmanager/operator.go Outdated Show resolved Hide resolved
pkg/alertmanager/operator.go Outdated Show resolved Hide resolved
pkg/alertmanager/amcfg.go Show resolved Hide resolved
pkg/alertmanager/amcfg.go Outdated Show resolved Hide resolved
pkg/alertmanager/amcfg.go Outdated Show resolved Hide resolved
@angelbarrera92
Copy link
Contributor Author

I think I resolved all the points @simonpasquier raised, so asking for a new review round!
Thanks!

@angelbarrera92
Copy link
Contributor Author

Maybe I can do a rebase to squash all commits before merging. What do you think?

@simonpasquier
Copy link
Contributor

Maybe I can do a rebase to squash all commits before merging. What do you think?

We can "Squash and merge" from the GitHub UI :)

@philipgough
Copy link
Contributor

@angelbarrera92 - thanks for taking care of this. Looks in good shape now but needs a rebase :)

@angelbarrera92 angelbarrera92 force-pushed the issues/4703 branch 2 times, most recently from a9d8d4d to f2c3d14 Compare May 9, 2022 14:01
@angelbarrera92
Copy link
Contributor Author

@angelbarrera92 - thanks for taking care of this. Looks in good shape now but needs a rebase :)

Ready!

@mtb-xt
Copy link

mtb-xt commented May 16, 2022

Guys please merge this! ⏳

angelbarrera92 and others added 11 commits May 16, 2022 09:32
This commit adds the logic to enable the usage of telegram as receiver for alertmanger

Fixes: prometheus-operator#4703
Changes chatID from secret to int and adds a check for the alertmanager version

Fixes: prometheus-operator#4703
Moves parseMode to be an enum in the telegram configuration.

Fixes: prometheus-operator#4703
Removes not needed validation as the input is validated with the openAPI schema

Fixes: prometheus-operator#4703
change errors -> fmt

Co-authored-by: Simon Pasquier <spasquie@redhat.com>
change errors -> fmt

Co-authored-by: Simon Pasquier <spasquie@redhat.com>
change error message as suggested

Co-authored-by: Simon Pasquier <spasquie@redhat.com>
check if exists config before checking the version

Co-authored-by: Simon Pasquier <spasquie@redhat.com>
Move botToken and chatID validation to sanitize function
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.

Add Telegram Receiver type to AlertmanagerConfig CRD
4 participants