-
Notifications
You must be signed in to change notification settings - Fork 27
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
feat: dynamic matcher+template checks #181
base: main
Are you sure you want to change the base?
Conversation
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.
@alex5517 thank you for this! I've had something similar in mind for a long time, but apparently never created an issue, nor documented it anywhere.
I have a few comments below that I'd like to see implemented, or I'm happy to discuss with you.
These stem from my own experience in stubbing my toe by leaving existing users of the tool in a hard spot trying to integrate the new version of the linter into their workflow. This is used in enough places for CI that making breaking changes, particularly without versioning, can really disrupt downstream users.
docs/index.md
Outdated
-c, --config string path to a configuration file | ||
--fix automatically fix problems if possible | ||
-h, --help help for lint | ||
-m, --matcher stringArray matcher required to be present in all selectors, e.g. 'instance=~"$instance"' or 'cluster="$cluster"', can be specified multiple times (default ["instance=~""$instance""","job=~""$job"""]) |
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'd like to see this configured in the .lint
config file rather than as a CLI flag. In the case of linting several dashboards in a repo, or when embedding into something like mixtool that makes this a bit more flexible, and can be different per dashboard-project.
Something like;
---
settings:
template-variable-matchers-rule:
matchers:
- instance=~""
- instance=""
- job=~""
…of configfile settings
I made a quick commit with what i had since i ran out of time... |
Looking good so far! I was suggesting that the new rule be enabled, only if config exists for it, but it looks like you're beginning to implement an experimental flag which is great. I wrote up an issue for this yesterday in #185. You certainly don't need to implement the experimental flag, nor the features described there, but it may be a good reference. You said this was a quick commit. What do you think you have left to do? I didn't do a deep review because you indicated this was a work in progress. Also, a nit, but a lot of files had their modes changed from |
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.
Looking good! I know the PR isn't quite ready to merge, but I went over it again as-is and spotted a few things.
Thank you for being flexible and implementing the feedback!
Sorry for the inactivity... I had a look at the comments you left, and implemented them. |
Hi @rgeyer, I have been trying to understand how the variable expansion should work, but i have not been able to fully get it, and currently i am not sure if all of the expansions are working as expected. To get some debug info i tried printing the expr at different stages. https://github.com/grafana/dashboard-linter/blob/main/lint/variables_test.go The input expr is the string that is provided to It might be that i am just missing something?
|
Not a problem! Welcome back from holiday. :) I saw your commits and questions yesterday but didn't have a chance to review. Hopefully I will get through them today. Thank you again for the contribution! |
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.
Looks good! See my responses to your question about the tests and variable expansion above.
This is, admittedly, confusing. The goal of the variable expansion is to replace variables in a promql which the promql parser can not understand. In short, that means that any place a variable appears in a query, that is not in double quotes, some value has to be substituted in order for the promql parser to grok it. This is almost entirely a concession for the global grafana variables which get used to define time ranges and other things which would not be considered a plain string value inside of double quotes. The range variables are intentionally obscure large time intervals, because some tests need to check that the variable was substituted.
|
Hi @rgeyer, Thanks for the explanation, i also figured that it was to get the promql parser to behave... I think i will take another crack at it... I wanna get nil issues fixed such as this one where the promql parser is not able to parse the expr properly.
These are some thoughts i have about changes that could be made to the variable expansion.
Then reversing it would be replacing But again these are just some unfinished thoughts that i wanted to share... |
Hi @rgeyer, I have been working a bit on the issue with reversing the variable expansion, it is not 100% done... I have made some assumptions...
And i am also aware of a few shortcomings that are present in the code atm but that should be fixable :)
I hope it is okay to request review/feedback despite the fact that it is still not finished... |
This is fine, we're not doing anything with the special formats. If we ultimately do, we can make the necessary changes then.
Not specifically 10s no, but, it does need to be a time value so that the promql parser can process it.
Not a problem at all, thank you for the continued iteration and clear communication. |
Still missing a few places where tests are now failing due to promql parser errors being handled. |
…k with single test run and full package run
All tests are now passing... But i do see an issue with the merging of oldData and the newData when using autofix https://github.com/grafana/dashboard-linter/blob/main/main.go#L98-L115 Instead of merging the newData it appends it so that the result contains duplicate expressions, it must be that the conflate package is not able to merge them, based on my debugging the data provided to it looks correct. |
I believe that this is resolved by zeitlinger/conflate#1. Do you have test data to try this with? I suppose I could knock together a pretty basic dashboard to test with. I want to try to get this merged before main get's too far ahead. |
Signed-off-by: Alexander Soelberg Heidarsson <[email protected]>
Signed-off-by: Alexander Soelberg Heidarsson <[email protected]>
Signed-off-by: Alexander Soelberg Heidarsson <[email protected]>
I tried testing using newest conflate:
|
Also i made a few commits, i only saw the ref to #208 after... But commit: 09e53e8 fixes an issue i found where if a template variable has matchers ,then it would not expand correctly example:
As for c2e6171 it is a bit obscure that the user might have specified that Last but not least i will try to find time to have a look at #208 during this week. |
Hey @alex5517. First off, thank you for taking another look, and proving some details on the conflate issue. I wasn't able to reproduce it so it seemed "fine" to me. I didn't mean to create confusion by creating another PR. I had read your previous last message as "things look good, if conflate is resolved, this is ready to merge", so I went about resolving the conflicts with main. Seems there's more to work through, so I won't rush it, and will continue to collaborate with you. |
Hi @rgeyer, Sounds good that you weren't able reproduce it perhaps it is something specific to my environment... And it is fine with the other PR, the commits made after was not something i was not aware of back then :) Depending on your policies, then perhaps it would be better to have #208 merged, since the things i have seen failing are concerned with rules that are experimental anyways, and the PR might just get harder to get merged over time... A separate issue/pr could then be made for the other "bugs" If you are fine with merging #208 i hope you will consider including the 2 new commits i made here: 09e53e8 |
Removes the hardcoded checks on instance and job
Adds option to provide matchers that are required to be present in all expr's
if one or more of these matchers use variables, then also check if template exists.
Defaults to checking instance and job so that it almost works as usual.
Also makes the matchers check fixable, implemented same way as in: #180
Just created it in 2 PRs in case this PR could not be merged.