Menu
Grafana Cloud

Optimize generated queries

Run through this workflow when you want to audit and polish any query, whether Assistant-generated or human-authored, before putting it into production.

What you’ll achieve

  • Request structured reviews that highlight syntax, performance, and cardinality concerns.
  • Apply recommended changes without losing sight of the original intent.
  • Validate updates in Grafana so you can commit them to dashboards, alerts, or runbooks.

Before you begin

  • Generated query: Copy the query from chat or the panel editor.
  • Performance goal: Know whether you need faster responses, lower cardinality, or clearer formatting.

Request a structured review

Ask the Assistant to audit the query with performance goals in mind so you know which areas need attention.

  1. Share the query and ask the Assistant to analyze potential issues. Mention the data source, expected result shape, and any performance symptoms so the review stays grounded.
Review this PromQL query for performance and suggest improvements.
  1. Confirm the Assistant evaluates label usage, aggregation strategy, and time windows.

Refine the query based on the review, requesting diffs or commentary so the updates stay understandable.

  • Ask for safer alternatives when the query scans too much data, for example, Rewrite this LogQL query to avoid high cardinality labels.
  • Request comments or explanations so future maintainers understand the logic.
  • If you need to keep the original query, ask for a diff highlighting the changes.
  • Apply changes incrementally and correct the Assistant politely if a recommendation conflicts with your requirements.

Validate in Grafana

Execute the revised query in Grafana to confirm correctness and performance before committing it to production use.

  • Run the updated query in Explore or the dashboard panel to confirm it returns the expected data.
  • Compare execution time or sample size before and after optimization.

Share the optimization outcome

You now have an optimized, validated query along with a summary of what changed. Capture the diff in your version control or dashboard notes so others know why you made the update.

Troubleshooting

  • Assistant suggests unavailable labels: verify the data source metadata and adjust, for example, Use label job instead of app.
  • No improvements offered: provide additional context about the performance issue or desired outcome.
  • Query still slow: combine Assistant guidance with manual sampling or metric relabeling.
  • Switching to an unrelated query: open a new conversation so earlier diagnostics do not influence the next review.

Next steps