1
0
mirror of https://github.com/prometheus/alertmanager.git synced 2026-02-05 15:45:34 +01:00

157 Commits

Author SHA1 Message Date
Guido Trotter
8098e2275e Fix alertmanager test port allocation race conditions (#4768)
At the moment we try to allocate ports in the tests, the close them, and
then start alertmanager on those ports. This is very brittle and often
fails.

Fix the race conditions by directly starting alertmanager on
system-allocated free ports (using :0 in the address) and then detecting
the ports used, and using those in the test.

Signed-off-by: Guido Trotter <guido@hudson-trading.com>
Co-authored-by: Guido Trotter <guido@hudson-trading.com>
2025-12-02 12:10:34 -08:00
Guido Trotter
e542c68a6b MockWebhook: track shutdown status more gracefully (#4761)
* MockWebhook: track shutdown status more gracefully

When we close the server sometimes the messages are interrupted and
can't be decoded by the webhook. This change accepts any decoding
failure after server shutdown.

Signed-off-by: Guido Trotter <guido@hudson-trading.com>

* Call NewWebhook passing 't', and protect against nil cmd in Terminate

Signed-off-by: Guido Trotter <guido@hudson-trading.com>

---------

Signed-off-by: Guido Trotter <guido@hudson-trading.com>
Co-authored-by: Guido Trotter <guido@hudson-trading.com>
2025-11-21 19:01:59 +01:00
Guido Trotter
03e0782142 test/... remove duplicated code (#4752)
* Deduplicate code between test/cli and test/with_api_v2

Signed-off-by: Guido Trotter <guido@hudson-trading.com>

* Consolidate MockWebhook

Signed-off-by: Guido Trotter <guido@hudson-trading.com>

* Consolidate acceptance types and start cluster functionality

Signed-off-by: Guido Trotter <guido@hudson-trading.com>

---------

Signed-off-by: Guido Trotter <guido@hudson-trading.com>
Co-authored-by: Guido Trotter <guido@hudson-trading.com>
2025-11-21 15:07:16 +01:00
Guido Trotter
64ac47bfe6 Fix silence import: also wait for the error collection goroutine to finish (#4735)
* Fix silence import: also wait for the error collection goroutine to finish

As noticed by George Robinson the error collection goroutine in silence
import is also not waited for, so we may get an incorrect count when we
exit. This adds a done channel for that goroutine, and checks that the
error count is correct with a new test.

Signed-off-by: Guido Trotter <guido@hudson-trading.com>

* bulkImport: use sync.Once to close channels

Signed-off-by: Guido Trotter <guido@hudson-trading.com>

---------

Signed-off-by: Guido Trotter <guido@hudson-trading.com>
Co-authored-by: Guido Trotter <guido@hudson-trading.com>
2025-11-21 14:53:12 +01:00
Ben Kochie
f656273159 Enable modernize linter (#4750)
Enable the golangci-lint modernize linter.
* Add exception for the omitempty struct issue.
* Apply modernize fixes.

Signed-off-by: SuperQ <superq@gmail.com>
2025-11-18 11:46:15 +01:00
Solomon Jacobs
023885c52c chore: modernize with range over int (#4746)
A purely mechanical change with no effect on behaviour. Stops `gopls`
from complaining.

Corresponding spec, see here:
https://github.com/golang/go/issues/61405

Introduced in `Go 1.22`, see here:
https://go.dev/ref/spec#For_range

Signed-off-by: Solomon Jacobs <solomonjacobs@protonmail.com>
2025-11-18 09:43:43 +01:00
Siavash Safi
2e0970e8d8 feat(dispatch): add start delay (#4704)
This change adds a new cmd flag `--dispatch.start-delay` which
corresponds to the `--rules.alert.resend-delay` flag in Prometheus.
This flag controls the minimum amount of time that Prometheus waits
before resending an alert to Alertmanager.

By adding this value to the start time of Alertmanager, we delay
the aggregation groups' first flush, until we are confident all alerts
are resent by Prometheus instances.

This should help avoid race conditions in inhibitions after a (re)start.

Other improvements:
- remove hasFlushed flag from aggrGroup
- remove mutex locking from aggrGroup

Signed-off-by: Alexander Rickardsson <alxric@aiven.io>
Signed-off-by: Siavash Safi <siavash@cloudflare.com>
Co-authored-by: Alexander Rickardsson <alxric@aiven.io>
2025-11-15 15:35:59 +01:00
Guido Trotter
da9f50c540 Fix erroneous channels close (#4733)
* Fix erroneous channels close

while we did fix the goroutine leak at bulk import, in case of errors,
unfortunately we broke the non-error path, since the silence channel
needed to be closed, so that addSilenceWorker would terminate the loop,
and and wg.Wait would work

solve this by having just one cleanup function, that gets called on
defer, but also manually before returning, ensuring the error count is
correct, and all workers have indeed been collected.

Fixes issue introduced in https://github.com/prometheus/alertmanager/pull/4556

Signed-off-by: Guido Trotter <guido@hudson-trading.com>

* Add import silence cli tests

Signed-off-by: Guido Trotter <guido@hudson-trading.com>

---------

Signed-off-by: Guido Trotter <guido@hudson-trading.com>
Co-authored-by: Guido Trotter <guido@hudson-trading.com>
2025-11-14 07:56:00 +01:00
Hélia Barroso
e75b0814e9 feat: replace interface with any
Signed-off-by: Hélia Barroso <helia_barroso@hotmail.com>
2025-08-28 11:29:43 +01:00
Matthieu MOREL
31b64f6a00 chore: bump golangci-lint to v2.3.0
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2025-08-01 23:40:52 +02:00
SuperQ
e3725c1290 Update Go
* Update Go build to 1.24.
* Update minimum Go version to 1.23.
* Fixup various testifylint issues.

Signed-off-by: SuperQ <superq@gmail.com>
2025-03-27 09:56:40 +01:00
Steve Simpson
0f65e8fa5f Add timeout option for webhook notifier. (#4137)
* Add timeout option for webhook notifier.

Signed-off-by: Steve Simpson <steve@grafana.com>

* Tweak error handling and de-pointer timeout field.

Signed-off-by: Steve Simpson <steve@grafana.com>

---------

Signed-off-by: Steve Simpson <steve@grafana.com>
2024-12-02 14:53:51 +00:00
George Robinson
58dc6f8d33 Fix invalid silence causes incomplete updates (#3898)
This commit fixes a bug where an invalid silence causes incomplete
updates of existing silences. This is fixed moving validation
out of the setSilence method and putting it at the start of the
Set method instead.

Signed-off-by: George Robinson <george.robinson@grafana.com>
2024-06-25 12:38:33 +01:00
George Robinson
342f6a599c Add godot linter (#3613)
* Add godot linter

Signed-off-by: George Robinson <george.robinson@grafana.com>

* Remove extra line from LICENSE

Signed-off-by: George Robinson <george.robinson@grafana.com>

---------

Signed-off-by: George Robinson <george.robinson@grafana.com>
2024-03-21 11:26:46 +00:00
George Robinson
4d6ddd25c9 Fix panic in acceptance tests (#3592)
* Fix panic in acceptance tests

This commit attempts to address a panic that occurs in acceptance
tests if a server in the cluster fails to start.

Signed-off-by: George Robinson <george.robinson@grafana.com>

* Remove started and check am.cmd.Process != nil

Signed-off-by: George Robinson <george.robinson@grafana.com>

---------

Signed-off-by: George Robinson <george.robinson@grafana.com>
2024-02-13 15:38:44 +00:00
Matthieu MOREL
b9e347b9d1 golangci-lint: enable testifylint linter
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2023-12-10 08:50:03 +00:00
Matthieu MOREL
b81bad8711 use Go standard errors
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2023-12-08 16:44:13 +01:00
George Robinson
4494abfce4 Fix UTF-8 not supported in group_by (#3619)
* Fix UTF-8 not supported in group_by

This commit fixes missing UTF-8 support in the group_by for routes.

Signed-off-by: George Robinson <george.robinson@grafana.com>
---------

Signed-off-by: George Robinson <george.robinson@grafana.com>
2023-11-24 11:26:39 +00:00
George Robinson
70bd5dad98 Support UTF-8 label matchers: Use compat package in Alertmanager server (#3567)
* Support UTF-8 label matchers: Use compat package in Alertmanager server

This pull request adds use of the compat package in Alertmanager server that will allow users to switch between the new matchers/parse parser and the old pkg/labels parser. The new matchers/parse parser uses a fallback mechanism where if the input cannot be parsed in the new parser it then attempts to use the old parser. If an input is parsed in the old parser but not the new parser then a warning log is emitted.

Signed-off-by: George Robinson <george.robinson@grafana.com>

---------

Signed-off-by: George Robinson <george.robinson@grafana.com>
2023-11-24 10:01:40 +00:00
gotjosh
b4f7027908 Deprecate and remove api/v1/ (#2970)
* Deprecate and remove api/v1/

Signed-off-by: gotjosh <josue.abreu@gmail.com>
---------

Signed-off-by: gotjosh <josue.abreu@gmail.com>
2023-11-24 09:06:04 +00:00
George Robinson
16aa996c4f Support UTF-8 label matchers: Add compat package with feature flag and use in amtool (#3483)
* Add adapter package for parser feature flag

This commit adds the compat package allowing users to switch
between the new matchers/parse parser and the old pkg/labels parser.
The new matchers/parse parser uses a fallback mechanism where if
the input cannot be parsed in the new parser it then attempts to
use the old parser. If an input is parsed in the old parser but
not the new parser, then a warning log is emitted.

---------

Signed-off-by: George Robinson <george.robinson@grafana.com>
2023-10-19 12:00:01 +01:00
George Robinson
5a462df83a Support UTF-8 label matchers: Add more acceptance tests for braces when using amtool (#3523)
* Add tests for PromQL braces when using amtool alert

Signed-off-by: George Robinson <george.robinson@grafana.com>
---------

Signed-off-by: George Robinson <george.robinson@grafana.com>
2023-09-21 13:57:11 +01:00
George Robinson
5ba9b9c7c3 Add test for PromQL braces when parsing lists of matchers (#3507)
* Add test for PromQL braces when parsing lists of matchers

Signed-off-by: George Robinson <george.robinson@grafana.com>

* Use acceptance tests

Signed-off-by: George Robinson <george.robinson@grafana.com>

* Add test creating silence with braces

Signed-off-by: George Robinson <george.robinson@grafana.com>

---------

Signed-off-by: George Robinson <george.robinson@grafana.com>
2023-09-12 17:00:18 +01:00
George Robinson
6ce841ca22 Fix scheme required for webhook url in amtool (#3509)
* Fix scheme required for webhook url in amtool

This commit fixes issue #3505 where amtool would fail with
"error: scheme required for webhook url" when using amtool
with --alertmanager.url.

The issue here is that UnmarshalYaml for WebhookConfig checks
if the scheme is present when c.URL is non-nil. However,
UnmarshalYaml for SecretURL returns a non-nil, default value
url.URL{} if the response from api/v2/status contains <secret>
as the webhook URL.

Signed-off-by: George Robinson <george.robinson@grafana.com>

* Add test for config routes test

Signed-off-by: George Robinson <george.robinson@grafana.com>

---------

Signed-off-by: George Robinson <george.robinson@grafana.com>
2023-09-05 17:53:24 +01:00
Rohan Gupta
df1dc0d359 Changes receiver and inhibition rules arrays to slices of value items
Signed-off-by: Rohan Gupta <rohangupta.0927@gmail.com>
2023-01-18 10:21:51 -05:00
Simon Pasquier
01e1f5433a test: reduce flakiness of acceptance tests
The CI environment isn't as performant as local machines: the time
needed to fully initialize the test environment can be significant and
skew the verification. Rather than setting the "virtual" clock used to
measure alert timings at the beginning of the acceptance test, it is
better to wait for the test bed to be ready.

Signed-off-by: Simon Pasquier <spasquie@redhat.com>
2023-01-13 16:10:38 +01:00
Ben Kochie
432ee01c8c Update Go to 1.19 (#3150)
* Update Go to 1.19

* Update Go.
* Update some Go modules.
* Update Swagger to the latest for Go 1.19 compatibility.
* api/v2: regenerate
* Accommodate to the changes in the client package
* asset/assets_vfsdata.go: regenerate

Signed-off-by: SuperQ <superq@gmail.com>
Signed-off-by: Simon Pasquier <spasquie@redhat.com>
Co-authored-by: Simon Pasquier <spasquie@redhat.com>
2022-11-30 17:06:57 +01:00
Cosrider
228b7959b3 Delete unreachable code caused by t.Fatalf (#3042)
Signed-off-by: Cosrider <cosrider7@gmail.com>

Signed-off-by: Cosrider <cosrider7@gmail.com>
2022-09-09 16:07:53 +02:00
inosato
791e542100 Remove ioutil
Signed-off-by: inosato <si17_21@yahoo.co.jp>
2022-07-18 22:01:02 +09:00
gotjosh
cbc94fad46 Acceptance Tests: Better error messages
The CI keeps reporting flakes for our acceptance test around the starting and stopping of the Alertmanagers. While I have an idea of where these failures are coming from, it would be nice to get a confirmation by structuring our error messages a bit better.

Signed-off-by: gotjosh <josue.abreu@gmail.com>
2022-07-07 11:09:42 +01:00
gotjosh
ef786ea402 Force close mock servers as part of v2 acceptance tests
While merging #2944, I noticed the CI failed: https://app.circleci.com/pipelines/github/prometheus/alertmanager/2686/workflows/b6f87b0a-20c3-455b-b706-432c38a77511/jobs/12028.

It seemed like a deadlock between uncoordinated routines but I couldn't pin point (or reproduce, I tried with -race and -count) the exact problem. However, from the logs, I could point out where the problem originated and kind of have a hunch it had to do with the way net listeners are handled by the TODO removed.

The more worrying bit of the CI failure is that it took 10m to timeout, with this change we'll force close the connection with a 5s deadline so at the very least we'll get the feedback faster.

Signed-off-by: gotjosh <josue.abreu@gmail.com>
2022-06-17 12:43:43 +01:00
Matthias Loibl
a6d10bd5bc Update golangci-lint and fix complaints (#2853)
* Copy latest golangci-lint files from Prometheus

Signed-off-by: Matthias Loibl <mail@matthiasloibl.com>

* Use grafana/regexp over stdlib regexp

Signed-off-by: Matthias Loibl <mail@matthiasloibl.com>

* Fix typos in comments

Signed-off-by: Matthias Loibl <mail@matthiasloibl.com>

* Fix goimports complains in import sorting

Signed-off-by: Matthias Loibl <mail@matthiasloibl.com>

* gofumpt all Go files

Signed-off-by: Matthias Loibl <mail@matthiasloibl.com>

* Update naming to comply with revive linter

Signed-off-by: Matthias Loibl <mail@matthiasloibl.com>

* config: Fix error messages to be lower case

Signed-off-by: Matthias Loibl <mail@matthiasloibl.com>

* test/cli: Fix error messages to be lower case

Signed-off-by: Matthias Loibl <mail@matthiasloibl.com>

* .golangci.yaml: Remove obsolete space

Signed-off-by: Matthias Loibl <mail@matthiasloibl.com>

* config: Fix expected victorOps error

Signed-off-by: Matthias Loibl <mail@matthiasloibl.com>

* Use stdlib regexp

Signed-off-by: Matthias Loibl <mail@matthiasloibl.com>

* Clean up Go modules

Signed-off-by: Matthias Loibl <mail@matthiasloibl.com>
2022-03-25 17:59:51 +01:00
sinkingpoint
e2a10119aa Move api v1 client into v1 tests
This commit moves the stuff formerly in /client into /test/with_api_v1
so that we can discourage use of the v1 client without breaking things

Signed-off-by: sinkingpoint <colin@quirl.co.nz>
2021-11-16 09:36:07 +01:00
QuentinBisson
4aea4560ce Fix flapping acceptance test
Signed-off-by: QuentinBisson <quentin@giantswarm.io>
2021-04-28 15:04:37 +02:00
Ben Kochie
53535551f5 Fix up golangci-lint errors.
Signed-off-by: Ben Kochie <superq@gmail.com>
2021-03-16 10:43:45 +01:00
Kiril Vladimirov
7320d83cbc Replace types.Matcher(s)? with labels.Matcher(s)?
Signed-off-by: Kiril Vladimirov <kiril@vladimiroff.org>
2021-01-22 17:02:48 +02:00
Josh Soref
0f2c65d265 Spelling (#2167)
* spelling: inhibition

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: matchers

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: notification

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: nonexistent

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: obfuscated

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: occurred

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: relevant

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: unexpected

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: marshaled

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: marshaling

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2020-01-23 17:06:16 +01:00
Ilya Gladyshev
196c62f488 At least one non-empty silence matcher (#2081)
* check if at least one silence matcher doesn't match empty strings

Signed-off-by: qoops <ilya.v.gladyshev@gmail.com>

* fixed grammar

Signed-off-by: qoops <ilya.v.gladyshev@gmail.com>
2019-10-31 15:42:03 +01:00
stuart nelson
a74758e4c7 Merge pull request #1830 from pgier/amtool-tests
test/cli: add basic amtool cli tests
2019-07-24 17:41:10 +02:00
Paul Gier
588e1e3f9f test/cli: add periods to comment sentences and import ordering
Signed-off-by: Paul Gier <pgier@redhat.com>
2019-06-20 10:37:59 -05:00
Simon Pasquier
1207b90029 test/with_api_v2: remove calls to the v1 API
Signed-off-by: Simon Pasquier <spasquie@redhat.com>
2019-06-20 17:37:08 +02:00
Paul Gier
50ad3114a0 test/cli: add basic tests for amtool cli
Signed-off-by: Paul Gier <pgier@redhat.com>
2019-06-19 17:33:35 -05:00
Simon Pasquier
0c3120efac *: split notify package
Instead of keeping all notifiers in the notify package, it splits them
into individual sub-packages. This improves readability and
maintainability of the code.

Signed-off-by: Simon Pasquier <spasquie@redhat.com>
2019-06-18 15:36:19 +02:00
Simon Pasquier
c20873b1fe test/with_api_v2: fix variable shadowing (#1889)
Signed-off-by: Simon Pasquier <spasquie@redhat.com>
2019-05-15 10:49:59 +02:00
stuart nelson
6749f9faa9 Merge pull request #1871 from johncming/hotfix/dup-close
test/with_api_v1: delete duplicate close of http body.
2019-05-06 12:41:29 +02:00
johncming
1c38a90eeb test/with_api_v1: delete duplicate close of http body.
Signed-off-by: johncming <johncming@yahoo.com>
2019-05-05 08:40:18 +08:00
stuart nelson
1cc6c6f79c Move alert endpoints filter parsing to single function
They are exactly the same, no reason to duplicate.

Signed-off-by: stuart nelson <stuartnelson3@gmail.com>
2019-04-30 10:59:17 +02:00
Paul Gier
8688c7b9ad api/v2: move generated client code from test to api/v2 (#1792)
- Move the generated api/v2 client code out of the test directory
and into the api/v2 directory with models and restapi.
- Remove duplicate models directory
- Update tests to use api/v2 package for models and client

Signed-off-by: Paul Gier <pgier@redhat.com>
2019-03-12 17:11:23 +01:00
Karsten Weiss
c637ca1a6e Fix typos in comments and metric HELPs (#1790)
No functional change.

Signed-off-by: Karsten Weiss <knweiss@gmail.com>
2019-03-12 10:29:26 +01:00
Paul Gier
458f1d646b Makefile improvements
- make clean shouldn't print errors when files/directories have already
been removed
- add copyright header to generated api files to pass license check

Signed-off-by: Paul Gier <pgier@redhat.com>
2019-03-11 10:45:45 -05:00