This change adds a inhibition cache. New alerts are checked against all
inhibition rules' source matchers. At notification time, we only have to
check the target matchers against the notified alerts. If there are
alerts in the source cache, we only have to verify the equal labels
against these.
Tests for:
- inheriting a receiver from the default route
- overriding the receiver when the parent route has not set one
- inheriting a receiver from a parent route that's not the default
Adds a route which matches on a `group_by` label which inherits the
default receiver and also has a child route, matching on an `env` label,
which overrides the receiver.
To be sure of edge case behaviour, we test inheriting the receiver from
a child route. Hopefully no one would actually implement this edge case
in reality as it's overly complex but we test anyway to be sure that it
doesn't trigger unexpected behaviour.
This is useful when you're using a label to determine the receiver but
want to override other options such as `group_by`. Currently you'd have
to duplicate the matchers for the receivers to be able to do this.
`checkReceiver()` now returns no error if a receiver is empty and we add
a check to ensure that the root route has a receiver defined. I've added
a test for this.
This brings the `receiver` option into line with the other options
(`group_by`, `group_wait`, etc) in the sense that routes can now inherit
the receiver from the parent node.
From https://prometheus.io/docs/alerting/configuration/:
> A route block defines a node in a routing tree and its children. Its
> optional configuration parameters are inherited from its parent node
> if not set.
Previously, the tests would listen on all available interfaces.
Instead, have the tests use localhost only; using all available
interfaces is unnecessary.
On Mac OS X with the builtin firewall enabled, it triggers annoying
prompts to allow the tests to listen on all interfaces.
Depending on the environment the timestamp internal fields
are different to handle timezones.
Thus a reflect.DeepEqual comparison falsely evaluates to
false.
This commit manually compares timestamps via the time.Time.Equal
method to circumvent the issue.