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

Allow for multiple auto interval template variables #9216

Merged

Conversation

alin-amana
Copy link
Contributor

Allow for multiple auto interval template variables without them overwriting each other's value.

Apologies for the possibly crappy code quality and missing tests, not a frontend coder. The fix is the best I could come up with, the testing framework plus Grafana internals I couldn't really wrap my head around (it would have been useful to add a test ensuring multiple auto interval variables actually work. (I did test it manually and they work fine, but still.)

@alin-amana
Copy link
Contributor Author

Added a test (spec?). It doesn't use the same setup as the other tests because it requires 2 variables to be created, but (with my limited understanding of frontend development) I would say it's sane.

@alin-amana
Copy link
Contributor Author

Friendly ping.

@torkelo
Copy link
Member

torkelo commented Sep 14, 2017

Not sure about this as this looks like a breaking change.

@alin-amana
Copy link
Contributor Author

Not breaking. I am loading dashboards saved before I made the change into a Grafana instance built with the patch and while /api/dashboards/file/collectd.json returns the value as "$__auto_interval", there is no console error in Chrome and the View JSON link on the dashboard shows the value as "$__auto_interval_period". It just works automagically.

If you are still concerned though, I could add code to look for an existing auto value (in addition to looking for a missing one, currently) and updating its value to the new format.

@alin-amana
Copy link
Contributor Author

Any opinion? I'm willing to put in the grunt work.

@alin-amana
Copy link
Contributor Author

Friendly ping.

@alin-amana
Copy link
Contributor Author

I've tested the internal variable name change (unintentionally, as part of running various feature branches) for weeks now and have seen zero of errors (user visible or Chrome console). This is AFAICT because the internal $__auto_interval variable is only used in internal and serialized representations of dashboards and these are basically rebuilt on dashboard load.

Any chance of having this merged?

Or else, any guidance on what sort of explicit handling of auto interval variables you would like to see implemented before you'd merge this? Thanks.

@torkelo
Copy link
Member

torkelo commented Oct 4, 2017

Will old links with var-interval=$__auto_interval work ?

@alin-amana
Copy link
Contributor Author

Thanks for bringing this up, I hadn't thought about it. I spent a bit of time checking and:

  • Hardcoded (e.g. saved) links with var-interval=$__auto_interval will not work. The literal value $__auto_interval will be displayed in the dropdown (if the variable is not hidden) and will be passed in Prometheus queries. Curiously enough, if the dashboard has a refresh interval set, everything will automagically go back to normal on the first refresh.
  • Generated links from dashboards having interval template variables saved with "value": "$__auto_interval" will work, as the value will be replaced at runtime with $__auto_interval_foo on dashboard load, and the generated links will have $__auto_interval_foo in them.

@alin-amana
Copy link
Contributor Author

That was supposed to be:

Correctly handle old links with var-interval=$__auto_interval.

but I used double quotes when running git commit.

Anyway, this change is now fully backwards compatible, as interval variables with an auto value will now create 2 "hidden" variables, $__auto_interval_<var_name> and the legacy $__auto_interval. In case there are multiple auto interval variables, the last one will "win" and set the value of $__auto_interval, which is exactly the current behavior.

@codecov-io
Copy link

codecov-io commented Oct 24, 2017

Codecov Report

Merging #9216 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #9216   +/-   ##
=======================================
  Coverage   43.29%   43.29%           
=======================================
  Files         243      243           
  Lines       21449    21449           
  Branches      545      545           
=======================================
  Hits         9286     9286           
  Misses      11649    11649           
  Partials      514      514
Flag Coverage Δ
#go 38.78% <ø> (ø) ⬆️
#javascript 79.62% <ø> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e91b00c...6c682cb. Read the comment docs.

@alin-amana
Copy link
Contributor Author

This change is now fully backward compatible. Both the legacy $__auto_interval and a new $__auto_interval_<variable_name> are set and all of the internal logic relies on the latter. The former is only necessary for old (saved) links and may be (eventually) dropped in a future release.

Any chance of having it merged? It is literally 3 lines of code.

@torkelo
Copy link
Member

torkelo commented Oct 24, 2017

thanks for taking the time with this PR, sorry it takes a while for us to respond (and merge).

@torkelo torkelo merged commit d99f4f9 into grafana:master Oct 24, 2017
@torkelo torkelo added this to the 4.7.0 milestone Oct 24, 2017
@alin-amana alin-amana deleted the allow_multiple_auto_interval_variables branch October 24, 2017 14:39
ryantxu added a commit to NatelEnergy/grafana that referenced this pull request Oct 24, 2017
* grafana/master: (21 commits)
  Fix typo in template help tab
  replace store.js with store.ts, test for store.ts (grafana#9646)
  docs: update first page with data source guides
  docs: document annotations for postgres/mysql
  docs: update for template variables
  changelog: spelling
  Allow for multiple auto interval template variables (grafana#9216)
  changelog: adds note about closing grafana#9645
  tech: remove rabbitmq event publisher
  changelog: note for grafana#9030
  dont quote variables for mysql and postgres datasource (grafana#9611)
  asscoiate comment with name
  Update development.md
  changelog: adds note about closing grafana#9640
  alerting: only editors can pause rules
  prom: adds pre built grafana dashboard
  changelog: adds note about closing grafana#9636
  fix: another fix for playlist view state, grafana#9639
  shore: migrating config/settings.js to typescript
  fix: fixed playlist controls and view state, fixes grafana#9639
  ...
@bergquist bergquist modified the milestones: 4.7.0, 5.0.0-beta1 Jan 26, 2018
@ying-jeanne ying-jeanne added the pr/external This PR is from external contributor label Apr 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/dashboard/templating pr/external This PR is from external contributor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants