prometheus / prometheus/alertmanager

Decode plus sign ('+') as a space (' ' or '%20') when decoding silence filters

Open
#3,946 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

component/templating
Dominant language
Go
Stars
8.6k
Forks
2.5k
Avg merge
2d 6h
Merged PRs (30d)
61

Description

What did you do?
We added a "silence" link to the pagerduty "details" map for convenience so that users don't have to click through to alertmanager and then re-find the alert they care about and then click the silence button. This uses the go function urlQuery which will become important later.

pagerduty:
  details:
    silence: |-
      https://alertmanager.at.mongodb.com/#/silences/new?filter=%7B
      {{- $first := true }}
      {{- with index .Alerts 0 -}}
        {{- range .Labels.SortedPairs -}}
          {{- if $first }}{{ $first = false }}{{ else }},{{ end -}}
          {{ .Name | urlquery }}%3D%22{{.Value | urlquery }}%22
        {{- end }}
      {{- end -}}%7D

What did you expect to see?

We expect the alerts to match existing alerts that are firing. This works in the vast majority of cases, but increasingly our users are using spaces in their alertnames

What did you see instead? Under which circumstances?

We see alertnames with pluses in them, which does not match any of the firing alerts since the firing alerts have spaces.

Why did you see this?

elm is very opinionated about it. And go templates just happen to use plusses instead of %20

https://github.com/elm/url/issues/32

Where is the patch?
https://github.com/prometheus/alertmanager/pull/3945

I just copied the solution from here since it's been a while since
using functional languages and I didn't know the order of the parser,
but I suspect there are much better places to put this, including
repacing in rest var above

https://github.com/elm/url/issues/32#issuecomment-803595052

Environment

$ uname -s
Linux
  • System information:

  • Alertmanager version:

Fails with later versions as well

Version Information
Branch:
HEAD
BuildDate:
20240228-11:51:20
BuildUser:
root@22cd11f671e9
GoVersion:
go1.21.7
Revision:
0aa3c2aad14cff039931923ab16b26b7481783b5
Version:
0.27.0

  • Prometheus version:

victoria metrics

  • Alertmanager configuration file:
insert configuration here
  • Prometheus configuration file:
insert configuration here (if relevant to the issue)
  • Logs:
insert Prometheus and Alertmanager logs relevant to the issue here

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Go urlQuery/urlquery template function referenced in the issue and review pull request #3945, including its suggested placement near the rest variable. Confirm the behavior for silence filters whose alert names contain spaces; done means decoding '+' as a space so those filters match firing alerts.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.