8000 Add parseDurationTime in templating by iamhalje · Pull Request #16619 · prometheus/prometheus · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add parseDurationTime in templating #16619

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

iamhalje
Copy link
@iamhalje iamhalje commented May 20, 2025

Currently, Prometheus template functions include parseDuration, which parses a duration string (e.g. "1h2m10ms") and returns the total duration in seconds as a float. However, it is often more useful to work directly with Go time.Duration objects or time.Time operations in templates for alerting and logging purposes.

For example, in Loki alerting, when adding a ActiveAt (need add to Loki) function for alert start time, using parseDurationTime allows returning the time in the needed format, such as:

{{ (activeAt.Add (parseDurationTime "30m")).UnixMilli }}

Adding parseDurationTime enhances Prometheus templating by providing rich duration/time operations in templates, improving alerting capabilities with use cases in Loki.

Related Issues and Pull Requests

grafana/loki#4980
prometheus/alertmanager#3816

Signed-off-by: Dmitry Ponomaryov <me@halje.ru>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant
0