Skip to content

Conversation

@m-burst
Copy link
Contributor

@m-burst m-burst commented Apr 15, 2025

notify.TmplText and notify.TmplHTML use an unusual error handling pattern: the error is not explicitly returned but still must be checked by callers.

In the Telegram notifier the check is missing. Because of this, if template rendering fails, Alertmanager still attempts to send an empty message to Telegram and logs an error with text Bad Request: message text is empty (400).

With this patch applied, Alertmanager will log the actual error that happens during template rendering.

Signed-off-by: Mikhail Burshteyn <mdburshteyn@gmail.com>

messageText, truncated := notify.TruncateInRunes(tmpl(n.conf.Message), maxMessageLenRunes)
if err != nil {
return true, err
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this should be false, no? The message cannot be retried as it will fail again for the same reason?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It will most probably fail again indeed.

However, I see that below in the code true is returned if getBotToken() returns an error. As far as I understand, getBotToken() will not probably recover on its own (only if someone reloads the config or changes the bot_token_file on the filesystem), similarly to the template rendering. This is why I chose true in this case, but I can change this to false if fits better here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think returning true for getBotToken() is also a bug 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, changed this case to false

Signed-off-by: Mikhail Burshteyn <mdburshteyn@gmail.com>
@grobinson-grafana grobinson-grafana merged commit 7980594 into prometheus:main Apr 15, 2025
11 checks passed
@m-burst m-burst deleted the patch-1 branch April 15, 2025 15:22
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.

2 participants