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

Extend discord messages with content #4007

Merged
merged 4 commits into from
Oct 23, 2024
Merged

Conversation

mogoll92
Copy link
Contributor

@mogoll92 mogoll92 commented Aug 30, 2024

These changes are aimed to support discord content parameter besides with embedded message and allow to overcome limitation when you need to ping someone or group of people. (Ping over embedded messages doesn't trigger discord notifications)

Alertmanager already has struct that allows to send content.

type webhook struct {
	Content string         `json:"content"`
	Embeds  []webhookEmbed `json:"embeds"`
}

These changes make content optional and allow to send any text that doesn't break discord limits with embedded message.
To enable this user should apply the following changes:

receivers:
  - name: nothing
  - name: discord-success
    discord_configs:
      - webhook_url: ""
        content: '{{ template "discord.content" . }}'
        title: '{{ template "discord.title" . }}'
        message: '{{ template "discord.message" . }}'

and override text in custom template like the following.

{{ define "discord.content" }}
Hey you! <@6532081833221312329>
{{ end }}

Here is the result.
Screenshot 2024-08-30 at 15 34 41

@grobinson-grafana
Copy link
Contributor

Hello! 👋 I think this might be a duplicate of #3821?

@mogoll92
Copy link
Contributor Author

mogoll92 commented Aug 30, 2024

Hello! 👋 I think this might be a duplicate of #3821?

Yeah, I saw that PR but looks like author is not interested in pushing it forward and I really don't see value in making that additional changes with avatar and username. The only feature that makes sense there is content that is really needed in cases there you need to ping ppl outside.

@grobinson-grafana
Copy link
Contributor

Sounds good to me! Before I review, it looks like you have somehow brought in a number of additional commits that aren't relevant to your PR. For example, commits fbcb49b and c07eec8. Can you fix your PR to remove those additional commits? I think just we need commits ae07f25 and 5875042.

@grobinson-grafana
Copy link
Contributor

Hi, looks like you added even more commits?

@mogoll92
Copy link
Contributor Author

mogoll92 commented Sep 2, 2024

Hi, looks like you added even more commits?

yeah, a bit struggled on replacing with needed set of commits. I will ping you here once I'm done.

@mogoll92 mogoll92 force-pushed the main branch 2 times, most recently from b7a6c23 to 6e7b460 Compare September 2, 2024 13:28
@mogoll92
Copy link
Contributor Author

mogoll92 commented Sep 2, 2024

@grobinson-grafana check if nothing needs to add, please.

@featheredtoast
Copy link
Contributor

Is this still being looked at? I am interested in the avatar/username fields, and it'd be nice for this work to be in place before chipping away at adding other fields.

@gotjosh gotjosh mentioned this pull request Oct 22, 2024
@@ -123,6 +123,7 @@ Alerts Resolved:
{{ end }}
{{ end }}

{{ define "discord.default.content" }}{{ end }}
Copy link
Contributor

Choose a reason for hiding this comment

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

You want to update DefaultDiscordConfig on Line 46 of config/notifiers.go so this template is used.

@grobinson-grafana
Copy link
Contributor

I've tested it and looks good to me! I've left a comment of something small that's missing. Please also add some documentation for this in docs/configuration.md.

Something that I'm still not 100% satisfied with is the intuitiveness of title, message and content. It seems like users will be confused when to use title and message and when to use content.

Since the use case here is mentioning users, and nothing else, it might make more sense to do the following instead:

receivers:
  - name: discord
    discord_configs:
      - webhook_url: https://discord.com/api/webhooks/abc
        title: '{{ template "discord.title" . }}'
        message: '{{ template "discord.message" . }}'
        mentions:
          - 6532081833221312329

This will avoid the confusion and be more intuitive to users while still solving the intended use case.

@mogoll92
Copy link
Contributor Author

mogoll92 commented Oct 23, 2024

I've tested it and looks good to me! I've left a comment of something small that's missing. Please also add some documentation for this in docs/configuration.md.

Something that I'm still not 100% satisfied with is the intuitiveness of title, message and content. It seems like users will be confused when to use title and message and when to use content.

Since the use case here is mentioning users, and nothing else, it might make more sense to do the following instead:

receivers:
  - name: discord
    discord_configs:
      - webhook_url: https://discord.com/api/webhooks/abc
        title: '{{ template "discord.title" . }}'
        message: '{{ template "discord.message" . }}'
        mentions:
          - 6532081833221312329

This will avoid the confusion and be more intuitive to users while still solving the intended use case.

It will confuse even more, as there is no mentions entity in discord, mentions is some kind of feature that you can use in context, but it isn't the same. Overall in discord the embedded message it's a part of the message and can't exist separately. If you would like to have mirror between alertmanager discord configuration and discord's entities I would recommend the following structure.

receivers:
  - name: discord
    discord_configs:
      - webhook_url: https://discord.com/api/webhooks/abc
        context: '{{ template "discord.content" . }}'
        embedded:
            title: '{{ template "discord.title" . }}'
            message: '{{ template "discord.message" . }}'

In this case it represent exactly what it is. Also this structure could be extended with other fields that discord supports.

@grobinson-grafana
Copy link
Contributor

If you would like to have mirror between alertmanager discord configuration and discord's entities I would recommend the following structure.

The problem we have is that renaming/moving/deleting existing fields creates a lot of complex migration issues for other software that builds on top of Alertmanager, like Cortex and Mimir. We can add new fields, but making breaking changes to existing ones is hard.

Could you please update the documentation in docs/configuration.md for this new field? We can then merge it and add it to the 0.28 release.

Copy link
Member

@gotjosh gotjosh left a comment

Choose a reason for hiding this comment

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

LGTM

I'll add the documentation in a follow up PR.

@gotjosh gotjosh enabled auto-merge (squash) October 23, 2024 13:35
@gotjosh gotjosh disabled auto-merge October 23, 2024 13:35
@gotjosh gotjosh mentioned this pull request Oct 23, 2024
@gotjosh
Copy link
Member

gotjosh commented Oct 23, 2024

Hey @mogoll92 I'll give you about ~30 minutes or so to see if you can get it sorted and update the documentation. Otherwise, I'll proceed with #4080 unless you feel oppose to it.

@mogoll92
Copy link
Contributor Author

Hey @mogoll92 I'll give you about ~30 minutes or so to see if you can get it sorted and update the documentation. Otherwise, I'll proceed with #4080 unless you feel oppose to it.

if it's okay to you feel free to proceed with it, no objections at all.

Signed-off-by: Yevhen Sydorenko <[email protected]>

Signed-off-by: Yevhen Sydorenko <[email protected]>
Updated assets_vfsdata.go

Signed-off-by: Yevhen Sydorenko <[email protected]>
@gotjosh
Copy link
Member

gotjosh commented Oct 23, 2024

Can you rebase and update the vfs_asserts?

Signed-off-by: Yevhen Sydorenko <[email protected]>
Signed-off-by: Yevhen Sydorenko <[email protected]>
@gotjosh gotjosh merged commit 6b77acd into prometheus:main Oct 23, 2024
11 checks passed
@gotjosh
Copy link
Member

gotjosh commented Oct 23, 2024

Thank you very much for your contribution!

@mogoll92
Copy link
Contributor Author

Thank you very much for your contribution!

you are welcome, first of all I need those changes so I'm interested in it. Thought it never will be happened since so much time passed with no response :)

gotjosh added a commit that referenced this pull request Oct 24, 2024
* Release v0.28.0-rc.0

* [CHANGE] Templating errors in the SNS integration now return an error. #3531 #3879
* [FEATURE] Add a new Microsoft Teams integration based on Flows #4024
* [FEATURE] Add a new Rocket.Chat integration #3600
* [FEATURE] Add a new Jira integration #3590 #3931
* [FEATURE] Add support for `GOMEMLIMIT`, enable it via the feature flag `--enable-feature=auto-gomemlimit`. #3895
* [FEATURE] Add support for `GOMAXPROCS`, enable it via the feature flag `--enable-feature=auto-gomaxprocs`. #3837
* [FEATURE] Add support for limits of silences including the maximum number of active and pending silences, and the maximum size per silence (in bytes). You can use the flags `--silences.max-silences` and `--silences.max-silence-size-bytes` to set them accordingly #3852 #3862 #3866 #3885 #3886 #3877
* [FEATURE] Muted alerts now show whether they are suppressed or not in both the `/api/v2/alerts` endpoint and the Alertmanager UI. #3793 #3797 #3792
* [ENHANCEMENT] Add support for `content`, `username` and `avatar_url` in the Discord integration. `content` and `username` also support templating. #4007
* [ENHANCEMENT] Only invalidate the silences cache if a new silence is created or an existing silence replaced - should improve latency on both `GET api/v2/alerts` and `POST api/v2/alerts` API endpoint. #3961
* [ENHANCEMENT] Add image source label to Dockerfile. To get changelogs shown when using Renovate #4062
* [ENHANCEMENT] Build using go 1.23 #4071
* [ENHANCEMENT] Support setting a global SMTP TLS configuration. #3732
* [ENHANCEMENT] The setting `room_id` in the WebEx integration can now be templated to allow for dynamic room IDs. #3801
* [ENHANCEMENT] Enable setting `message_thread_id` for the Telegram integration. #3638
* [ENHANCEMENT] Support the `since` and `humanizeDuration` functions to templates. This means users can now format time to more human-readable text. #3863
* [ENHANCEMENT] Support the `date` and `tz` functions to templates. This means users can now format time in a specified format and also change the timezone to their specific locale. #3812
* [ENHANCEMENT] Latency metrics now support native histograms. #3737
* [BUGFIX] Fix the SMTP integration not correctly closing an SMTP submission, which may lead to unsuccessful dispatches being marked as successful. #4006
* [BUGFIX]  The `ParseMode` option is now set explicitly in the Telegram integration. If we don't HTML tags had not been parsed by default. #4027
* [BUGFIX] Fix a memory leak that was caused by updates silences continuously. #3930
* [BUGFIX] Fix hiding secret URLs when the URL is incorrect. #3887
* [BUGFIX] Fix a race condition in the alerts - it was more of a hypothetical race condition that could have occurred in the alert reception pipeline. #3648
* [BUGFIX] Fix a race condition in the alert delivery pipeline that would cause a firing alert that was delivered earlier to be deleted from the aggregation group when instead it should have been delivered again. #3826
* [BUGFIX] Fix version in APIv1 deprecation notice. #3815
* [BUGFIX] Fix crash errors when using `url_file` in the Webhook integration. #3800
* [BUGFIX] fix `Route.ID()` returns conflicting IDs. #3803
* [BUGFIX] Fix deadlock on the alerts memory store. #3715
* [BUGFIX] Fix `amtool template render` when using the default values. #3725
* [BUGFIX] Fix `webhook_url_file` for both the Discord and Microsoft Teams integrations. #3728 #3745

---------

Signed-off-by: SuperQ <[email protected]>
Signed-off-by: gotjosh <[email protected]>
Co-authored-by: gotjosh <[email protected]>
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.

4 participants