-
Notifications
You must be signed in to change notification settings - Fork 35
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
Use templateSrv to interpolate timeFrom and timeTo variables. #31
Conversation
I realized that `timeFrom` and `timeTo` variables can be used to access the overridden time range values at the panel level (Query Options). Those variables were interpolated using a regex instead of using `templateSrv`, thus preventing custom date formats to be used. With this change, it's now possible to specify a custom date format for `timeFrom` and `timeTo` variables if running on Grafana >= v7.2. For example: ``` query { data:submissions( where: { submitTime: {_gte: "${timeFrom:date}", _lte: "${timeTo:date}"}, } ) { Time:submitTime } } ```
I meant to make this PR a long time ago but I never got around to it. It looks good to me, we might consider removing timeFrom and timeTo altogether unless we want to keep backwards compatibility with older queries since we just use But this is definitely much better than what we had before. |
Date formats are fully supported using the builtin |
@retrodaredevil and @retzkek I might getting this wrong since I'm not a Grafana expert, but Isn't |
No, they were just internal variables, from before the global builtins were added in Grafana 7.
It looks like that's a bug grafana/grafana#20147 |
@retzkek thanks for the clarifying that. It seems that bug is there since Grafana v6.4.3. Other datasource plugins provide a different ways to access the time range so I guess that's the reason the bug is not fixed yet (e.g. MySQL and Postgres datasource provide For now, I guess |
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.
I've tested this, sorry for the delay. It seems to work OK, although unfortunately the date
format options that are provided for __from
and __to
don't seem to work, but the behavior doesn't change from what we had before, so 🤷. Presumably this is some limitation of templateSrv
, but documentation here is scarce.
LGMT. Thanks for contributing! |
I realized that
timeFrom
andtimeTo
variables can be used to access the overridden time range values at the panel level (Query Options). Those variables were interpolated using a regex instead of usingtemplateSrv
, thus preventing custom date formats to be used. With this change, it's now possible to specify a custom date format fortimeFrom
andtimeTo
variables if running on Grafana >= v7.2. For example: