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

Support auto interval variables #71

Merged
merged 1 commit into from
Jun 16, 2022

Conversation

wuzuf
Copy link
Contributor

@wuzuf wuzuf commented Jun 15, 2022

Hello,

One of my colleague reported another interesting case... When using "auto" option for interval variables, the variable definition is not a valid value but $__auto_interval_xxxx.
So I added support for this by:

  • recursively expanding variables (which might not be needed in other cases, but I can't tell for sure)
  • replacing all __auto_interval variable with a 10s magic number

Let me know if you have questions/remarks,
Gabriel

@CLAassistant
Copy link

CLAassistant commented Jun 15, 2022

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link
Collaborator

@rgeyer rgeyer left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the contribution!

// If it is a template variable and we have a value, we use it
for _, v := range variables {
if v.Name != name {
continue
}
// if it has a current value, use it
if v.Current.Value != "" {
return v.Current.Value, nil
return expandVariables(v.Current.Value, variables)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I had to clone your repo and run through some debugging to wrap my head around this. I was worried about infinite recursion, but it'll just walk the tree until it either finds the templated value, or exhausts it's options!

This should also actually fix another issue I discovered where you have a multi-select value with the var $__all that didn't get expanded.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks a lot for the comment. Actually, there could be a case, if the template variable self references itself.
I don't know how grafana would handle it, but the linter was failing with a stack overflow. I submitted an updated PR for that.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ahh yes! That is a potential case. The solution is elegant. :)

Could I ask you to add a test for this? Where a template variable references itself, and the expected outcome is failure/empty.

Once we have that, I'll be happy to merge. Thank you for the contribution!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a test, already :). I used it to trigger the stack overflow so I am sure it validates the behavior...
https://github.com/grafana/dashboard-linter/pull/71/files#diff-34ec875ff928ca836dfa602bba4346279462424c106b50f59016b04462883051R165

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sheesh, you're right, I missed it, or github didn't render it.

That's what I get for reviewing before coffee. Thank you!

@wuzuf wuzuf force-pushed the feature/auto-sampling-support branch from eceeb3f to 1f975c7 Compare June 16, 2022 08:11
@rgeyer rgeyer merged commit 7b170eb into grafana:main Jun 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants