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

Query prettifier doesn't work with Grafana variables #166

Closed
hagen1778 opened this issue Jun 13, 2024 · 9 comments
Closed

Query prettifier doesn't work with Grafana variables #166

hagen1778 opened this issue Jun 13, 2024 · 9 comments
Assignees
Labels
bug Something isn't working

Comments

@hagen1778
Copy link
Contributor

Try putting the following query in panel:

topk_max(10, 
    sum(rate(vmalert_iteration_duration_seconds_sum{job=~"$job", instance=~"$instance", group=~"$group"}[$__rate_interval])) by(job, group))

and press Prettify button.

Expected result: query gets prettified
Actual result: "msg": "cannot recognize \"$__rate_interval]))by(job, group))\"; unparsed data: \"[$__rate_interval]))by(job, group))\""

@hagen1778 hagen1778 added the bug Something isn't working label Jun 13, 2024
@hagen1778
Copy link
Contributor Author

@dmitryk-dk I think this involves changes to metricsql Go lib.

@dmitryk-dk
Copy link
Contributor

@dmitryk-dk I think this involves changes to metricsql Go lib.

Ok, i will check it

@dmitryk-dk
Copy link
Contributor

@hagen1778 the problem there with Grafana variables. I think we should remove them before executing in a prettify function

@dmitryk-dk dmitryk-dk self-assigned this Jun 14, 2024
@hagen1778
Copy link
Contributor Author

@hagen1778 the problem there with Grafana variables. I think we should remove them before executing in a prettify function

Would that help to prettify query afterwards? Would you be able to restore the prettified query back by putting variables in it?

@dmitryk-dk
Copy link
Contributor

@hagen1778 the problem there with Grafana variables. I think we should remove them before executing in a prettify function

Would that help to prettify query afterwards? Would you be able to restore the prettified query back by putting variables in it?

@hagen1778 i think we should discuss where it is better to handle it. I am not sure that we should handle Grafana variables in the metricsql library

@dmitryk-dk
Copy link
Contributor

@hagen1778 I think we can use a static lookbehind window to replace the Grafana variable. Make the query prettier, and then replace the static look behind window with the Grafana variable back. I think this behavior should work well.

@hagen1778
Copy link
Contributor Author

Agree. Do you think it should be handled on front end side?

@dmitryk-dk
Copy link
Contributor

Agree. Do you think it should be handled on front end side?

Checked the code. So the backend just works as a proxy to data source, and there are no handlers to handle this request, and I think it is not necessary to add this handler to the backend. I think the better place to do it is on the front end. The frontend part can manipulate query string on request and response and show the correct results.

@hagen1778
Copy link
Contributor Author

The fix was included into v0.8.3 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants