Skip to content

Alert rule create/update drops non-PromQL query model fields (Graphite, classic_conditions) #731

@hanks

Description

@hanks

Bug

When creating or updating alert rules via the alerting_manage_rules tool, the AlertQueryModel struct silently drops fields that are not explicitly defined in the Go struct. This causes alert rules with non-PromQL datasources (e.g., Graphite) and classic_conditions expressions to be created with incomplete query models, resulting in evaluation errors.

Steps to Reproduce

  1. Use alerting_manage_rules with operation: create to create an alert rule with a Graphite datasource query and a classic_conditions expression
  2. Pass the full model including Graphite-specific fields (target, datasource, textEditor) and classic_conditions fields (query.params, operator, reducer)
  3. The created rule fails evaluation with:
    [sse.parseError] failed to parse expression [A]: condition 1 is missing the query RefID argument
    

Root Cause

In tools/alerting_manage_rules_types.go, AlertQueryModel only defines typed fields for PromQL-style queries:

type AlertQueryModel struct {
    Expr       string           `json:"expr,omitempty"`
    Type       string           `json:"type,omitempty"`
    Expression string           `json:"expression,omitempty"`
    Reducer    string           `json:"reducer,omitempty"`
    Conditions []AlertCondition `json:"conditions,omitempty"`
}

And AlertCondition only captures evaluator:

type AlertCondition struct {
    Evaluator ConditionEvaluator `json:"evaluator"`
}

When convertAlertQueries() marshals q.Model to JSON and then to map[string]any, fields not in the struct are silently dropped:

  • Graphite: target, datasource, textEditor — query has no expression at all
  • Classic conditions: query.params (carries the RefID reference, e.g. ["C"]), operator, reducer — condition is incomplete and fails parsing

Affected Datasources

Any datasource that uses model fields beyond expr:

  • Graphite (target, datasource, textEditor)
  • Classic conditions (query.params, operator, reducer)
  • Likely also: CloudWatch, Elasticsearch, InfluxDB, and others with custom model fields

Environment

  • mcp-grafana v0.11.6
  • Grafana (self-hosted)

Fix

#730

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions