{"record":{"id":"7e3a36f2799bff63","repo":"SigNoz/signoz","slug":"errcodealertmanagerconfiginvalid-7e3a36","errorCode":"ErrCodeAlertmanagerConfigInvalid","errorMessage":"invalid filter","messagePattern":"invalid filter","errorType":"validation","errorClass":null,"httpStatus":400,"severity":"warning","filePath":"pkg/types/alertmanagertypes/alert.go","lineNumber":180,"sourceCode":"\treturn GettableAlertsParams{\n\t\tGetAlertsParams: params,\n\t\tRawQuery:        req.URL.RawQuery,\n\t}, nil\n}\n\nfunc NewGettableAlertsFromAlertProvider(\n\talerts provider.Alerts,\n\tcfg *Config,\n\tgetAlertStatusFunc func(model.Fingerprint) types.AlertStatus,\n\tsetAlertStatusFunc func(model.LabelSet),\n\tmutedByFunc func(model.LabelSet) []string,\n\tparams GettableAlertsParams,\n) (GettableAlerts, error) {\n\tres := GettableAlerts{}\n\n\tmatchers, err := parseFilter(params.Filter)\n\tif err != nil {\n\t\treturn nil, errors.Wrapf(err, errors.TypeInvalidInput, ErrCodeAlertmanagerConfigInvalid, \"invalid filter\")\n\t}\n\n\tvar receiverFilter *regexp.Regexp\n\tif params.Receiver != nil {\n\t\treceiverFilter, err = regexp.Compile(\"^(?:\" + *params.Receiver + \")$\")\n\t\tif err != nil {\n\t\t\treturn nil, errors.Wrapf(err, errors.TypeInvalidInput, ErrCodeAlertmanagerConfigInvalid, \"failed to parse receiver param\")\n\t\t}\n\t}\n\n\titerator := alerts.GetPending()\n\tdefer iterator.Close()\n\n\talertFilter := alertFilter(getAlertStatusFunc, setAlertStatusFunc, matchers, *params.Silenced, *params.Inhibited, *params.Active)\n\tnow := time.Now()\n\n\tfor a := range iterator.Next() {\n\t\tif err = iterator.Err(); err != nil {","sourceCodeStart":162,"sourceCodeEnd":198,"githubUrl":"https://github.com/SigNoz/signoz/blob/5069bf80b08f1f00d7e014eccc09902f9871004f/pkg/types/alertmanagertypes/alert.go#L162-L198","documentation":"NewGettableAlertsFromAlertProvider builds alertmanager GettableAlerts from provider params and throws this invalid-input error when parseFilter cannot parse the params.Filter matcher string. The filter uses alertmanager matcher syntax (e.g. 'severity=\"critical\", team=~\"web.*\"'), and any syntax error — unbalanced quotes, bad operators, stray characters — fails parsing before any data is fetched.","triggerScenarios":"Calling GetAlerts with a filter string containing invalid matcher syntax: missing quotes around values, invalid operators (=, !=, =~, !~ only), unmatched parentheses/braces, or empty matcher bodies. Also triggered by URL-encoding artifacts (e.g. %22 left in the string) when filters arrive via query params.","commonSituations":"Hand-built filter strings in API clients, dashboards passing raw user input as filter, double-encoding of query parameters, or version differences in accepted matcher syntax after alertmanager API upgrades.","solutions":["Check the wrapped parseFilter error for the position/reason of the syntax error and fix the matcher string","Validate the filter against matcher syntax before calling GetAlerts (parse it with the same parser client-side, or use the provider's own validation if exposed)","Ensure filter values are double-quoted and use only the four valid operators (=, !=, =~, !~)","If filters come from URLs, decode them exactly once before passing","Consider accepting structured matchers in your API and serializing to the string form yourself to avoid user-authored syntax"],"exampleFix":"// before\nalerts, err := alertProvider.GetAlerts(ctx, GettableAlertsParams{Filter: []string{`severity=critical`}})\n\n// after\nalerts, err := alertProvider.GetAlerts(ctx, GettableAlertsParams{Filter: []string{`severity=\"critical\"`}})","handlingStrategy":"validation","validationCode":"// Validate filter syntax before calling GetAlerts using the same parser:\nif _, err := parseFilter(params.Filter); err != nil {\n    return fmt.Errorf(\"bad filter: %w\", err)\n}","typeGuard":"func isValidFilter(f []string) bool {\n    for _, s := range f {\n        if _, err := parseFilter(s); err != nil { return false }\n    }\n    return true\n}","tryCatchPattern":"alerts, err := provider.GetAlerts(ctx, params)\nif err != nil {\n    if errors.Ast(err, errors.TypeInvalidInput) && errors.IsCode(err, ErrCodeAlertmanagerConfigInvalid) {\n        // 400 to the client with the parse error details\n    }\n}","preventionTips":["Quote all matcher values and restrict operators to =, !=, =~, !~","Build filters from structured matchers programmatically rather than concatenating user strings","URL-decode filter params exactly once before passing them to the provider"],"tags":["alertmanager","filter-parsing","invalid-input","matcher-syntax","go"],"backgroundTag":"alertmanager-filter-parse-error","analyzedSha":"5069bf80b08f1f00d7e014eccc09902f9871004f","analyzedAt":"2026-08-28T06:22:12.824Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}