Skip to content

Commit 65a6ca0

Browse files
authored
feat(om2.0): Add UTF-8 metric names and labels (#2746)
Part of prometheus/prometheus#16093 Signed-off-by: Owen Williams <[email protected]>
1 parent 2530b2c commit 65a6ca0

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

docs/specs/om/open_metrics_spec_2_0.md

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ Strings MUST only consist of valid UTF-8 characters and MAY be zero length. NULL
9292

9393
Labels are key-value pairs consisting of strings.
9494

95-
Label names beginning with underscores are RESERVED and MUST NOT be used unless specified by this standard. Label names MUST follow the restrictions in the ABNF section.
95+
Label names beginning with two underscores are RESERVED and MUST NOT be used unless specified by this standard. Label names SHOULD follow the restrictions in the ABNF section under the `label-name` section. Label names MAY be any quoted escaped UTF-8 string as described in the ABNF section. Be aware that exposing UTF-8 metrics is still experimental and may reduce usability.
9696

9797
Empty label values SHOULD be treated as if the label was not present.
9898

@@ -128,7 +128,7 @@ A MetricFamily MAY have zero or more Metrics. A MetricFamily MUST have a name, H
128128

129129
##### Name
130130

131-
MetricFamily names are a string and MUST be unique within a MetricSet. Names SHOULD be in snake_case. Metric names MUST follow the restrictions in the ABNF section.
131+
MetricFamily names are a string and MUST be unique within a MetricSet. Names SHOULD be in snake_case. Names SHOULD follow the restrictions in the ABNF section under `metricname`. Metric names MAY be any quoted and escaped UTF-8 string as described in the ABNF section. Be aware that exposing UTF-8 metrics is still experimental and may reduce usability, especially when suffixes are not included.
132132

133133
Colons in MetricFamily names are RESERVED to signal that the MetricFamily is the result of a calculation or aggregation of a general purpose monitoring system.
134134

@@ -329,22 +329,24 @@ metricset = *metricfamily
329329
330330
metricfamily = *metric-descriptor *metric
331331
332-
metric-descriptor = HASH SP type SP metricname SP metric-type LF
333-
metric-descriptor =/ HASH SP help SP metricname SP escaped-string LF
334-
metric-descriptor =/ HASH SP unit SP metricname SP *metricname-char LF
332+
metric-descriptor = HASH SP type SP (metricname / metricname-utf8) SP metric-type LF
333+
metric-descriptor =/ HASH SP help SP (metricname / metricname-utf8) SP escaped-string LF
334+
metric-descriptor =/ HASH SP unit SP (metricname / metricname-utf8) SP *metricname-char LF
335335
336336
metric = *sample
337337
338338
metric-type = counter / gauge / histogram / gaugehistogram / stateset
339339
metric-type =/ info / summary / unknown
340340
341-
sample = metricname [labels] SP number [SP timestamp] [SP created] [exemplar] LF
341+
sample = metricname-and-labels SP number [SP timestamp] [SP created] [exemplar] LF
342342
343-
exemplar = SP HASH SP labels SP number [SP timestamp]
343+
exemplar = SP HASH SP labels-in-braces SP number [SP timestamp]
344344
345-
labels = "{" [label *(COMMA label)] "}"
345+
metricname-and-labels = metricname [labels-in-braces] / name-and-labels-in-braces
346+
labels-in-braces = "{" [label *(COMMA label)] "}"
347+
name-and-labels-in-braces = "{" metricname-utf8 *(COMMA label) "}"
346348
347-
label = label-name EQ DQUOTE escaped-string DQUOTE
349+
label = label-key EQ DQUOTE escaped-string DQUOTE
348350
349351
number = realnumber
350352
; Case insensitive
@@ -386,13 +388,16 @@ metricname = metricname-initial-char 0*metricname-char
386388
387389
metricname-char = metricname-initial-char / DIGIT
388390
metricname-initial-char = ALPHA / "_" / ":"
391+
metricname-utf8 = DQUOTE escaped-string-non-empty DQUOTE
389392
393+
label-key = label-name / DQUOTE escaped-string-non-empty DQUOTE
390394
label-name = label-name-initial-char *label-name-char
391395
392396
label-name-char = label-name-initial-char / DIGIT
393397
label-name-initial-char = ALPHA / "_"
394398
395399
escaped-string = *escaped-char
400+
escaped-string-non-empty = 1*escaped-char
396401
397402
escaped-char = normal-char
398403
escaped-char =/ BS ("n" / DQUOTE / BS)
@@ -448,6 +453,8 @@ A double backslash SHOULD be used to represent a backslash character.
448453
A single backslash SHOULD NOT be used for undefined escape sequences.
449454
As an example, `\\\\a` is equivalent and preferable to `\\a`.
450455

456+
Escaping MUST also be applied to quoted UTF-8 strings.
457+
451458
##### Numbers
452459

453460
Integer numbers MUST NOT have a decimal point. Examples are `23`, `0042`, and `1341298465647914`.
@@ -751,7 +758,7 @@ Metric labels and MetricPoint value labels MAY be in any order.
751758

752759
##### Summary
753760

754-
If present, the MetricPoint's Sum Value Sample MetricName MUST have the suffix `_sum`. If present, the MetricPoint's Count Value MetricName MUST have the suffix `_count`. If present, the MetricPoint's Quantile Values MUST specify the quantile measured using a label with a label name of "quantile" and with a label value of the quantile measured.
761+
If present, the MetricPoint's Sum Value Sample MetricName MUST have the suffix `_sum`. If present, the MetricPoint's Count Value MetricName MUST have the suffix `_count`. If present, the MetricPoint's Quantile Values MUST specify the quantile measured using a label with a label name of "quantile" and with a label value of the quantile measured.
755762

756763
If present the MetricPoint's Created Timestamp MUST be inlined with the Metric point with a `ct@` prefix. If the value's timestamp is present, the Created Timestamp MUST be added right after it. If exemplar is present, the Created Timestamp MUST be added before it. Created Timestamp MUST be appended to all Quantile Values, to the MetricPoint's Sum and MetricPoint's Count.
757764

@@ -775,7 +782,7 @@ Quantiles MAY be in any order.
775782

776783
##### Histogram
777784

778-
The MetricPoint's Bucket Values Sample MetricNames MUST have the suffix `_bucket`. If present, the MetricPoint's Sum Value Sample MetricName MUST have the suffix `_sum`.
785+
The MetricPoint's Bucket Values Sample MetricNames MUST have the suffix `_bucket`. If present, the MetricPoint's Sum Value Sample MetricName MUST have the suffix `_sum`.
779786

780787
If present the MetricPoint's Created Timestamp MUST be inlined with the Metric point with a `ct@` prefix. If the value's timestamp is present, the Created Timestamp MUST be added right after it. If exemplar is present, the Created Timestamp MUST be added before it. Created Timestamp MUST be appended to all Bucket Values, to the MetricPoint's Sum and MetricPoint's Count.
781788

@@ -980,7 +987,7 @@ For high availability and ad-hoc access a common approach is to have multiple in
980987
# EDITOR’S NOTE: This section might be good for a BCP paper.
981988
-->
982989

983-
We aim for a balance between understandability, avoiding clashes, and succinctness in the naming of metrics and label names. Names are separated through underscores, so metric names end up being in “snake_case”.
990+
We aim for a balance between understandability, avoiding clashes, and succinctness in the naming of metrics and label names. Names are separated through underscores, so metric names end up being in “snake_case”. While we strongly recommend the practices recommended in this document, other metric systems have different philosophies regarding naming conventions. OpenMetrics allows these metrics to be exposed, but without the conventions and suffixes recommended here there is an increased risk of collisions and incompatibilities along the chain of services in a metrics system. Users wishing to use alternative conventions will need to take special care and expend additional effort to ensure that the entire system is consistent.
984991

985992
To take an example "http_request_seconds" is succinct but would clash between large numbers of applications, and it's also unclear exactly what this metric is measuring. For example, it might be before or after auth middleware in a complex system.
986993

@@ -1020,7 +1027,7 @@ While there is metadata about metric names such as HELP, TYPE and UNIT there is
10201027

10211028
### Metric Names versus Labels
10221029

1023-
There are situations in which both using multiple Metrics within a MetricFamily or multiple MetricFamilies seem to make sense. Summing or averaging aMetricFamily should be meaningful even if it's not always useful. For example, mixing voltage and fan speed is not meaningful.
1030+
There are situations in which both using multiple Metrics within a MetricFamily or multiple MetricFamilies seem to make sense. Summing or averaging a MetricFamily should be meaningful even if it's not always useful. For example, mixing voltage and fan speed is not meaningful.
10241031

10251032
As a reminder, OpenMetrics is built with the assumption that ingestors can process and perform aggregations on data.
10261033

0 commit comments

Comments
 (0)