* Migrate from go-bindata to vfsgen
Signed-off-by: Simon Pasquier <spasquie@redhat.com>
* Ensure idempotent generation for vfsgen
Signed-off-by: Simon Pasquier <spasquie@redhat.com>
* asset: update generated files
Signed-off-by: Simon Pasquier <spasquie@redhat.com>
* Fix asset paths for Windows platforms
Signed-off-by: Simon Pasquier <spasquie@redhat.com>
* Regenerate assets
Signed-off-by: Simon Pasquier <spasquie@redhat.com>
* Add vfs wrapper that returns constant mod time
This is identical to what we had with go-bindata and avoids the extra
step of storing the identity of the complete file system in another
location.
Signed-off-by: Simon Pasquier <spasquie@redhat.com>
* Additional cleanup
Signed-off-by: Simon Pasquier <spasquie@redhat.com>
* Use a button instead of a for buttons
Using <a> was causing an unintended redirect to
the root. It appears this behavior has changed in
0.19.
Signed-off-by: stuart nelson <stuartnelson3@gmail.com>
* bindata
Signed-off-by: stuart nelson <stuartnelson3@gmail.com>
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>
Move the code for storing and GC'ing alerts from being re-implemented in
several packages to existing in its own package
Signed-off-by: stuart nelson <stuartnelson3@gmail.com>
Errcheck [1] enforces error handling accross all go files. Functions can
be excluded via `scripts/errcheck_excludes.txt`.
This patch adds errcheck to the `test` Make target.
[1] https://github.com/kisielk/errcheck
Signed-off-by: Max Leonard Inden <IndenML@gmail.com>
In moving from a plain string to url.URL, we
incorrectly were setting the query string via the
path. The `?` signaling the start of the query
string would then be escaped when the URL was
turned into a string.
Signed-off-by: Stuart Nelson <stuartnelson3@gmail.com>
... rather than in the Subscribe method. Currently the cleanup for a
given Alert subscription is done in a blocking goroutine, started in
the Subscribe method.
This simplifies it by moving the cleanup to the GC.
Additionally it simplifies the subscribe method by setting up the
buffered channel big enough to fill it up with all pending alerts
preventing the necessity to start a goroutine in Subscribe at all.
Signed-off-by: Sergiusz Urbaniak <sergiusz.urbaniak@gmail.com>
TestAlertsSubscribePutStarvation tests starvation of `iterator.Close` and
`alerts.Put`. Both `Subscribe` and `Put` use the Alerts.mtx lock. `Subscribe`
needs it to subscribe and more importantly unsubscribe `Alerts.listeners`.
`Put` uses the lock to add additional alerts and iterate the `Alerts.listeners`
map. If the channel of a listener is at its limit, `alerts.Lock` is blocked,
whereby a listener can not unsubscribe as the lock is hold by `alerts.Lock`.
Signed-off-by: Max Leonard Inden <IndenML@gmail.com>
This adds compatiblity with PagerDuty's Event rules feature, allowing resolve events to be routed based on attributes
Fixes#1440
Signed-off-by: Mike Bryant <m@ocado.com>
`honnef.co/go/tools/cmd/staticcheck` complains with
`config/config_test.go:260:32: regular expression does not contain any
meta characters (SA6004)`. Instead of using a RegEx this patch simply
switches to using Golangs `strings.Count` function.
Signed-off-by: Max Leonard Inden <IndenML@gmail.com>
* config: validate URLs at config load time
Signed-off-by: Simon Pasquier <spasquie@redhat.com>
* Address Brian and Lucas comments
Signed-off-by: Simon Pasquier <spasquie@redhat.com>
* Shallow copy of URL instead of reparsing it
Signed-off-by: Simon Pasquier <spasquie@redhat.com>
* Unshadow net/url package
Signed-off-by: Simon Pasquier <spasquie@redhat.com>
* Make a deep-copy of URL struct
Signed-off-by: Simon Pasquier <spasquie@redhat.com>
- `tmplText` and `tmplHTML` are using a monad-style error handling [1].
This reduces the verbosity of the error logic, but introduces the risk
of forgetting the final error check. This patch does not remove this
coding-style, but ensures proper error checking in the Email and
PagerDuty notifier.
- Ensure to handle errors returned by `multipartWriter.Close()` and
`wc.Write(buffer.Bytes())` in `Email.Notify()`.
[1] https://www.innoq.com/en/blog/golang-errors-monads/
Signed-off-by: Max Leonard Inden <IndenML@gmail.com>
* Add support for adding alerts using amtool
Signed-off-by: Bob Shannon <bshannon@palantir.com>
* comment: Simplify return in addAlert
Signed-off-by: Bob Shannon <bshannon@palantir.com>
Alertmanager is exiting with a non-zero exit code if the initial cluster
join fails. This behavior could be not wanted because:
- As Alertmanager is a critical component with an at-least-once
guarantee, failing on joining the cluster is unnecessary as
Alertmanager still functions by itself.
- In an environment like Kubernetes discovering peers via DNS, peers
might roll out one-by-one, leaving the DNS entries unpopulated for the
first peer of a set. Failing on initial join prevents a roll-out.
Instead of failing on the initial join this patch only logs the failure.
The cluster can be later joined via the `handleReconnect`.
This is a regression introduced in PR #1456 [1].
[1] https://github.com/prometheus/alertmanager/pull/1456
Signed-off-by: Max Leonard Inden <IndenML@gmail.com>
* fix concurrent read and wirte group
Signed-off-by: denghuan <denghuan@actionsky.com>
* make lock more elegant
Signed-off-by: denghuan <denghuan@actionsky.com>
* amtool: add support for stdin to check-config
Signed-off-by: Simon Pasquier <spasquie@redhat.com>
* Address Stuart's comment
Signed-off-by: Simon Pasquier <spasquie@redhat.com>
* cluster: make sure we don't miss the first pushPull
During the join, memberlist initiates a pushPull to get initial data.
Unfortunately, at this point the nflog and silence listener have not
been registered yet, so the first data arrives only after one pushPull
cycle (1min by default !).
Signed-off-by: Corentin Chary <c.chary@criteo.com>