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

Pass Go's time function into the alertmanager templates to be able to do time calculations #3762

Open
aboukhal opened this issue Mar 12, 2024 · 15 comments

Comments

@aboukhal
Copy link

Proposal

Currently, it's not possible to do time calculations when sending alerts to Slack for example. Explicitly converting to another time zone or calculating a duration between startsAt and now would be a tremendous help. There is nothing on Slack/Mattermost's side to do any conversions or calculations there.

This would be easily solved by passing the default time functions into the template at this location.

var DefaultFuncs = FuncMap{

@roidelapluie roidelapluie transferred this issue from prometheus/prometheus Mar 12, 2024
TheMeier added a commit to TheMeier/alertmanager that referenced this issue Mar 20, 2024
TheMeier added a commit to TheMeier/alertmanager that referenced this issue Mar 20, 2024
fixes prometheus#3726
fixes prometheus#3762
fixes prometheus#603

Signed-off-by: Christoph Maser <christoph.maser+github@gmail.com>
TheMeier added a commit to TheMeier/alertmanager that referenced this issue Mar 20, 2024
fixes prometheus#3726
fixes prometheus#3762
fixes prometheus#603

Signed-off-by: Christoph Maser <christoph.maser+github@gmail.com>
TheMeier added a commit to TheMeier/alertmanager that referenced this issue Mar 20, 2024
fixes prometheus#3726
fixes prometheus#3762
fixes prometheus#603

Signed-off-by: Christoph Maser <christoph.maser+github@gmail.com>
TheMeier added a commit to TheMeier/alertmanager that referenced this issue Mar 22, 2024
fixes prometheus#3726
fixes prometheus#3762
fixes prometheus#603

Signed-off-by: Christoph Maser <christoph.maser+github@gmail.com>
TheMeier added a commit to TheMeier/alertmanager that referenced this issue Mar 22, 2024
fixes prometheus#3726
fixes prometheus#3762
fixes prometheus#603

Signed-off-by: Christoph Maser <christoph.maser+github@gmail.com>
TheMeier added a commit to TheMeier/alertmanager that referenced this issue Mar 24, 2024
fixes prometheus#3726
fixes prometheus#3762
fixes prometheus#603

Signed-off-by: Christoph Maser <christoph.maser+github@gmail.com>
TheMeier added a commit to TheMeier/alertmanager that referenced this issue Mar 24, 2024
fixes prometheus#3726
fixes prometheus#3762
fixes prometheus#603

Signed-off-by: Christoph Maser <christoph.maser+github@gmail.com>
TheMeier added a commit to TheMeier/alertmanager that referenced this issue Mar 24, 2024
fixes prometheus#3726
fixes prometheus#3762
fixes prometheus#603

Signed-off-by: Christoph Maser <christoph.maser+github@gmail.com>
TheMeier added a commit to TheMeier/alertmanager that referenced this issue Mar 24, 2024
fixes prometheus#3726
fixes prometheus#3762
fixes prometheus#603

Signed-off-by: Christoph Maser <christoph.maser+github@gmail.com>
@grobinson-grafana
Copy link
Contributor

We added date and timezone functions here.

@aboukhal
Copy link
Author

This is awesome. Although, since so little from time is passed through, calculations are still not possible.

@grobinson-grafana
Copy link
Contributor

Perhaps I misunderstood, what calculations would you like to do?

@aboukhal
Copy link
Author

As I wrote initially:

or calculating a duration between startsAt and now

In an alert I would like to create text, such as "started 3 hours, 22 minutes ago". This is especially helpful for a repeated message, to see that this is ongoing instead of new, or for the resolved message, to have a clear documentation of how long an issue was present.

@grobinson-grafana
Copy link
Contributor

As I wrote initially:

or calculating a duration between startsAt and now

In an alert I would like to create text, such as "started 3 hours, 22 minutes ago". This is especially helpful for a repeated message, to see that this is ongoing instead of new, or for the resolved message, to have a clear documentation of how long an issue was present.

Oh OK. You want a humanize function / or ago function. I think we can add that!

@grobinson-grafana
Copy link
Contributor

grobinson-grafana commented Apr 27, 2024

Keep in mind the started at text will be relative to the time the notification was sent. So if the alert started at 09:00 UTC, and the notification was sent at 10:00 UTC, then the text would be "started one hour ago". However, suppose you don't see the notification until 11:00 UTC, the text will still say "started one hour ago" even though it actually started two hours ago.

TheMeier added a commit to TheMeier/alertmanager that referenced this issue Apr 27, 2024
fixes prometheus#3726
fixes prometheus#3762
fixes prometheus#603

Signed-off-by: Christoph Maser <christoph.maser+github@gmail.com>
TheMeier added a commit to TheMeier/alertmanager that referenced this issue May 3, 2024
fixes prometheus#3726
fixes prometheus#3762
fixes prometheus#603

Signed-off-by: Christoph Maser <christoph.maser+github@gmail.com>
TheMeier added a commit to TheMeier/alertmanager that referenced this issue May 8, 2024
fixes prometheus#3726
fixes prometheus#3762
fixes prometheus#603

Signed-off-by: Christoph Maser <christoph.maser+github@gmail.com>
TheMeier added a commit to TheMeier/alertmanager that referenced this issue May 8, 2024
fixes prometheus#3726
fixes prometheus#3762
fixes prometheus#603

Signed-off-by: Christoph Maser <christoph.maser+github@gmail.com>
@bryanasdev000
Copy link

bryanasdev000 commented May 13, 2024

Related:

#3717

#3720

prometheus/common#627

@aboukhal
Copy link
Author

Keep in mind the started at text will be relative to the time the notification was sent. So if the alert started at 09:00 UTC, and the notification was sent at 10:00 UTC, then the text would be "started one hour ago". However, suppose you don't see the notification until 11:00 UTC, the text will still say "started one hour ago" even though it actually started two hours ago.

Yes, this is expected and is consistent with how chatops usually displays things.

@aboukhal
Copy link
Author

Is there a specific design decision why you don't want to pass though the entire time through, instead of covering the use cases one by one? That way the end user would be able to do anything that is covered by Go's time functions.

@grobinson-grafana
Copy link
Contributor

Hi! 👋 Most of the functions in time are methods, so you should be able to use them. We don't pass all of the functions in because there are some we don't want to add to templates like time.Sleep.

@freak12techno
Copy link
Contributor

I want to add time.Since and pretty formatting a duration and filed an issue on that here: #3717
We agreed to move humanizeDuration from prometheus to common package to reuse it here, so I did this prometheus/common#627 but it's still in review.
After this is done and merged, we can import it here and use it here as well.

Can someone from Alertmanager team review it? (@grobinson-grafana maybe?)

@grobinson-grafana
Copy link
Contributor

I can do a review! 🙂 I can't merge it as I'm not an Alertmanager maintainer, but I'll let @gotjosh know when I've reviewed it for him to look at too.

TheMeier added a commit to TheMeier/alertmanager that referenced this issue Jun 14, 2024
fixes prometheus#3726
fixes prometheus#3762
fixes prometheus#603

Signed-off-by: Christoph Maser <christoph.maser+github@gmail.com>
@aboukhal
Copy link
Author

aboukhal commented Aug 6, 2024

I believe this issue is fixed by #3863. I would love to test it - is there a schedule for the next release? If it works as advertised, I'll happily close this ticket myself.
Thanks for your effort, @freak12techno

@freak12techno
Copy link
Contributor

@aboukhal yes, you can build from source to test it. As per the new release, I am not an Alertmanager maintainer, so I do not know. @gotjosh can you maybe ping someone or answer here?

@aboukhal
Copy link
Author

aboukhal commented Aug 6, 2024

It's... challenging to build external projects in our environment to say the least. Otherwise I would have been more actively involved in this issue from the start. So unfortunately I can only test it once it's released.

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 a pull request may close this issue.

4 participants