SigNoz/signoz · warning

ErrCodeAlertmanagerConfigInvalid

ErrCodeAlertmanagerConfigInvalid

Error message

invalid filter

What it means

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.

Source

Thrown at pkg/types/alertmanagertypes/alert.go:180

	return GettableAlertsParams{
		GetAlertsParams: params,
		RawQuery:        req.URL.RawQuery,
	}, nil
}

func NewGettableAlertsFromAlertProvider(
	alerts provider.Alerts,
	cfg *Config,
	getAlertStatusFunc func(model.Fingerprint) types.AlertStatus,
	setAlertStatusFunc func(model.LabelSet),
	mutedByFunc func(model.LabelSet) []string,
	params GettableAlertsParams,
) (GettableAlerts, error) {
	res := GettableAlerts{}

	matchers, err := parseFilter(params.Filter)
	if err != nil {
		return nil, errors.Wrapf(err, errors.TypeInvalidInput, ErrCodeAlertmanagerConfigInvalid, "invalid filter")
	}

	var receiverFilter *regexp.Regexp
	if params.Receiver != nil {
		receiverFilter, err = regexp.Compile("^(?:" + *params.Receiver + ")$")
		if err != nil {
			return nil, errors.Wrapf(err, errors.TypeInvalidInput, ErrCodeAlertmanagerConfigInvalid, "failed to parse receiver param")
		}
	}

	iterator := alerts.GetPending()
	defer iterator.Close()

	alertFilter := alertFilter(getAlertStatusFunc, setAlertStatusFunc, matchers, *params.Silenced, *params.Inhibited, *params.Active)
	now := time.Now()

	for a := range iterator.Next() {
		if err = iterator.Err(); err != nil {

View on GitHub (pinned to 5069bf80b0)

Solutions

  1. Check the wrapped parseFilter error for the position/reason of the syntax error and fix the matcher string
  2. 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)
  3. Ensure filter values are double-quoted and use only the four valid operators (=, !=, =~, !~)
  4. If filters come from URLs, decode them exactly once before passing
  5. Consider accepting structured matchers in your API and serializing to the string form yourself to avoid user-authored syntax

Example fix

// before
alerts, err := alertProvider.GetAlerts(ctx, GettableAlertsParams{Filter: []string{`severity=critical`}})

// after
alerts, err := alertProvider.GetAlerts(ctx, GettableAlertsParams{Filter: []string{`severity="critical"`}})
Defensive patterns

Strategy: validation

Validate before calling

// Validate filter syntax before calling GetAlerts using the same parser:
if _, err := parseFilter(params.Filter); err != nil {
    return fmt.Errorf("bad filter: %w", err)
}

Type guard

func isValidFilter(f []string) bool {
    for _, s := range f {
        if _, err := parseFilter(s); err != nil { return false }
    }
    return true
}

Try / catch

alerts, err := provider.GetAlerts(ctx, params)
if err != nil {
    if errors.Ast(err, errors.TypeInvalidInput) && errors.IsCode(err, ErrCodeAlertmanagerConfigInvalid) {
        // 400 to the client with the parse error details
    }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of SigNoz/signoz@5069bf80b0 (2026-08-28). Data as JSON: /api/errors/7e3a36f2799bff63. Report an issue: GitHub.