Skip to content

Commit 532758b

Browse files
authored
OM2.0: Add info and examples for UTF-8 (#2784)
Signed-off-by: Owen Williams <[email protected]>
1 parent 61ce601 commit 532758b

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

docs/specs/om/open_metrics_spec_2_0.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,39 @@ go_goroutines 69
439439
# UNIT process_cpu_seconds seconds
440440
# HELP process_cpu_seconds Total user and system CPU time spent in seconds.
441441
process_cpu_seconds_total 4.20072246e+06
442+
# TYPE "foodb.read.errors" counter
443+
# HELP "foodb.read.errors" The number of errors in the read path for fooDb.
444+
{"foodb.read.errors","service.name"="my_service"} 3482
445+
# EOF
446+
```
447+
448+
##### UTF-8 Quoting
449+
450+
Metric names not conforming to the ABNF definition of `metricname` MUST be
451+
enclosed in double quotes and the alternative UTF-8 syntax MUST be used. In
452+
these MetricPoints, the quoted metric name MUST be moved inside the brackets
453+
without a label name and equal sign, in accordance with the ABNF. The metric
454+
names MUST be enclosed in double quotes in TYPE, UNIT, and HELP lines. Quoting
455+
and the alternative metric syntax MAY be used for any metric name, regardless of
456+
whether the name requires quoting or not.
457+
458+
Label names not conforming to the `label-name` ABNF definition MUST be enclosed
459+
in double quotes. Any label name MAY be enclosed in double quotes.
460+
461+
Expressed as regular expressions, metric names that don't need to be enclosed
462+
in quotes must match: `^[a-zA-Z_:][a-zA-Z0-9_:]*$`. For label names, the string
463+
must match: `^[a-zA-Z_][a-zA-Z0-9_]*$`.
464+
465+
Complete example:
466+
467+
```openmetrics
468+
# TYPE "process.cpu.seconds" counter
469+
# UNIT "process.cpu.seconds" seconds
470+
# HELP "process.cpu.seconds" Total user and system CPU time spent in seconds.
471+
{"process.cpu.seconds","node.name"="my_node"} 4.20072246e+06
472+
# TYPE "quoting_example" gauge
473+
# HELP "quoting_example" Number of goroutines that currently exist.
474+
{"quoting_example","foo"="bar"} 4.5
442475
# EOF
443476
```
444477

@@ -538,6 +571,8 @@ The value of a UNIT or HELP line MAY be empty. This MUST be treated as if no met
538571
# HELP foo_seconds Some text and \n some \" escaping
539572
```
540573

574+
See the UTF-8 Quoting section for circumstances where the metric name MUST be enclosed in double quotes.
575+
541576
There MUST NOT be more than one of each type of metadata line for a MetricFamily. The ordering SHOULD be TYPE, UNIT, HELP.
542577

543578
Aside from this metadata and the EOF line at the end of the message, you MUST NOT expose lines beginning with a #.
@@ -566,6 +601,13 @@ Label values MAY be any valid UTF-8 value, so escaping MUST be applied as per th
566601
bar_seconds_count{a="x",b="escaping\" example \n "} 0
567602
```
568603

604+
Metric names and label names MAY also be any valid UTF-8 value, and under certain circumstances they MUST be quoted and escaped per the ABNF.
605+
See the UTF-8 Quoting section for specifics.
606+
607+
```openmetrics-add-eof
608+
{"\"bar\".seconds.count","b\\"="escaping\" example \n "} 0
609+
```
610+
569611
The rendering of values for a MetricPoint can include additional labels (e.g. the "le" label for a Histogram type), which MUST be rendered in the same way as a Metric's own LabelSet.
570612

571613
#### MetricPoint

0 commit comments

Comments
 (0)