Requesting feedback: New docs for templating labels and annotations

Hello! :wave:

It’s been about 8 months since I rewrote the documentation for templating labels and annotations. However, I’m seeing a lot of confusion on the forums about how the templating language works and how to use.

To see if I can improve on this I’ve rewritten the documentation once more. There is no longer a topic on how to write text/template. Instead, the documentation has been made into a showcase of practical, useful templates that can be used verbatim or adjusted to your specific needs. You can still learn text/template using these examples, but much of explanations for how it works is now deferred to the official documentation and other tutorials online.

It would be great to get some feedback on this change from the community to see if you find it more or less helpful and what is still missing.

You can find the link to it here Templating labels and annotations | Grafana documentation.


:star_struck: Thank you.
Q: Is there a way a how to work (print, format) with timestamp(s) from timestamp/label/value in the template?

I’m kind of following, but not sure I fully understand. Do you have an example?

I have alert from timeseries and I want to print timestamp of value in the alert in my local format (in the same as we have for variable Add and manage variables | Grafana documentation) - will it be possible?

If I understood, you can template the timestamp that the alert fired in a notification template, but you cannot template the timestamp of the metric in the template for a custom label or annotation. The reason for that is that it gets weird once you start to do functions on metrics. If your alert is on the average of 10 metrics, which timestamp does it use? What about the 95th percentile? You see what I mean?

Ok, what if I have timestamp as label parsed from log line and I want to format it, when alert is raised (My real use case: I’m watching Grafana audit logs from Loki - it’s “event” detected alert, so I wouldn’t have multiple metrics for calculation). I think it can be real use case.

I think we could support something for that. It’s not supported at present. There are some LogQL functions that let you format dates from within the query, although I’m not sure if that should be put in the templating documentation. I’ll discuss with the team about adding support for date functions.

1 Like