VictoriaMetrics/VictoriaMetrics · error
expecting series selector; got %q
Error message
expecting series selector; got %q
What it means
IfExpression.Parse requires the input string to parse via metricsql AND to be a plain MetricExpr (a series selector). If the expression parses but is any other MetricsQL node (function call, rollup, binary operation, etc.), this error reports the parsed expression string.
Source
Thrown at lib/promrelabel/if_expression.go:206
// and empty otherwise - see getCommonMetricName.
metricName string
}
func (ie *ifExpression) String() string {
if ie == nil {
return ""
}
return ie.s
}
func (ie *ifExpression) Parse(s string) error {
expr, err := metricsql.Parse(s)
if err != nil {
return err
}
me, ok := expr.(*metricsql.MetricExpr)
if !ok {
return fmt.Errorf("expecting series selector; got %q", expr.AppendString(nil))
}
lfss, err := metricExprToLabelFilterss(me)
if err != nil {
return fmt.Errorf("cannot parse series selector: %w", err)
}
ie.s = s
ie.lfss = lfss
ie.metricName = getCommonMetricName(lfss)
return nil
}
func (ie *ifExpression) parseFromMetricExpr(me *metricsql.MetricExpr) error {
lfss, err := metricExprToLabelFilterss(me)
if err != nil {
return fmt.Errorf("cannot parse series selector: %w", err)
}
ie.s = string(me.AppendString(nil))
ie.lfss = lfssView on GitHub (pinned to 5079fb58f1)
Solutions
- Strip the expression down to a bare selector: metric name plus optional `{label="value"}` block
- Move computation (rate, sum, comparisons) elsewhere — relabeling matches raw series only
- If multiple conditions are needed, use multiple match items or `if` with mapping form
Example fix
// before if: 'up == 1' // after if: 'up'
Defensive patterns
Strategy: validation
Validate before calling
import "github.com/VictoriaMetrics/metricsql"
func ensureSeriesSelector(s string) error {
expr, err := metricsql.Parse(s)
if err != nil { return err }
if _, ok := expr.(*metricsql.MetricExpr); !ok {
return fmt.Errorf("not a series selector: %q", s)
}
return nil
} Type guard
func isMetricExpr(expr metricsql.Expr) bool {
_, ok := expr.(*metricsql.MetricExpr)
return ok
} Try / catch
if err := ie.Parse(userInput); err != nil {
if strings.Contains(err.Error(), "expecting series selector") {
return fmt.Errorf("relabel selectors cannot contain functions/operators: %w", err)
}
return err
} Prevention
- Never put rate/sum/comparisons in `match` or `if` — bare selectors only
- Pre-validate strings with metricsql.Parse and a MetricExpr type assertion
- Document for config authors that relabeling matches raw series, not computed expressions
When it happens
Trigger: `match` or `if` values like `match: 'up == 1'`, `match: 'rate(x[5m])'`, `match: 'foo or bar'` — valid MetricsQL but not a bare series selector.
Common situations: Copying full alerting/recording-rule expressions into relabel `match`/`if`; users assuming selectors can contain operators; GUI-generated configs that emit expressions.
Related errors
- unexpected `match` option: %w
- unexpected `match` item: %w
- cannot parse series selector: %w
- cannot unmarshal `relabel_configs` from %q: %w
- error when parsing `relabel_config` #%d: %w
AI-assisted analysis of VictoriaMetrics/VictoriaMetrics@5079fb58f1 (2026-09-03).
Data as JSON: /api/errors/046f5bebdfaecae1.
Report an issue: GitHub.