Skip to content

fix: include full query data in alert rule get response#733

Open
hanks wants to merge 1 commit intografana:mainfrom
hanks:fix/alert-get-return-full-query-data
Open

fix: include full query data in alert rule get response#733
hanks wants to merge 1 commit intografana:mainfrom
hanks:fix/alert-get-return-full-query-data

Conversation

@hanks
Copy link
Copy Markdown

@hanks hanks commented Apr 10, 2026

Summary

The alerting_manage_rules get operation returns only a querySummary (ref_id, datasource_uid, expression) for each query, discarding the full query model from the provisioning API. This makes get -> update round-trips silently lose datasource-specific fields for non-PromQL datasources (Graphite, OpenSearch, Elasticsearch, etc.).

Fixes #732

Changes

  • Add Data []*models.AlertQuery field to alertRuleDetail struct
  • Populate Data from provisioned.Data in mergeRuleDetail, preserving full query models alongside the existing Queries summary
  • Add unit test verifying Graphite model fields (target, textEditor, datasource) survive in the Data field
  • Add assertions to existing mergeRuleDetail test verifying Data is populated for Prometheus queries

Why both Queries and Data?

  • Queries (summary) is compact and useful for LLM context — shows ref_id, datasource, and expression at a glance
  • Data (full) contains the complete models.AlertQuery with all model fields, enabling safe round-trip updates

Removing Queries would be a breaking change for existing consumers. Adding Data alongside is backward-compatible.

Test Plan

  • go vet ./tools/ passes
  • go test ./tools/ — all unit tests pass
  • JSON schema linter passes
  • New test: TestMergeRuleDetail/Data_preserves_full_Graphite_query_model_for_round-tripping
  • Extended test: existing merges_provisioned_config_with_runtime_state now verifies Data field

Note

Low Risk
Low risk, additive API response change that preserves existing queries behavior while returning additional data payload for round-tripping; main risk is unexpected larger responses for consumers that deserialize strictly.

Overview
The alerting_manage_rules get response now includes full provisioning query payloads (data: []*models.AlertQuery) in addition to the existing compact queries summaries, preventing loss of datasource-specific query fields during getupdate round-trips.

mergeRuleDetail now copies provisioned.Data into the new alertRuleDetail.Data field, and unit tests were extended to assert round-tripping for Prometheus queries and a Graphite query model (e.g., target, textEditor, datasource).

Reviewed by Cursor Bugbot for commit 5bc6d44. Bugbot is set up for automated code reviews on this repo. Configure here.

The alerting_manage_rules get operation only returned a querySummary
(ref_id, datasource_uid, expression) which discards datasource-specific
fields like Graphite 'target', 'datasource', 'textEditor', and
OpenSearch 'bucketAggs', 'metrics', 'queryType'.

This made it impossible to round-trip get -> update without silently
losing query data for non-PromQL datasources.

Add a 'data' field to alertRuleDetail that contains the full
models.AlertQuery slice from the provisioning API response, preserving
all datasource-specific model fields alongside the existing summary.

Fixes grafana#732
@hanks hanks requested a review from a team as a code owner April 10, 2026 10:29
@alexander-akhmetov alexander-akhmetov self-requested a review April 10, 2026 18:21
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.

alerting_manage_rules get operation discards full query model, breaking round-trip updates for non-PromQL datasources

1 participant