-
Notifications
You must be signed in to change notification settings - Fork 524
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 $rate_interval when parsing Query during dashboards analysis #6657
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
We have an internal tool that does a similar job, and instead of a list of string replaces it just does: var variableRangeQueryRangeRegex = regexp.MustCompile(`\[\$?\w+?]`)
var variableSubqueryRangeRegex = regexp.MustCompile(`\[\$?\w+:\$?\w+?]`)
func removeVariablesFromRanges(query string) string {
query = variableRangeQueryRangeRegex.ReplaceAllLiteralString(query, `[5m]`)
query = variableSubqueryRangeRegex.ReplaceAllLiteralString(query, `[5m:1m]`)
return query
} WDYT about applying it here? |
wilfriedroset
force-pushed
the
mimirtool-rate-interval
branch
from
November 14, 2023 17:04
28836b0
to
8185f38
Compare
Nice! Would you mind adding a CHANGELOG entry? 🙏 Then we're good to go. |
Grafana support several Global variables but also allow users to define an `interval` templated variable. When using mimirtool on such case we might have the following error: ``` "query=histogram_quantile(0.70, sum by (le) (rate(rpc_server_duration_milliseconds_bucket{rpc_method=~\"$gRPC_method\", job=\"$job\"}[$rate_interval]))): 1:124: parse error: missing unit character in duration", ``` This commit improve the support variables in ranges. See: https://grafana.com/docs/grafana/latest/dashboards/variables/add-template-variables/#global-variables Signed-off-by: Wilfried Roset <wilfriedroset@users.noreply.github.com>
wilfriedroset
force-pushed
the
mimirtool-rate-interval
branch
from
November 15, 2023 08:20
8185f38
to
6f5c79e
Compare
colega
approved these changes
Nov 15, 2023
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.
Thank you!
4 tasks
cristiangreco
added a commit
that referenced
this pull request
May 6, 2024
When parsing queries from grafana dashboards, use a replacer with a list of variables rather than a regex matcher. The regex matcher works ok with ranges and subqueries, but is not working when the variables are used in other parts of the query (e.g. with `offset`). This PR switches back to using a list of variables to be replaced, partially reverting the changes from #6657, but uses a `strings.Replacer` for better readability.
colega
pushed a commit
that referenced
this pull request
May 6, 2024
* mimirtool: use strings replacer in dashboards queries analyzer When parsing queries from grafana dashboards, use a replacer with a list of variables rather than a regex matcher. The regex matcher works ok with ranges and subqueries, but is not working when the variables are used in other parts of the query (e.g. with `offset`). This PR switches back to using a list of variables to be replaced, partially reverting the changes from #6657, but uses a `strings.Replacer` for better readability. * restore regexps
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Grafana support several Global variables but also allow users to define an
interval
templated variable. When using mimirtool on such case we might have the following error:This commit add support for more user define variables matching the global ones.
See: https://grafana.com/docs/grafana/latest/dashboards/variables/add-template-variables/#global-variables
We have the following global variables that are out of the scope of dashboards analysis:
However those are interesting:
What this PR does
Which issue(s) this PR fixes or relates to
Checklist
CHANGELOG.md
updated - the order of entries should be[CHANGE]
,[FEATURE]
,[ENHANCEMENT]
,[BUGFIX]