-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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 parseDuration function to templates #3816
base: main
Are you sure you want to change the base?
Conversation
ec4ab14
to
2d89845
Compare
I have one question about the intended use case. Wouldn't it be better to have the For example, instead of this: "annotations": {
"title": "Alert Summary text",
"description": "Detailed alert description",
"log_url": "https://grafana.example.com ...from=%from%, to=%to%",
"grafana_dashboard_range": "-2m"
}, Have this: "annotations": {
"title": "Alert Summary text",
"description": "Detailed alert description",
"log_url": "https://grafana.example.com ...from=now, to=-2h"
}, |
We use Alertmanager not only with Prometheus but also with Loki, and in LogQL, there are no functions to get the current timestamp. There is an open issue describing such a case. Therefore, we cannot form values for If we add a |
2d89845
to
740a580
Compare
OK! 👍 The reason I asked is I was looking at this example:
and made the following observations:
Would print:
|
I couldn't find another solution in the case with Loki that would allow getting the timestamp of the moment when the alert-triggering logic is activated, as well as a way to perform operations with this timestamp (adding or subtracting time intervals to get a range). The only "hack" way is the fact that
This is a simplified version of the template, and the responsibility for preparing data in custom templates rests with the end user. Most often, we use this approach in the template for creating buttons in messages sent to Slack. If there is an error in forming the URL, the button simply will not be displayed in the message.
I can change the name of the function to eliminate ambiguous interpretation of its functionality. For example, name it |
I just want to make sure there is no-misunderstanding here too. I'm not against adding a function to parse time durations to do operations on However, I also think Prometheus, Mimir and Loki should make the
I appreciate that you cannot do this right now because those features are missing, and why you're having to do it in the notification template instead. I think we should create an issue in prometheus/prometheus for StartsAt and related time functions to be made available in annotation templates. @gotjosh what do you think? |
740a580
to
99674c4
Compare
I agree that splitting the logic of forming alert messages and moving part of it to Alertmanager is not the best idea. I would prefer to have this functionality available on the Prometheus or Loki side. Therefore, I will definitely support the idea of creating an issue in the repositories of these products. While this functionality is not available on the Prometheus or Loki side, I would still request that my custom function be accepted into the code that handles template processing in Alertmanager. I have renamed the function to |
Yeah I asked @gotjosh for a second opinion as he is an official maintainer and I'm not 🙂 |
Signed-off-by: Vadim Aleksandrov <valeksandrov@me.com>
99674c4
to
cf28754
Compare
@gotjosh, @grobinson-grafana, can I help with the review process of this PR in any way? |
I add a
duration
function. This would, for example, allow generating links to a grafana dashboards where a time range for display can be passed.We will pass a time offset in the annotation and use it to generate the link in the following way:
Alert data:
Alert template:
The function itself is very simple: