Commit Graph

115 Commits

Author SHA1 Message Date
Kiril Vladimirov
2b6315f399 api/v2: Add Matcher.IsEqual to support all types
Signed-off-by: Kiril Vladimirov <kiril@vladimiroff.org>
2021-02-16 14:22:59 +02:00
Koki Kato
b5ddc5d638 Add test cases for silences with negative matchers
Signed-off-by: Koki Kato <koki.kato1994@gmail.com>
2021-02-09 23:01:21 +09:00
Koki Kato
b9aae07a73 Check silence matching with Protobuf models
Signed-off-by: Koki Kato <koki.kato1994@gmail.com>

To support negative matchers.
2021-02-09 22:53:00 +09:00
Koki Kato
72ce7fd71f api: add test for gettableSilenceMatchesFilterLabels
Signed-off-by: Koki Kato <koki.kato1994@gmail.com>
2021-02-09 22:07:15 +09:00
Koki Kato
f8c33ab47d api: check silence matching by string comparison in getSilences
Signed-off-by: Koki Kato <koki.kato1994@gmail.com>
2021-02-09 22:07:15 +09: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
Victor Araujo
846c04e807
Make filter labels consistent with Prometheus (#2403)
* Make filter labels consistent with Prometheus

Filtering the alert out when the label is missing precludes a
possible match for an empty value. This change allows the
match to be evaluated.

Closes #2342

Signed-off-by: Victor Araujo <vear91@gmail.com>

* Add tests for matchFilterLabels in v2 api

Signed-off-by: Victor Araujo <vear91@gmail.com>
2020-11-06 11:26:32 +01:00
Julien Pivotto
1cba0c7a37
Remove HipChat (#2281)
Signed-off-by: Julien Pivotto <roidelapluie@inuits.eu>
2020-06-11 15:51:10 +02:00
Simon Pasquier
e0cc523893
api/v2: add path and method to API v2 logs (#2261)
* api/v2: add path and method to API v2 logs

When an API v2 handler logged a message, the log wouldn't include the
path and method. Since different handlers perform the same validations
(e.g. matchers for alerts and silences), it isn't easy to know which
handler was invoked (though the logged filename
+ line number provides a hint).

Signed-off-by: Simon Pasquier <spasquie@redhat.com>

* Capitalize messages + improve logs

Signed-off-by: Simon Pasquier <spasquie@redhat.com>
2020-06-02 16:13:31 +02:00
Simon Pasquier
e347c31ab6
api/v2: return empty array of peers when disabled (#2203)
Signed-off-by: Simon Pasquier <spasquie@redhat.com>
2020-03-10 15:47:43 +01:00
Simon Pasquier
56e966bc20
api/v2: Fix silence creation error message (#2179)
Signed-off-by: Simon Pasquier <spasquie@redhat.com>
2020-02-13 10:07:58 +01:00
Célian GARCIA
dcc0b70c7d
[Minor][one line change] Fix an error message about start and end time validation. EOM (#2173)
* Fix an error message about start and end time validation

Signed-off-by: Célian Garcia <celian.garcia@amadeus.com>

* Modified start and end time validation message to be affirmative

Signed-off-by: Célian Garcia <celian.garcia@amadeus.com>
2020-02-05 15:13:46 +01: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
meichuntao
5cb556e4b2 api/metrics/metrics.go: Fix returning wrong counter (#2126)
Signed-off-by: meichuntao <mei.chuntao@zte.com.cn>
2019-12-04 11:26:13 +01:00
johncming
5ef70697a7 api/v1: return error more clear and common. (#2050)
Signed-off-by: johncming <johncming@yahoo.com>
2019-09-27 10:05:09 +02:00
Simon Pasquier
e4437ab54f
*: remove dependency on github.com/prometheus/prometheus (#2009)
Signed-off-by: Simon Pasquier <spasquie@redhat.com>
2019-09-16 10:56:29 +02:00
Simon Pasquier
d5f6f88928
*: bump Open API dependencies (#2024)
Signed-off-by: Simon Pasquier <spasquie@redhat.com>
2019-09-09 10:57:38 +02:00
Simon Pasquier
98a604efa7
api/v2: fix alerts with multiple receivers (#1948)
Signed-off-by: Simon Pasquier <spasquie@redhat.com>
2019-07-03 16:34:54 +02:00
Simon Pasquier
adcf283d4c api: add missing metrics for API v2
Signed-off-by: Simon Pasquier <spasquie@redhat.com>
2019-05-24 14:48:45 +02:00
stuart nelson
0a7e227549 Merge branch 'master' into default-grouping-in-ui
Signed-off-by: stuart nelson <stuartnelson3@gmail.com>
2019-04-30 15:09:56 +02: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
Andrey Kuzmin
287c149f92 Regenerate v2 models
Signed-off-by: Andrey Kuzmin <andrey.kuzmin@soundcloud.com>
2019-04-27 12:44:12 +02:00
Andrey Kuzmin
26f3e4ef44 Generate AlertGroup decoders
Signed-off-by: Andrey Kuzmin <andrey.kuzmin@soundcloud.com>
2019-04-27 12:14:31 +02:00
stuart nelson
2fa210d0e3 add groups endpoint to v2 api
Signed-off-by: stuart nelson <stuartnelson3@gmail.com>
2019-04-17 11:32:21 +02:00
Paul Gier
74fa2236f7 cli: update amtool to use apiv2
Includes godoc improvements

Signed-off-by: Paul Gier <pgier@redhat.com>
2019-03-29 09:11:09 -05:00
Paul Gier
89b0ff0574 api/v2: Respond with 404 when silence ID is not found (#1816)
When the client attempts to update a silence with a non-existent
ID, respond with a 404 (Not Found) instead of a 400 (Bad Request).

Signed-off-by: Paul Gier <pgier@redhat.com>
2019-03-29 12:29:00 +01:00
Matthias Loibl
70dde48f5c
Sort peers before returning via API
Signed-off-by: Matthias Loibl <mail@matthiasloibl.com>
2019-03-15 14:58:14 +01:00
Panayiotis
f40ecee773 api/v1: Add POST as an allowed CORS request method (#1796)
Signed-off-by: xdrop <xdrop.me@gmail.com>
2019-03-14 12:14:22 +01: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
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
Paul Gier
538305bec9 update Makefile.common and license headers
Sync Makefile.common to latest which updates promu version
and adds license check to default target.
Add missing license headers.

Signed-off-by: Paul Gier <pgier@redhat.com>
2019-03-11 10:39:31 -05:00
Paul Gier
3ffe6cfdc8 api/v2: sort silences similarly to v1 api (#1786)
* api/v2: sort silences similarly to v1 api

Sort the queried silences to match behaviour in the v1 api.

Sort silences in-place instead of creating multiple slices.
Use separate function for sorting silences for easier testing.
Add unit test for sort order.

Signed-off-by: Paul Gier <pgier@redhat.com>
2019-03-11 14:19:52 +01:00
Simon Pasquier
bc373f562f *: fix filter parameters with comma
Signed-off-by: Simon Pasquier <spasquie@redhat.com>
2019-03-08 09:56:05 +01:00
beorn7
3c981a92f7 Improve Mutes performance for silences
Add version tracking of silences states. Adding a silence to the state
increments the version. If the version hasn't changed since the last
time an alert was checked for being silenced, we only have to verify
that the relevant silences are still active rather than checking the
alert against all silences.

Signed-off-by: beorn7 <beorn@soundcloud.com>
2019-02-28 12:34:41 +01:00
beorn7
f3d9c89bbc Create a Muter implementation for silences
This encapsulates the logic of querying and marking silenced
alerts. It removes the code duplication flagged earlier.

I removed the error returned by the setAlertStatus function as we were
only logging it, and that's already done anyway when the error is
received from the `silence.Query` call (now in the `Mutes` method).

Signed-off-by: beorn7 <beorn@soundcloud.com>
2019-02-26 16:42:59 +01:00
Simon Pasquier
c7de536129
*: use stdlib context (#1768)
This changes removes all usage of golang.org/x/net/context in the code
base. It also bumps a few dependencies for the same reason:
- github.com/gogo/protobuf
- go-openapi/*

Signed-off-by: Simon Pasquier <spasquie@redhat.com>
2019-02-26 12:18:57 +01:00
Max Inden
6d555302fc
Merge pull request #1744 from mxinden/introduce-config-coordinator
*: Introduce config coordinator bundling config specific logic
2019-02-25 12:01:46 +01:00
Max Leonard Inden
d0cd5a0f08
*: Introduce config coordinator bundling config specific logic
Instead of handling all config specific logic inside
Alertmangaer.main(), this patch introduces the config coordinator
component.

Tasks of the config coordinator:
- Load and parse configuration
- Notify subscribers on configuration changes
- Register and manage configuration specific metrics

Signed-off-by: Max Leonard Inden <IndenML@gmail.com>
2019-02-25 11:26:30 +01:00
Nguyen Quang Huy
edf170d03b Add signed off to commit (#1766)
- Fix error string should not be capitalized from [Golang coding convention](https://github.com/golang/go/wiki/CodeReviewComments#error-strings)
- Fix some typos

Signed-off-by: Nguyen Quang Huy <huynq0911@gmail.com>
2019-02-25 11:04:42 +01:00
Simon Pasquier
57c4ff10ab api/v2: serve OpenAPI specification (#1751)
Signed-off-by: Simon Pasquier <spasquie@redhat.com>
2019-02-20 15:36:19 +01:00
stuart nelson
51eebbef85
Stn/correctly mark api silences (#1733)
* Update alert status on every GET to alerts

Signed-off-by: stuart nelson <stuartnelson3@gmail.com>
2019-02-18 17:06:51 +01:00
beorn7
21de9ff88c Various improvements after code review
Most importantly, `api.New` now takes an `Options` struct as an
argument, which allows some other things done here as well:

- Timout and concurrency limit are now in the options, streamlining
  the registration and the implementation of the limiting middleware.

- A local registry is used for metrics, and the metrics used so far
  inside any of the api packages are using it now.

The 'in flight' metric now contains the 'get' as a method label. I
have also added a TODO to instrument other methods in the same way
(otherwise, the label doesn't reall make sense, semantically). I have
also added an explicit error counter for requests rejected because of
the concurrency limit. (They also show up as 503s in the generic HTTP
instrumentation (or they would, if v2 were instrumented, too), but
those 503s might have a number of reasons, while users might want to
alert on concurrency limit problems explicitly).

Signed-off-by: beorn7 <beorn@soundcloud.com>
2019-02-12 18:42:08 +01:00
beorn7
3382a0e949 Add HTTP instrumentation for GET requests in flight
While the newly added in-flight instrumentation works for all GET
requests, the existing HTTP instrumentation omits api/v2 calls. This
commit adds a TODO note about that.

Signed-off-by: beorn7 <beorn@soundcloud.com>
2019-02-11 19:34:06 +01:00
beorn7
4747fd9b2f Propagate timeout to alert listing via context
The context is created by the http.TimeoutHandler we use to set the
timeout.

I believe this is the only endpoint where propagating the timeout is
feasible and needed.

Signed-off-by: beorn7 <beorn@soundcloud.com>
2019-02-11 19:34:06 +01:00
beorn7
fc4b67ce80 Introduce a timeout and concurrency limit for HTTP requests
The default concurrency limit is max(GOMAXPROCS, 8). That should not
imply that each GET requests eats a whole CPU. It's more to get some
reasonable heuristics for the processing power of the hosting machine
(while allowing at least 8 concurrent requests even on the smallest
machines). As GET requests can easily overload the Alertmanager,
rendering it incapable of doing its main task, namely sending alert
notifications, we need to limit GET requests by default.

In contrast, no timeout is set by default. The http.TimeoutHandler
inovkes quite a bit of machinery behind the scenes, in particular an
additional layer of buffering. Thus, we should first get a bit of
experience with it before we consider enforcing a timeout by default,
even if setting a timeout is in general the safer setting for
resiliency.

Signed-off-by: beorn7 <beorn@soundcloud.com>
2019-02-11 19:34:06 +01:00
Max Leonard Inden
c57542127d
api: Combine v1 and v2 into generic api
Instead of cmd/alertmanager/main.go instantiating and starting both api
v1 and v2, delegate that work to a generic api combining the two.

Signed-off-by: Max Leonard Inden <IndenML@gmail.com>
2019-02-04 14:31:33 +01:00
Max Leonard Inden
8e157b3af5
api/v2: Make cluster status peers and name optional
If a users chooses to disable the Alertmanager cluster feature, there is
no cluster name nor cluster peers. Hence these should be optional. Only
cluster status is set to "disabled".

Signed-off-by: Max Leonard Inden <IndenML@gmail.com>
2019-02-04 11:40:30 +01:00
Max Leonard Inden
2f055d9966
api/v2: Do not populate cluster info if clustering is disabled
When users start Alertmanager with `--cluster.listen-address=`, the
cluster will not be initialized, hence api.peer will be `nil`. So far
this would result in a nil pointer dereference by the API v2 accessing
the api.peer field.

With this patch, api v2 skips populating the peers array, sets the name
to an empty string and the status to "disabled" in case `api.peer` is
nil.

Signed-off-by: Max Leonard Inden <IndenML@gmail.com>
2019-01-31 16:56:59 +01:00
Max Leonard Inden
7aa8ea9d9d
api/v2: Disable serving swagger spec and redoc UI
By default go-swagger serves the swagger spec and the redoc UI. This
patch disables both.

Signed-off-by: Max Leonard Inden <IndenML@gmail.com>
2019-01-17 16:19:29 +01:00
Simon Pasquier
b676fa79c0 *: update Makefile.common with new staticcheck (#1692)
Signed-off-by: Simon Pasquier <spasquie@redhat.com>
2019-01-04 15:37:33 +01:00