-
Notifications
You must be signed in to change notification settings - Fork 62
Description
Description
This feature request proposes adding incident timing-related functions to message templates, enabling users to include start times, durations, and current timestamps (with optional timezone support) in alert messages.
This feature leverages the StartsAt
field from the Prometheus Alert notification template, which provides the timestamp when the alert was first triggered.
Proposed Template Functions
-
CurrentTime(location ...string) string
:- Returns the current time.
- If a timezone is provided, it returns the current time in the specified timezone.
- If no timezone is provided, it returns the current time in the default format (
2025-05-03 15:42:53.754 +0000 UTC
).
-
ConvertTZ(t time.Time, location string) (string, error)
:- Converts a time.Time object to the specified timezone.
- Example: Converts
2025-05-03 13:41:53.754 +0000 UTC
->Sat, 03 May 2025 7:11:53 PM IST
for"Asia/Kolkata"
.
-
DurationSince(pastTime time.Time) (string, error)
:- Calculates the human-readable time elapsed since t (e.g., incident start time).
Example Template Usage
- Without Timezone:
*Incident Timings*:
⏳`Start `: {{ .StartsAt }}
⌛`Current `: {{ CurrentTime }}
⏱️`Duration`: *{{ DurationSince .StartsAt }}*

- With Timezone:
*Incident Timings*:
⏳`Start `: {{ ConvertTZ .StartsAt "Asia/Kolkata" }}
⌛`Current `: {{ CurrentTime "Asia/Kolkata" }}
⏱️`Duration`: *{{ DurationSince .StartsAt }}*

I have been using these in Lenskart's monitoring system for the past six months. By providing detailed incident timing information, they have significantly improved the clarity and usability of alert messages.
Looking forward to your feedback.
Thank you for creating and maintaining this tool! It has been incredibly useful for us.