-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
feat: add time helpers #3720
feat: add time helpers #3720
Conversation
Signed-off-by: Techno Freak <freak12techno@gmail.com>
e6cf027
to
fe8dec6
Compare
{ | ||
title: "Template using since", | ||
in: "{{ . | since | humanizeDuration }}", | ||
data: time.Now().Add(-1 * time.Hour), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tbh I am not sure how to test this one properly without mocking time.Since, which as far as I know cannot be done without some kinds of workaround, this one looks ugly and flaky (as it relies on local time and will fail if the time between creating this variable and rendering is more than 1 second), but it kinda works, let me know if there's a better way to do it
Signed-off-by: Techno Freak <freak12techno@gmail.com>
13f7681
to
ac7d8b7
Compare
@gotjosh can you review or ping somebody to do that? |
@freak12techno how do you feel about moving the helper into https://github.com/prometheus/common so that we don't have to copy/pate here? |
@gotjosh I am ok with this, I can do the following:
does this sound decent? |
Sounds perfect to me! |
I'll close this one as it'll be required to rewrite it anyways. |
Fixes #3717.
The
humanizeDirection
helper is 100% copied from Prometheus, thesince
is added by me.The tests are also copied from Prometheus and adapted, plus I added my own
since
test.Tested it locally: creating an alert like this one:
with a template like this one
produces the following output: