Skip to content

Support for Incident Timings in Alert Messages #90

@sh-divyansh

Description

@sh-divyansh

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

  1. 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).
  2. 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".
  3. DurationSince(pastTime time.Time) (string, error):

    • Calculates the human-readable time elapsed since t (e.g., incident start time).

Example Template Usage

  1. Without Timezone:
*Incident Timings*:
⏳`Start   `: {{ .StartsAt }}
⌛`Current `: {{ CurrentTime }}
⏱️`Duration`: *{{ DurationSince .StartsAt }}*
Image

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

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions