Documentation: clarify label matching (#55650)

* Documentation: clarify label matching

Behaviour in case of multiple matchers is not documented, but my experiments show they are reduced using logical AND. Please validate the updated description.

* Accept wording suggestion

Co-authored-by: brendamuir <100768211+brendamuir@users.noreply.github.com>

* Accept suggestion for docs/sources/alerting/fundamentals/annotation-label/labels-and-label-matchers.md

Co-authored-by: brendamuir <100768211+brendamuir@users.noreply.github.com>

* Improve wording according to review suggestions

Co-authored-by: brendamuir <100768211+brendamuir@users.noreply.github.com>
This commit is contained in:
Vladimir 2022-09-28 01:06:04 -07:00 committed by GitHub
parent 51028b1b2e
commit efef672d19
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -30,15 +30,18 @@ A label matchers consists of 3 distinct parts, the **label**, the **value** and
| `=~` | Select labels that regex-match the value. |
| `!~` | Select labels that do not regex-match the value. |
## Example of a label matcher
If you are using multiple label matchers, they are combined using the AND logical operator. This means that all matchers must match in order to link a rule to a policy.
Imagine we've defined the following set of labels for our alert.
## Example scenario
If you define the following set of labels for your alert:
`{ foo=bar, baz=qux, id=12 }`
In this situation,
then:
- A label matcher defined as `foo=bar` will match this alert rule.
- A label matcher defined as `foo!=bar` will _not_ match this alert rule.
- A label matcher defined as `id=~[0-9]+` will match this alert rule.
- A label matcher defined as `baz!~[0-9]+` will match this alert rule.
- A label matcher defined as `foo=bar` matches this alert rule.
- A label matcher defined as `foo!=bar` does _not_ match this alert rule.
- A label matcher defined as `id=~[0-9]+` matches this alert rule.
- A label matcher defined as `baz!~[0-9]+` matches this alert rule.
- Two label matchers defined as `foo=bar` and `id=~[0-9]+` match this alert rule.