prometheus / prometheus/alertmanager
Add basic arithmetic functions to templating funcmap
@siavashs is already working on this.
Since Jul 24, 2026.
- Dominant language
- Go
- Stars
- 8.6k
- Forks
- 2.5k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 61
Description
Why
I link to grafana dashboards from my prometheus alerts, using some alert labels as grafana variables in the URL to narrow down the dashboard queries. I would like to link to a specific range (eg: 30 mins before/after) around StartsAt and/or EndsAt instead of having to adjust the timeline after opening the link, but this requires basic arithmetic functions (ie: add/sub). In addition, grafana URL params expect unix timestamps in milliseconds, making StartsAt and EndsAt currently unusable, forcing me to return to the alert and manually translate the times from it to grafana via a date picker.
Proposal
Add the following self-explanatory arithmetic functions to DefaultFuncs in https://github.com/prometheus/alertmanager/blob/master/template/template.go
addsubdivmul
From a user perspective, I don't want to worry about types here, so these functions will require type assertions to differentiate between floats and ints (and maybe strconv.Atoi if string, but I'm not sold on the usefulness of that). Still, this should be relatively simple to implement.
Add the following two functions to allow the use of the above arithmetic functions to manipulate the timestamps in StartsAt and EndsAt:
toUnixfromUnix
This is similar to #603 but that request has other concerns about manipulating/accessing current dates, sorting lists etc, so I thought it worth separating the two.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.