{"record":{"id":"046f5bebdfaecae1","repo":"VictoriaMetrics/VictoriaMetrics","slug":"expecting-series-selector-got-q","errorCode":null,"errorMessage":"expecting series selector; got %q","messagePattern":"expecting series selector; got %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/promrelabel/if_expression.go","lineNumber":206,"sourceCode":"\t// and empty otherwise - see getCommonMetricName.\n\tmetricName string\n}\n\nfunc (ie *ifExpression) String() string {\n\tif ie == nil {\n\t\treturn \"\"\n\t}\n\treturn ie.s\n}\n\nfunc (ie *ifExpression) Parse(s string) error {\n\texpr, err := metricsql.Parse(s)\n\tif err != nil {\n\t\treturn err\n\t}\n\tme, ok := expr.(*metricsql.MetricExpr)\n\tif !ok {\n\t\treturn fmt.Errorf(\"expecting series selector; got %q\", expr.AppendString(nil))\n\t}\n\tlfss, err := metricExprToLabelFilterss(me)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"cannot parse series selector: %w\", err)\n\t}\n\tie.s = s\n\tie.lfss = lfss\n\tie.metricName = getCommonMetricName(lfss)\n\treturn nil\n}\n\nfunc (ie *ifExpression) parseFromMetricExpr(me *metricsql.MetricExpr) error {\n\tlfss, err := metricExprToLabelFilterss(me)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"cannot parse series selector: %w\", err)\n\t}\n\tie.s = string(me.AppendString(nil))\n\tie.lfss = lfss","sourceCodeStart":188,"sourceCodeEnd":224,"githubUrl":"https://github.com/VictoriaMetrics/VictoriaMetrics/blob/5079fb58f1e8e62113f90c945ad71586c797d770/lib/promrelabel/if_expression.go#L188-L224","documentation":"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.","triggerScenarios":"`match` or `if` values like `match: 'up == 1'`, `match: 'rate(x[5m])'`, `match: 'foo or bar'` — valid MetricsQL but not a bare series selector.","commonSituations":"Copying full alerting/recording-rule expressions into relabel `match`/`if`; users assuming selectors can contain operators; GUI-generated configs that emit expressions.","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"],"exampleFix":"// before\nif: 'up == 1'\n// after\nif: 'up'","handlingStrategy":"validation","validationCode":"import \"github.com/VictoriaMetrics/metricsql\"\n\nfunc ensureSeriesSelector(s string) error {\n\texpr, err := metricsql.Parse(s)\n\tif err != nil { return err }\n\tif _, ok := expr.(*metricsql.MetricExpr); !ok {\n\t\treturn fmt.Errorf(\"not a series selector: %q\", s)\n\t}\n\treturn nil\n}","typeGuard":"func isMetricExpr(expr metricsql.Expr) bool {\n\t_, ok := expr.(*metricsql.MetricExpr)\n\treturn ok\n}","tryCatchPattern":"if err := ie.Parse(userInput); err != nil {\n\tif strings.Contains(err.Error(), \"expecting series selector\") {\n\t\treturn fmt.Errorf(\"relabel selectors cannot contain functions/operators: %w\", err)\n\t}\n\treturn err\n}","preventionTips":["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"],"tags":["promql","series-selector","validation","prometheus","relabeling"],"backgroundTag":"invalid-series-selector","analyzedSha":"5079fb58f1e8e62113f90c945ad71586c797d770","analyzedAt":"2026-09-03T18:10:26.153Z","contentChangedAt":"2026-09-03T18:10:26.153Z","schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}