This commit adds a unit test for the postSilencesHandler to
create and then update a silence. It shows that changing the
ID of an existing silence returns 404 Not Found, and removing
the ID of an existing silence re-creates that silence with
a different ID.
Signed-off-by: George Robinson <george.robinson@grafana.com>
* Rename matchers package to matcher singular
I realized that we had named the package plural "matchers" when
its idiomatic in Go to use singular package names.
---------
Signed-off-by: George Robinson <george.robinson@grafana.com>
This commit removes the Id from the method silences.Set(*pb.Silence)
as it is redundant. The Id is still set even when creating a silence
fails. This will be fixed in a later change.
Signed-off-by: George Robinson <george.robinson@grafana.com>
* 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>
This commit fixes inconsistent UTF-8 behavior if the compat package is
not initialized and feature flags are not passed to the API. This can
happen when Alertmanager is used as a package in software such
as Cortex or Mimir.
The inconsistent behavior is that Alertmanager will accept UTF-8 alerts
but reject UTF-8 configurations.
Since feature flags are optional via api.Options, we cannot force them
to be passed to api.New at compile time. Instead, it's better to defer
back to the compat package which is consistent even when not initialized.
Signed-off-by: George Robinson <george.robinson@grafana.com>
* Add metrics to matchers compat package
This commit adds the following metrics to the compat package:
alertmanager_matchers_parse
alertmanager_matchers_disagree
alertmanager_matchers_incompatible
alertmanager_matchers_invalid
With a label called origin to differentiate the different sources
of inputs: the configuration file, the API, and amtool.
The disagree_total metric is incremented when an input is invalid
in both parsers, but results in different parsed representations,
then there is disagreement. This should not happen, and suggests
their is either a bug in one of the parsers or a mistake in the
backwards compatible guarantees of the matchers/parse parser.
The incompatible_total metric is incremented when an input is valid
in pkg/labels, but not the UTF-8 parser in matchers/parse. In such
case, the matcher should be updated to be compatible. This often
means adding double quotes around the right hand side of the matcher.
For example, foo="bar".
The invalid_total metric is incremented when an input is invalid
in both parsers. This was never a valid input.
The tests have been updated to check the metrics are incremented
as expected.
Signed-off-by: George Robinson <george.robinson@grafana.com>
---------
Signed-off-by: George Robinson <george.robinson@grafana.com>
* 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>
There's no change to the logic here - it just stroke me as odd that we were reusing the response from alerting groups in the silences call when it's pretty simple to add a new one in the API description.
This is more accurate as well, as this will be used to power the documentation.
Signed-off-by: gotjosh <josue.abreu@gmail.com>
Bumps the API spec/client generation util of `go-swagger` from 0.30.2 to 0.30.5 which is the latest stable.
Signed-off-by: gotjosh <josue.abreu@gmail.com>
* fix: change receiver pointer to value and add test
Signed-off-by: François Gouteroux <francois.gouteroux@gmail.com>
---------
Signed-off-by: François Gouteroux <francois.gouteroux@gmail.com>
* 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>
* Reduce memory utilization in downstream projects creating multiple Alertmanager instances
* Wrap the error instead of citing it
Signed-off-by: Marco Pracucci <marco@pracucci.com>
This is a of a nitpicky change, but having error logs on bad requests
is a bit of a pain. This means that a bad client can spam the logs with
bad requests that are really not actually an issue for the server -
we just send back the error and move on. This commit moves a couple of logs
from `Error` to `Debug` so that they can be filtered a bit better
Signed-off-by: sinkingpoint <colin@quirl.co.nz>
As part of #2971, I'm about to extend the test for silences - extract the functions into helpers as part of a separate file and add names to the expectations so that we can easily identify them.
Signed-off-by: gotjosh <josue.abreu@gmail.com>
* API: Make conversion functions public
All types are public so it makes sense to make these functions also
public for ease of downstream consumption.
Signed-off-by: gotjosh <josue@grafana.com>
* Add the license header to the new file
Signed-off-by: gotjosh <josue@grafana.com>
* Fix tests
Signed-off-by: gotjosh <josue@grafana.com>
* Make two more helper functions public
Signed-off-by: gotjosh <josue@grafana.com>
A Peer as defined by the `cluster` package represents the node in the
cluster. It is used in other packages to know the status of all of the
members or how long should we wait to know if a notification has already fired.
In Cortex, we'd like to implement a slightly different way of
clustering (using gRPC for communication and a
hash ring for node discovery).
This is a small change to support that by changing the consumer of other
packages to an interface.
Silences and Notification channels don't need an interface as they take
a `func([]byte) error` as a parameter.
Signed-off-by: gotjosh <josue@grafana.com>
* 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>
* 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>
* 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>