Commit Graph

108 Commits

Author SHA1 Message Date
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
Simon Pasquier 9a116736ef api/v2: Add CORS support (#1667)
Signed-off-by: Simon Pasquier <spasquie@redhat.com>
2018-12-16 14:05:34 +01:00
Max Leonard Inden 2b697aaa6b
api/v2: Extract shared properties of gettable and postable alert
With issue 1465 on openapi-generator [1] being fixed, we can not extract
shared properties of the gettable and postable alert definition into a
shared object (`alert`) like we do for silence, gettable silence and
postable silence.

In addition this patch does the following changes to the UI:

- Use `List GettableAlert` instead of plural type definition like
`GettableAlerts` because the plural definitions are not generated.

- Fix openapi-generator-cli docker image to specific hash.

[1] https://github.com/OpenAPITools/openapi-generator/issues/1465

Signed-off-by: Max Leonard Inden <IndenML@gmail.com>
2018-11-28 14:35:39 +01:00
Max Leonard Inden f504f953c1
ui: Move /alerts to API v2
Signed-off-by: Max Leonard Inden <IndenML@gmail.com>
2018-11-23 12:53:48 +01:00
Max Leonard Inden b4b8b750df
api/v2/openapi.yaml: Differentiate between post and get silence
Instead of having one general silence, differentiate between postable
and gettable silence, hence making more fields required.

Signed-off-by: Max Leonard Inden <IndenML@gmail.com>
2018-11-15 16:21:07 +01:00
Max Leonard Inden e4e053b18e
ui: Move /status & /silences to API v2
This patch makes the Alertmanager UI (/status & /silences) use the
api/v2 endpoint. In addition it adds logic to generate the elm side data
model based on the OpenAPI specification.

Signed-off-by: Max Leonard Inden <IndenML@gmail.com>
2018-11-15 13:24:26 +01:00
Max Leonard Inden f1b920bcc9
api: Implement OpenAPI generated Alertmanager API V2
The current Alertmanager API v1 is undocumented and written by hand.
This patch introduces a new Alertmanager API - v2. The API is fully
generated via an OpenAPI 2.0 [1] specification (see
`api/v2/openapi.yaml`) with the exception of the http handlers itself.

Pros:
- Generated server code
- Ability to generate clients in all major languages
  (Go, Java, JS, Python, Ruby, Haskell, *elm* [3] ...)
    - Strict contract (OpenAPI spec) between server and clients.
    - Instant feedback on frontend-breaking changes, due to strictly
      typed frontend language elm.
- Generated documentation (See Alertmanager online Swagger UI [4])

Cons:
- Dependency on open api ecosystem including go-swagger [2]

In addition this patch includes the following changes.

- README.md: Add API section

- test: Duplicate acceptance test to API v1 & API v2 version

  The Alertmanager acceptance test framework has a decent test coverage
  on the Alertmanager API. Introducing the Alertmanager API v2 does not go
  hand in hand with deprecating API v1. They should live alongside each
  other for a couple of minor Alertmanager versions.

  Instead of porting the acceptance test framework to use the new API v2,
  this patch duplicates the acceptance tests, one using the API v1, the
  other API v2.

  Once API v1 is removed we can simply remove `test/with_api_v1` and bring
  `test/with_api_v2` to `test/`.

[1]
https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md

[2] https://github.com/go-swagger/go-swagger/

[3] https://github.com/ahultgren/swagger-elm

[4]
http://petstore.swagger.io/?url=https://raw.githubusercontent.com/mxinden/alertmanager/apiv2/api/v2/openapi.yaml

Signed-off-by: Max Leonard Inden <IndenML@gmail.com>
2018-09-04 13:38:34 +02:00
Max Inden b1a8fdd169
Merge pull request #1521 from mxinden/errcheck
*.go: Introduce errcheck enforcing error handling
2018-08-30 17:53:49 +02:00