Repository navigation
docs: Guide on how to setup UTF-8 mode in Cortex #7439
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
RaphSku
wants to merge
5
commits into
cortexproject:master
Choose a base branch
from
RaphSku:docs/utf8-support-guide
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d561d5c
Guide on how to setup UTF-8 mode on Cortex
RaphSku 308fad2
Added ruler and alertmanager as affected components
RaphSku e45f856
Added a Using UTF-8 section to demonstrate a few examples on how to u…
RaphSku 80309fb
Punctuation fix
RaphSku c4791e0
Fix errors and inaccurate/wrong statements.
RaphSku File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,158 @@ | ||
| --- | ||
| title: "UTF-8 support" | ||
| linkTitle: "UTF-8 support" | ||
| weight: 70 | ||
| slug: utf8-support | ||
| --- | ||
|
|
||
| # UTF-8 support | ||
|
|
||
| ## Why enable UTF-8 support? | ||
|
|
||
| There are a number of reasons why UTF-8 support in Cortex is useful: | ||
|
|
||
| 1. With Prometheus version [3.0](https://prometheus.io/docs/guides/utf8/) UTF-8 support has been released for metric and label names. Thus, UTF-8 support improves the interoperability between Cortex and modern Prometheus ecosystems. | ||
| 2. It makes Cortex more flexible for internationalized or externally sourced metadata which is useful when metrics or labels originate from systems, teams, or domains that do not fit neatly into ASCII-only naming. | ||
| 3. It keeps behavior consistent across ingestion, rules and alerting. | ||
|
|
||
| ## Before you enable UTF-8 support | ||
|
|
||
| Although UTF-8 support increases flexibility, the traditional naming style remains the safest choice for broad ecosystem compatibility, because downstream tools might assume legacy-compatible names. Check the compatibility of these tools before enabling UTF-8 support. | ||
|
|
||
| Before enabling UTF-8 support, review the systems that write metrics to Cortex, the rules evaluated by the Ruler, and the alerting configuration used by Alertmanager. | ||
|
|
||
| Enabling UTF-8 support changes validation behavior. Roll it out in a staging environment first and verify that ingestion, rule evaluation, and alert routing continue to work as expected. | ||
|
|
||
| ## Configure UTF-8 support | ||
|
|
||
| Cortex supports configuring how metric names and label names are validated through the `-name-validation-scheme` flag or `name_validation_scheme` in the YAML configuration file. | ||
|
|
||
| Supported values are: | ||
|
|
||
| - `legacy` (default) | ||
| - `utf8` | ||
|
|
||
| UTF-8 name validation was introduced in Cortex [v1.20.0](https://github.com/cortexproject/cortex/releases/tag/v1.20.0). | ||
|
|
||
| This guide explains how to enable UTF-8 support and how the selected validation scheme affects the Cortex components. | ||
|
|
||
| To enable UTF-8 validation, set the validation scheme to `utf8`. | ||
|
|
||
| CLI: | ||
|
|
||
| ```text | ||
| -name-validation-scheme=utf8 | ||
| ``` | ||
|
|
||
| YAML: | ||
|
|
||
| ```yaml | ||
| name_validation_scheme: utf8 | ||
| ``` | ||
|
|
||
| ## Using UTF-8 | ||
|
|
||
| After enabling UTF-8 name validation, UTF-8 metric names and label names can be used. The following examples illustrate how to work with those names. | ||
|
|
||
| ### Querying | ||
|
|
||
| PromQL queries support UTF-8 metric names and label names. For example, a UTF-8 metric name can be queried with the following expression: | ||
|
|
||
| ```promql | ||
| {"series.1", "test.utf8.metric"="😄"} | ||
| ``` | ||
|
|
||
| Note that the metric name `series.1` is not valid under the `legacy` validation scheme. It is accepted only when UTF-8 validation is enabled. This is useful when metric or label names contain characters, such as `.`, that are supported by UTF-8 validation but not by the legacy validation scheme. | ||
|
|
||
| ### Alertmanager | ||
|
|
||
| Alertmanager configuration can use UTF-8 names in matchers, `group_by` fields, and silence matchers. For example, a route can group and match on UTF-8 label names: | ||
|
|
||
| ```yaml | ||
| route: | ||
| receiver: default | ||
| group_by: | ||
| - "group.test.🙂" | ||
| routes: | ||
| - receiver: utf8-receiver | ||
| matchers: | ||
| - '"🙂.utf8.label"="😄"' | ||
|
|
||
| receivers: | ||
| - name: default | ||
| - name: utf8-receiver | ||
| ``` | ||
|
|
||
| Silences can also match alerts using UTF-8 label names and values. For example, a silence can contain the following matcher: | ||
|
|
||
| ```json | ||
| { | ||
| "matchers": [ | ||
| { | ||
| "name": "🙂.utf8.label", | ||
| "value": "😄", | ||
| "isRegex": false, | ||
| "isEqual": true | ||
| } | ||
| ] | ||
| } | ||
| ``` | ||
|
|
||
| This is a partial silence object. Creating a silence through the API additionally requires `startsAt`, `endsAt`, `createdBy`, and `comment`. | ||
|
|
||
| Together, these capabilities support routing, grouping, and silencing alerts that contain UTF-8 label names and values. | ||
|
|
||
| ### Ruler | ||
|
|
||
| Ruler rule definitions can use UTF-8 names in rule names, rule labels and rule group labels. For example: | ||
|
|
||
| ```yaml | ||
| groups: | ||
| - name: "test.utf8.group" | ||
| labels: | ||
| "test.utf8.group.label": "😄" | ||
| rules: | ||
| - record: "test.utf8.recording.rule" | ||
| expr: up | ||
| labels: | ||
| "test.utf8.rule.label": "😄" | ||
| - alert: "test.utf8.alert" | ||
| expr: up == 0 | ||
| labels: | ||
| "test.utf8.alert.label": "😄" | ||
| ``` | ||
|
|
||
| ## Impact on Cortex components | ||
|
|
||
| ### Distributor | ||
|
|
||
| The [Distributor](https://cortexmetrics.io/docs/architecture/#distributor) validates incoming metric names and label names during ingestion. | ||
|
|
||
| When `name_validation_scheme` is set to `legacy`, Cortex applies the legacy validation behavior. When it is set to `utf8`, the Distributor accepts names that are valid under the UTF-8 scheme. | ||
|
|
||
| In practice, this means that enabling UTF-8 support can change whether samples or series are accepted during ingestion by the Distributor. With legacy validation, samples containing invalid metric or label names are rejected during validation. With UTF-8 validation enabled, names that are valid under the UTF-8 scheme can pass validation. Writers that send UTF-8 metric or label names require the Distributor to run with `utf8` validation enabled. | ||
|
|
||
| ### Ruler | ||
|
|
||
| The [Ruler](https://cortexmetrics.io/docs/architecture/#ruler) uses the selected scheme when validating rule definitions and external label names. With `utf8`, rule and external-label names that are valid under the UTF-8 scheme can be used. | ||
|
|
||
| ### Alertmanager | ||
|
|
||
| The [Alertmanager](https://cortexmetrics.io/docs/architecture/#alertmanager) uses the selected scheme directly when choosing how to parse matchers. Cortex maps `legacy` to Alertmanager's `classic-mode` and `utf8` to `utf8-strict-mode` during Alertmanager initialization. This affects parsing of matchers in Alertmanager configurations and validation of label names in fields such as `group_by`. | ||
|
|
||
| In UTF-8 strict mode, there is **no fallback to classic matcher parsing**. Existing Alertmanager configurations should be checked for strict-mode compatibility before enabling `utf8`, even if they do not use non-legacy label names. | ||
|
|
||
| ## Recommended rollout strategy | ||
|
|
||
| 1. Inventory metric producers and consumers, Ruler rules, external labels, and Alertmanager configurations. Check whether any tools assume legacy metric and label names. | ||
| 2. Verify that existing Alertmanager route matchers parse in UTF-8 strict mode. Update ambiguous or incompatible matchers before switching modes. | ||
| 3. Enable `utf8` in a staging environment. Ingest and query representative metrics with non-legacy names, and exercise label name, label value, and series API endpoints. | ||
| 4. Load representative recording and alerting rules, including group and rule labels, and verify evaluation and notifications. | ||
| 5. Test Alertmanager configuration loading, grouping, routing, and silence creation. Roll out consistently across the Cortex components that need the selected mode. | ||
|
|
||
| ## Compatibility notes | ||
|
|
||
| - Use `legacy` if you need to preserve the previous validation behavior. | ||
| - Use `utf8` if you want Cortex to accept UTF-8 metric names and label names. | ||
| - Plan migration carefully when different systems in your environment assume different naming rules. | ||
| - Refer to the [configuration reference](https://cortexmetrics.io/docs/configuration/configuration-file/#supported-contents-and-default-values-of-the-config-file) for the current flag and supported values. | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thing that might be worth covering: what happens when switching back from
utf8tolegacy.group_bylabel names fail to load inclassic-mode, and alerts with UTF-8 label names are rejected.ruler_external_labelsandmetric_relabel_configswith UTF-8 label names fail limits validation: in the default limits Cortex refuses to start, and in per-tenant overrides the runtime config file is rejected.Before switching back from
utf8tolegacy, remove or rename UTF-8 metric and label names from Ruler rule groups,ruler_external_labels,metric_relabel_configs, and Alertmanager configurations.Could you add a short "Rolling back to legacy" section with this after the rollout steps?