alertmanager icon indicating copy to clipboard operation
alertmanager copied to clipboard

bad matcher format when the filter param contains a leading '{' and a trailing '}'

Open ilpianista opened this issue 4 years ago • 5 comments

What did you do?

I upgraded Alertmanager from 0.21.0 to 0.23.0.

What did you expect to see?

http://localhost:9093/api/v2/silences?filter={alertname=%22MyAlert%22} should return a list of filtered silences.

What did you see instead? Under which circumstances?

It returns "bad matcher format: {alertname=\"MyAlert\"}"

Environment

  • System information:

    Linux 3.13.0-132-generic x86_64

  • Alertmanager version:

      alertmanager, version 0.23.0 (branch: HEAD, revision: 61046b17771a57cfd4c4a51be370ab930a4d7d54)
      build user:       root@e21a959be8d2
      build date:       20210825-10:48:55
      go version:       go1.16.7
      platform:         linux/amd64
    

ilpianista avatar Jan 05 '22 12:01 ilpianista

I forgot to say that if I remove the leading and trailing {} it works, but the doc says:

A leading '{' and/or a trailing '}' is optional and will be trimmed before further parsing.

ilpianista avatar Jan 05 '22 12:01 ilpianista

This discrepancy comes from https://github.com/prometheus/alertmanager/blob/e3fb99cc2d24330fdb81aa1d466c19b3de328b5b/api/v2/api.go - ParseMatcher is used to parse each individual filter arg (which doesn't strip braces), rather than ParseMatchers which does. FWIW the Swagger API documentation doesn't specify (or at least, hints that args are individual Matchers rather than one Matchers), so I don't think there's anything incorrect with the docs, it's just misleading perhaps

sinkingpoint avatar Jan 06 '22 00:01 sinkingpoint

Ok, but still the behavior changed by upgrading from 0.21.0 (maybe 0.22.0 too?) to 0.23.0.

ilpianista avatar Jan 13 '22 12:01 ilpianista

Ok, but still the behavior changed by upgrading from 0.21.0 (maybe 0.22.0 too?) to 0.23.0.

The change is from 0.21 to 0.22. It's not recorded in CHANGELOG. https://github.com/prometheus/alertmanager/pull/2441

johncming avatar Feb 07 '22 08:02 johncming

Agreed that the API documentation can be improved.

simonpasquier avatar Mar 04 '22 14:03 simonpasquier

@waltherlee I guess this issue is resolved in v0.30?

SoloJacobs avatar Dec 07 '25 11:12 SoloJacobs

Yes, I'm closing it

waltherlee avatar Dec 07 '25 20:12 waltherlee