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

mimirtool: use strings replacer in dashboards queries analyzer #8062

Merged
merged 2 commits into from
May 6, 2024

Conversation

cristiangreco
Copy link
Contributor

What this PR does

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.

Which issue(s) this PR fixes or relates to

n.a.

Checklist

  • Tests updated.
  • Documentation added.
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX].
  • about-versioning.md updated with experimental features.

@cristiangreco cristiangreco force-pushed the cristian/analyze-grafana-metrics-replacer branch from d66c72d to 359a62f Compare May 6, 2024 13:22
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.
@cristiangreco cristiangreco force-pushed the cristian/analyze-grafana-metrics-replacer branch from 359a62f to 6d5ed2b Compare May 6, 2024 13:23
@cristiangreco cristiangreco marked this pull request as ready for review May 6, 2024 13:35
@cristiangreco cristiangreco requested a review from a team as a code owner May 6, 2024 13:35
Comment on lines 28 to 29
variableRangeQueryRangeRegex = regexp.MustCompile(`\[\$?\w+?]`)
variableSubqueryRangeRegex = regexp.MustCompile(`\[\$?\w+:\$?\w+?]`)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure about removing these. I think they're there to cover the case of non-standard variable created by user (like $time_interval or whatever they'd want to create).
Unfortunately there's no test for that, but I'd also create one.

Copy link
Contributor

@colega colega 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!

@colega colega enabled auto-merge (squash) May 6, 2024 14:18
@colega colega merged commit 3c5967f into main May 6, 2024
29 checks passed
@colega colega deleted the cristian/analyze-grafana-metrics-replacer branch May 6, 2024 14:27
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.

2 participants