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 = lfss

View on GitHub (pinned to 5079fb58f1)

Solutions

  1. Strip the expression down to a bare selector: metric name plus optional `{label="value"}` block
  2. Move computation (rate, sum, comparisons) elsewhere — relabeling matches raw series only
  3. 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

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


AI-assisted analysis of VictoriaMetrics/VictoriaMetrics@5079fb58f1 (2026-09-03). Data as JSON: /api/errors/046f5bebdfaecae1. Report an issue: GitHub.