Commit Graph

19 Commits

Author SHA1 Message Date
George Robinson 44d5f70c3b
Fix a small number of inconsistencies in compat package logging (#3718)
This commit fixes a small number of inconsistencies in the compat
package logging. It now has consistent use of classic matchers
parser and UTF-8 matchers parser, instead of old matchers parser
and new matchers parser.

Signed-off-by: George Robinson <george.robinson@grafana.com>
2024-02-13 11:37:42 +00:00
George Robinson f69a508665
Remove metrics from compat package (#3714)
This commit removes the metrics from the compat package
in favour of the existing logging and the additional tools
at hand, such as amtool, to validate Alertmanager configurations.

Due to the global nature of the compat package, a consequence
of config.Load, these metrics have proven to be less useful
in practice than expected, both in Alertmanager and other projects
such as Mimir.

There are a number of reasons for this:

1. Because the compat package is global, these metrics cannot be
   reset each time config.Load is called, as in multi-tenant
   projects like Mimir loading a config for one tenant would reset
   the metrics for all tenants. This is also the reason the metrics
   are counters and not gauges.

2. Since the metrics are counters, it is difficult to create
   meaningful dashboards for Alertmanager as, unlike in Mimir,
   configurations are not reloaded at fixed intervals, and as such,
   operators cannot use rate to track configuration changes
   over time.

In Alertmanager, there are much better tools available to validate
that an Alertmanager configuration is compatible with the UTF-8
parser, including both the existing logging from Alertmanager
server and amtool check-config.

In other projects like Mimir, we can track configurations for
individual tenants using log aggregation and storage systems
such as Loki. This gives operators far more information than
what is possible with the metrics, including the timestamp,
input and ID of tenant configurations that are incompatible
or have disagreement.

Signed-off-by: George Robinson <george.robinson@grafana.com>
2024-02-08 09:59:03 +00:00
George Robinson cab8ecbc95
Change compat metrics to counters (#3686)
This commit changes the metrics in the compat package from gauges
to counters. The reason for this is that in some cases the gauge
should behave like a gauge (i.e. loading configurations) but in
other cases should behave like a counter (i.e. HTTP requests).

Second, because the compat package is a global package
(due to how config.Load works), in tenanted systems like Cortex
and Mimir it was non-trivial to reset the gauges per tenant
each time their configuration was reloaded.

Instead, it's easier to compute the rate of increase as 0 instead
of check that the gauge is 0 to know if UTF-8 strict mode can be
enabled.

Signed-off-by: George Robinson <george.robinson@grafana.com>
2024-01-30 10:22:00 +00:00
George Robinson c97b7f1b27
Fix nil error in warn logs about incompatible matchers (#3683)
This commit fixes a small bug in the warning logs for incompatible
matchers where the error from the UTF-8 parser was logged as nil.

Signed-off-by: George Robinson <george.robinson@grafana.com>
2024-01-29 18:04:52 +00:00
George Robinson 0483a6ad0f Fix missing check for len(name) == 0
Signed-off-by: George Robinson <george.robinson@grafana.com>
2024-01-15 19:46:52 +00:00
George Robinson 378933649c
Add origin to logs in compat (#3662)
Signed-off-by: George Robinson <george.robinson@grafana.com>
2024-01-05 11:13:09 +00:00
George Robinson 848e2191d9
Support UTF-8 label matchers: Add metrics to matchers compat package (#3658)
* 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>
2024-01-05 10:21:20 +00:00
George Robinson e772920993
Support UTF-8 label matchers: Make functions in compat package public (#3659)
* Make functions in compat package public

This commit makes functions in the compat package public. These
functions are useful for software that builds on top of the
Alertmanager that also need to migrate from classic mode to UTF-8.

Signed-off-by: George Robinson <george.robinson@grafana.com>

* Fix lint

Signed-off-by: George Robinson <george.robinson@grafana.com>

---------

Signed-off-by: George Robinson <george.robinson@grafana.com>
2024-01-04 17:42:58 +00:00
Matthieu MOREL b9e347b9d1 golangci-lint: enable testifylint linter
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2023-12-10 08:50:03 +00:00
Matthieu MOREL b81bad8711 use Go standard errors
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2023-12-08 16:44:13 +01:00
George Robinson 4494abfce4
Fix UTF-8 not supported in group_by (#3619)
* Fix UTF-8 not supported in group_by

This commit fixes missing UTF-8 support in the group_by for routes.

Signed-off-by: George Robinson <george.robinson@grafana.com>
---------

Signed-off-by: George Robinson <george.robinson@grafana.com>
2023-11-24 11:26:39 +00:00
George Robinson 70bd5dad98
Support UTF-8 label matchers: Use compat package in Alertmanager server (#3567)
* 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>
2023-11-24 10:01:40 +00:00
George Robinson ca5089d33e
Support UTF-8 label matchers: Rename feature flags and make package public (#3604)
* Rename feature flags and make package public

This commit renames the feature flags "classic-matchers-parsing"
and "utf8-matchers-parsing" to "classic-matchers" and "utf8-matchers".
This better represents their use, for example, when validating
both alerts and silences created via the API.

It also makes the feature flags package public for two reasons:

1. AllowedFlags is a public variable
2. We would rather use these consts in Mimir then have to hardcode
   the strings ourselves, and be subject to breaking changes in future

Signed-off-by: George Robinson <george.robinson@grafana.com>
---------

Signed-off-by: George Robinson <george.robinson@grafana.com>
2023-11-17 20:07:54 +00:00
George Robinson f96ba1b58f
unquote should check for invalid UTF-8 code points (#3595)
Quoted tokens can contain both UTF-8 byte and code point literals
that should be interpreted when quoted. However, we need to check
that the interpreted literals are valid UTF-8 code points or not.
This now happens in unquote.

Signed-off-by: George Robinson <george.robinson@grafana.com>
2023-11-13 16:31:15 +00:00
George Robinson 7cdecbf6ee
Remove braces from suggestion (#3568)
This commit removes the open and close braces from the suggestion
as braces do not make sense in the configuration file. This does
not change the behavior of the suggestion whatsoever as these
are optional.

Signed-off-by: George Robinson <george.robinson@grafana.com>
2023-10-30 14:30:19 +00:00
George Robinson b5b5a1df3d
Support UTF-8 label matchers: Do not allow unquoted escape sequences (#3571)
* Do not allow unquoted escape sequences

This commit updates the matchers parser to reject unquoted
openmetrics escape sequences. As an example, foo=bar\n
will no longer parse, and must instead be written as
foo="bar\n". This avoids an issue where the input is valid
in both the matchers and classic parsers, but results
in two different parsings.

---------

Signed-off-by: George Robinson <george.robinson@grafana.com>
2023-10-30 13:56:54 +00:00
George Robinson 8512285e54
Support UTF-8 label matchers: Update compliance tests (#3569)
* Update compliance tests

This commit updates compliance tests to include openmetrics
escape sequences that are not valid in the UTF-8 matchers parser.

Signed-off-by: George Robinson <george.robinson@grafana.com>

* Add tests for openmetrics escape sequences

Signed-off-by: George Robinson <george.robinson@grafana.com>

---------

Signed-off-by: George Robinson <george.robinson@grafana.com>
2023-10-25 09:52:17 +01:00
George Robinson 16aa996c4f
Support UTF-8 label matchers: Add compat package with feature flag and use in amtool (#3483)
* Add adapter package for parser feature flag

This commit adds the compat package allowing 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>
2023-10-19 12:00:01 +01:00
George Robinson 353c0a1304
Support UTF-8 label matchers: Add new parser (#3453)
* Add label matchers parser

This commit adds the new label matchers parser as proposed in #3353.
Included is a number of compliance tests comparing the grammar
supported in the new parser with the existing parser in pkg/labels.

Signed-off-by: George Robinson <george.robinson@grafana.com>
---------

Signed-off-by: George Robinson <george.robinson@grafana.com>
2023-09-05 11:32:58 +01:00