{"record":{"id":"798884a382da7fca","repo":"thanos-io/thanos","slug":"failed-to-convert-matchers-798884","errorCode":null,"errorMessage":"failed to convert matchers","messagePattern":"failed to convert matchers","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/thanos/rule.go","lineNumber":800,"sourceCode":"\t\t\tinfo.WithStatusInfoFunc(),\n\t\t)\n\t\tstoreServer := store.NewLimitedStoreServer(store.NewInstrumentedStoreServer(reg, tsdbStore), reg, conf.storeRateLimits)\n\t\toptions = append(options, grpcserver.WithServer(store.RegisterStoreServer(storeServer, logger)))\n\n\t\t// Add Status server for TSDB statistics\n\t\tstatusSrv := status.NewServer(\n\t\t\tcomponent.Rule.String(),\n\t\t\tstatus.WithTSDBStatisticsGetter(\n\t\t\t\tstatus.TSDBStatisticsGetterFunc(func(limit int, matchers []storepb.LabelMatcher) (map[string]tsdb.Stats, error) {\n\t\t\t\t\tif !httpProbe.IsReady() {\n\t\t\t\t\t\treturn nil, errors.New(\"not ready\")\n\t\t\t\t\t}\n\n\t\t\t\t\t// Check if external labels match the provided matchers.\n\t\t\t\t\textLabels := conf.lset\n\t\t\t\t\tpromMatchers, err := storepb.MatchersToPromMatchers(matchers...)\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\treturn nil, errors.Wrap(err, \"failed to convert matchers\")\n\t\t\t\t\t}\n\t\t\t\t\tfor _, matcher := range promMatchers {\n\t\t\t\t\t\tif !matcher.Matches(extLabels.Get(matcher.Name)) {\n\t\t\t\t\t\t\t// External labels don't match, return empty result.\n\t\t\t\t\t\t\treturn nil, nil\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tstats := tsdbDB.Head().Stats(labels.MetricName, limit)\n\t\t\t\t\treturn map[string]tsdb.Stats{\n\t\t\t\t\t\t\"\": *stats,\n\t\t\t\t\t}, nil\n\t\t\t\t}),\n\t\t\t),\n\t\t)\n\t\toptions = append(options, grpcserver.WithServer(status.RegisterStatusServer(statusSrv)))\n\t}\n","sourceCodeStart":782,"sourceCodeEnd":818,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/cmd/thanos/rule.go#L782-L818","documentation":"The status server converts incoming protobuf storepb.LabelMatchers to Prometheus matchers via storepb.MatchersToPromMatchers before applying external-label filtering. If a matcher's type or value cannot be represented as a Prometheus matcher, the error is wrapped as \"failed to convert matchers\" and the TSDBStats RPC fails.","triggerScenarios":"Calling the TSDB statistics API with a malformed label matcher: unknown matcher type in the protobuf, invalid regex value (uncompilable RE2), or an otherwise invalid matcher value in the request.","commonSituations":"Hand-crafted gRPC/API requests with wrong matcher type enums; a client sending a regex matcher with syntactically invalid regex like \"[a-\"; version mismatch between client storepb API and server.","solutions":["Fix the matcher: ensure regex values are valid RE2 (test with a regex validator).","Use only supported matcher types (EQ, NEQ, RE, NRE) in the request.","Update the client library to match the server's storepb API version.","Simplify to exact label matchers (\"=\" instead of \"=~\") when regex is unnecessary."],"exampleFix":"// before\nmatcher: {type: RE, name: \"rule\", value: \"[a-\"}   // invalid regex\n// after\nmatcher: {type: RE, name: \"rule\", value: \"[a-z]+\"}","handlingStrategy":"validation","validationCode":"// validate matchers client-side before the RPC\nre, err := regexp.Compile(m.Value)\nif err != nil { return fmt.Errorf(\"invalid matcher regex %q: %w\", m.Value, err) }","typeGuard":"func validMatcher(m storepb.LabelMatcher) bool {\n  switch m.Type {\n  case storepb.LabelMatcher_EQ, storepb.LabelMatcher_NEQ:\n    return true\n  case storepb.LabelMatcher_RE, storepb.LabelMatcher_NRE:\n    _, err := regexp.Compile(m.Value)\n    return err == nil\n  }\n  return false\n}","tryCatchPattern":null,"preventionTips":["Compile regex matchers client-side before sending","Restrict UI/automation to EQ/NEQ/RE/NRE matcher types","Keep client storepb versions aligned with the server"],"tags":["grpc","matchers","validation","regex"],"backgroundTag":"invalid-regex-pattern","analyzedSha":"35b8b991177def87ed52dcf10f9b6d87f07282c8","analyzedAt":"2026-09-07T01:49:59.689Z","contentChangedAt":"2026-09-07T01:49:59.689Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}