Skip to content
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

add date time sprig template functions in logql label/line formatter #4603

Merged
merged 3 commits into from
Nov 2, 2021

Conversation

garrettlish
Copy link
Contributor

@garrettlish garrettlish commented Nov 1, 2021

What this PR does / why we need it:
Introduce date time sprig template functions in logql label/line formatter, it allows us to get current time, format date time and parse date time with specified layout.

Which issue(s) this PR fixes:
Fixes #4511, we will be able to filter test jobs which create time is 1 day before as the following:

{job="test"} | label_format nowEpoch=`{{(unixEpoch now)}}`,createDateEpoch=`{{unixEpoch (toDate "2006-01-02" .createDate)}}` | label_format dateTimeDiff="{{sub .nowEpoch .createDateEpoch}}" | dateTimeDiff > 86400

Special notes for your reviewer:
N/A

Checklist

  • Documentation added
  • Tests updated

Copy link
Contributor

@sandeepsukhani sandeepsukhani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work @garrettlish! LGTM

Copy link
Collaborator

@kavirajk kavirajk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks nice 👍 Thanks @garrettlish. Left one minor suggestions.

And can you also please update the ``CHANGELOG.md`?


## date

`date` returns a textual representation of the time value formatted according to layout.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: about the layout. Can we explain bit about it? What are the other options? (is it same as golang's datetime layout?, if yes, we can mention that and refer the doc to the layout?)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good question. I'm not actually sure, although I expected it was the same as golang's.

Copy link
Contributor Author

@garrettlish garrettlish Nov 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are correct, it is golang datetime layout, added doc references to the layout - a4aa5e7

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool. thanks for adding the the clarification! 👍

Copy link
Member

@owen-d owen-d left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

With date time sprig template functions, we will be able to filter test jobs which create time is 1 day before as the following:
```
{job="test"} | label_format nowEpoch=`{{(unixEpoch now)}}`,createDateEpoch=`{{unixEpoch (toDate "2006-01-02" .createDate)}}` | label_format dateTimeDiff="{{sub .nowEpoch .createDateEpoch}}" | dateTimeDiff > 86400
```
* add golang datetime layout doc reference
* update CHANGELOG.md accordingly to include this PR
Copy link
Contributor

@cyriltovena cyriltovena left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Nice examples

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Request enabling more sprig template functions in logql label/line formatter?
5 participants