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
add
sub
div
mul
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:
toUnix
fromUnix
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.
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
StartsAtand/orEndsAtinstead 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, makingStartsAtandEndsAtcurrently 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
DefaultFuncsin https://github.com/prometheus/alertmanager/blob/master/template/template.goaddsubdivmulFrom 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.Atoiif 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
StartsAtandEndsAt:toUnixfromUnixThis 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.