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

TemplateSrv: Formatting options for ${__from} and ${__to}, unix seconds epoch, ISO 8601/RFC 3339 #26466

Merged
merged 9 commits into from
Jul 27, 2020

Conversation

torkelo
Copy link
Member

@torkelo torkelo commented Jul 20, 2020

Closes #15903

Introduces an extended templating syntax format that can have 1 or more arguments like this ${variable:<formatName>:<optionalArg1>:<optionalArg2>}

Adds date format and args

  • ${__from:date} no args, defaults to iso/rfc (example 2020-07-13T20:19:09.254Z)
  • ${__from:date:iso} same as above
  • ${__from:date:ms} unix millisecond epoch same as no date format ${__from}
  • ${__from:date:seconds} unix seconds epoch
  • ${__from:date:YYYY-MM} custom date format

TODO

  • Get feedback on naming and syntax
  • Update docs

In the upcoming PR:

  • Possibly refactor formats to use a new format registry using Registry class (could be useful for syntax IntelliSense in the future)

@ryantxu
Copy link
Member

ryantxu commented Jul 20, 2020

a new templating syntax! 🤯

When I actually look at the code, it looks great -- totally reasonable. I just get scared by adding more powerful hidden complex features to templateSrv.

+1 to refactor the formats into a Registry that we can more clearly promote with IntelliSense etc.

@jtorkkel
Copy link

There is similar need for "to" like ${__to:date:ms}, see #18763

@torkelo
Copy link
Member Author

torkelo commented Jul 24, 2020

of course, this also handled ${__to}

@torkelo torkelo changed the title TemplateSrv: Formatting options for ${__from}, unix seconds epoch, ISO 8601/RFC 3339 TemplateSrv: Formatting options for ${__from} and ${__to}, unix seconds epoch, ISO 8601/RFC 3339 Jul 24, 2020
@torkelo torkelo marked this pull request as ready for review July 26, 2020 15:57
@torkelo torkelo requested review from a team, mckn and dprokop and removed request for a team July 26, 2020 15:57
@torkelo
Copy link
Member Author

torkelo commented Jul 26, 2020

Ok, ready for merge. Updated docs.

The refactor to registry will come in new PR as we need to cherry-pick this to 7.1.2 so want to keep this PR as small as possible, so moving the refactoring to a new PR.

Copy link
Contributor

@oddlittlebird oddlittlebird left a comment

Choose a reason for hiding this comment

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

Good to go aside from some grammar suggestions in the docs.

docs/sources/variables/global-variables.md Outdated Show resolved Hide resolved
docs/sources/variables/global-variables.md Show resolved Hide resolved
docs/sources/variables/global-variables.md Outdated Show resolved Hide resolved
docs/sources/variables/global-variables.md Outdated Show resolved Hide resolved
docs/sources/variables/global-variables.md Outdated Show resolved Hide resolved
torkelo and others added 4 commits July 27, 2020 20:18
Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>
Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>
Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>
Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>
@torkelo torkelo merged commit 6c49fdb into master Jul 27, 2020
@torkelo torkelo deleted the template-srv-date-formats branch July 27, 2020 18:48
hugohaggmark pushed a commit that referenced this pull request Aug 5, 2020
…ds epoch, ISO 8601/RFC 3339 (#26466)

* TemplateSrv: WIP date formats

* Templating: formats with arguments

* WIP docs updates

* Docs: Updated docs

* fixed spelling

* Update docs/sources/variables/global-variables.md

Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>

* Update docs/sources/variables/global-variables.md

Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>

* Update docs/sources/variables/global-variables.md

Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>

* Update docs/sources/variables/global-variables.md

Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>

Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>
(cherry picked from commit 6c49fdb)
hugohaggmark pushed a commit that referenced this pull request Aug 5, 2020
…ds epoch, ISO 8601/RFC 3339 (#26466)

* TemplateSrv: WIP date formats

* Templating: formats with arguments

* WIP docs updates

* Docs: Updated docs

* fixed spelling

* Update docs/sources/variables/global-variables.md

Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>

* Update docs/sources/variables/global-variables.md

Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>

* Update docs/sources/variables/global-variables.md

Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>

* Update docs/sources/variables/global-variables.md

Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>

Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>
(cherry picked from commit 6c49fdb)
@ehenara
Copy link

ehenara commented Sep 7, 2020

I've upgraded to 7.1.5; but still not able to use the Formatting option

ex: Panel title "${__from:date}" result is seconds not date format

image

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

Successfully merging this pull request may close these issues.

Support $__from and $__to in seconds
7 participants