Skip to content

Commit be84ce7

Browse files
committed
om2: MetricFamilyName is MetricName
Fixes prometheus/OpenMetrics#305 Signed-off-by: bwplotka <[email protected]>
1 parent 61ce601 commit be84ce7

File tree

1 file changed

+79
-67
lines changed

1 file changed

+79
-67
lines changed

docs/specs/om/open_metrics_spec_2_0.md

Lines changed: 79 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,9 @@ Ingestors MAY discard exemplars.
116116

117117
#### Metric
118118

119-
Metrics are defined by a unique LabelSet within a MetricFamily. Metrics MUST contain a list of one or more MetricPoints. Metrics with the same name for a given MetricFamily SHOULD have the same set of label names in their LabelSet.
119+
Metrics are defined by a unique LabelSet within a MetricFamily. Metrics MUST contain a list of one or more MetricPoints.
120+
121+
Metrics with the same name for a given MetricFamily SHOULD have the same set of label names in their LabelSet.
120122

121123
MetricPoints SHOULD NOT have explicit timestamps.
122124

@@ -128,27 +130,21 @@ A MetricFamily MAY have zero or more Metrics. A MetricFamily MUST have a name, H
128130

129131
##### Name
130132

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.
132-
133-
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.
133+
MetricFamily name:
134134

135-
MetricFamily names beginning with underscores are RESERVED and MUST NOT be used unless specified by this standard.
135+
* MUST be string.
136+
* MUST be unique within a MetricSet.
137+
* MUST be the same as every MetricPoint's MetricName in the family. TODO(bwplotka): This assumes complex values will be introduced. Otherwise, we need to keep suffixes section for histograms and summaries.
136138

137-
###### Suffixes
139+
> NOTE: [OpenMetrics 1.0](https://prometheus.io/docs/specs/om/open_metrics_spec/#suffixes) was allowing different MetricFamily Name vs MetricName in the same family. For example MetricFamily Name `foo` for a counter with a MetricName `foo_total`. This is no longer accepted thanks to ComplexValue and for parser reliability and future compatibility.
138140
139-
The name of a MetricFamily MUST NOT result in a potential clash for sample metric names as per the ABNF with another MetricFamily in the Text Format within a MetricSet. An example would be a gauge called "foo_total" as a counter called "foo" could create a "foo_total" in the text format.
141+
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 `_total` or unit suffixes are not included.
142+
143+
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.
140144

141-
Exposers SHOULD avoid names that could be confused with the suffixes that text format sample metric names use.
145+
MetricFamily names beginning with underscores are RESERVED and MUST NOT be used unless specified by this standard.
142146

143-
* Suffixes for the respective types are:
144-
* Counter: `_total`
145-
* Summary: `_count`, `_sum`, `` (empty)
146-
* Histogram: `_count`, `_sum`, `_bucket`
147-
* GaugeHistogram: `_gcount`, `_gsum`, `_bucket`
148-
* Info: `_info`
149-
* Gauge: `` (empty)
150-
* StateSet: `` (empty)
151-
* Unknown: `` (empty)
147+
MetricFamily name CAN be used to connect [MetricFamily metadata](#metricfamily-metadata) with [MetricPoint](#metricpoint-1) in the [text format](#text-format).
152148

153149
##### Type
154150

@@ -190,13 +186,13 @@ A gauge MAY be used to encode an enum where the enum has many states and changes
190186

191187
Counters measure discrete events. Common examples are the number of HTTP requests received, CPU seconds spent, or bytes sent. For counters how quickly they are increasing over time is what is of interest to a user.
192188

193-
A MetricPoint in a Metric with the type Counter MUST have one value called Total. A Total is a non-NaN and MUST be monotonically non-decreasing over time, starting from 0.
194-
195-
A MetricPoint in a Metric with the type Counter SHOULD have a Timestamp value called Start Timestamp. This can help ingestors discern between new metrics and long-running ones it did not see before.
189+
A Counter MetricPoint's value MUST be a Number. The value MUST NOT be NaN and MUST be monotonically non-decreasing over time, starting from 0.
196190

197-
A MetricPoint in a Metric's Counter's Total MAY reset to 0. If present, the corresponding Start Timestamp MUST also be set to the timestamp of the reset.
191+
A Counter MetricPoint SHOULD have a Timestamp value called Start Timestamp. This can help ingestors discern between new metrics and long-running ones it did not see before.
198192

199-
A MetricPoint in a Metric's Counter's Total MAY have an exemplar.
193+
A Counter MetricPoint MAY reset to 0. If present, the corresponding Start Timestamp MUST also be set to the timestamp of the reset.
194+
195+
A Counter MetricPoint MAY have an exemplar.
200196

201197
#### StateSet
202198

@@ -424,6 +420,7 @@ Line endings MUST be signalled with line feed (\n) and MUST NOT contain carriage
424420

425421
An example of a complete exposition:
426422

423+
TODO(bwplotka): acme_http_router_request_seconds breaks MetricFamily rule until complex types are introduced.
427424
```openmetrics
428425
# TYPE acme_http_router_request_seconds summary
429426
# UNIT acme_http_router_request_seconds seconds
@@ -435,9 +432,9 @@ acme_http_router_request_seconds_count{path="/api/v2",method="POST"} 34.0 st@160
435432
# TYPE go_goroutines gauge
436433
# HELP go_goroutines Number of goroutines that currently exist.
437434
go_goroutines 69
438-
# TYPE process_cpu_seconds counter
439-
# UNIT process_cpu_seconds seconds
440-
# HELP process_cpu_seconds Total user and system CPU time spent in seconds.
435+
# TYPE process_cpu_seconds_total counter
436+
# UNIT process_cpu_seconds_total seconds
437+
# HELP process_cpu_seconds_total Total user and system CPU time spent in seconds.
441438
process_cpu_seconds_total 4.20072246e+06
442439
# EOF
443440
```
@@ -489,53 +486,60 @@ Timestamps SHOULD NOT use exponential float rendering for timestamps if nanoseco
489486

490487
#### MetricFamily
491488

492-
There MUST NOT be an explicit separator between MetricFamilies. The next MetricFamily MUST be signalled with either metadata or a new sample metric name which cannot be part of the previous MetricFamily.
493-
489+
There MUST NOT be an explicit separator between MetricFamilies. The next MetricFamily MUST be signalled with either metadata or a new sample metric name.
494490

495491
MetricFamilies MUST NOT be interleaved.
496492

497493
##### MetricFamily metadata
498494

499-
There are four pieces of metadata: The MetricFamily name, TYPE, UNIT and HELP. An example of the metadata for a counter Metric called foo is:
495+
There are four pieces of metadata: The MetricFamily name, TYPE, UNIT and HELP. An example of the metadata for a counter Metric called foo is:
500496

501497
```openmetrics-add-eof
502-
# TYPE foo counter
498+
# TYPE foo_total counter
503499
```
504500

505501
If no TYPE is exposed, the MetricFamily MUST be of type Unknown.
506502

507-
If a unit is specified it MUST be provided in a UNIT metadata line. In addition, an underscore and the unit SHOULD be the suffix of the MetricFamily name.
503+
If a unit is specified it MUST be provided in a UNIT metadata line. In addition, an underscore and the unit SHOULD be part of the suffix chain of the MetricFamily name.
508504

509-
Be aware that exposing metrics without the unit being a suffix of the MetricFamily name directly to end-users may reduce the usability due to confusion about what the metric's unit is.
505+
Be aware that exposing metrics without the unit being part of the suffix of the MetricFamily name directly to end-users may reduce the usability due to confusion about what the metric's unit is.
510506

511-
A valid example for a foo_seconds metric with a unit of "seconds":
507+
A valid example for a foo_seconds metric gauge with a unit of "seconds":
512508

513509
```openmetrics-add-eof
514-
# TYPE foo_seconds counter
510+
# TYPE foo_seconds gauge
515511
# UNIT foo_seconds seconds
512+
```
513+
514+
A valid example for a foo_seconds_total metric counter with a unit of "seconds":
515+
516+
```openmetrics-add-eof
517+
# TYPE foo_seconds_total counter
518+
# UNIT foo_seconds_total seconds
516519
```
517520

518-
A valid, but discouraged example, where the unit is not a suffix on the name:
521+
522+
A valid, but discouraged example, where the unit is not part of the suffix on the name:
519523

520524
```openmetrics-add-eof
521-
# TYPE foo counter
522-
# UNIT foo seconds
525+
# TYPE foo_total counter
526+
# UNIT foo_total seconds
523527
```
524528

525529
It is also valid to have:
526530

527531
```openmetrics-add-eof
528-
# TYPE foo_seconds counter
532+
# TYPE foo_seconds_total counter
529533
```
530534

531535
If the unit is known it SHOULD be provided.
532536

533537
The value of a UNIT or HELP line MAY be empty. This MUST be treated as if no metadata line for the MetricFamily existed.
534538

535539
```openmetrics-add-eof
536-
# TYPE foo_seconds counter
537-
# UNIT foo_seconds seconds
538-
# HELP foo_seconds Some text and \n some \" escaping
540+
# TYPE foo_seconds_total counter
541+
# UNIT foo_seconds_total seconds
542+
# HELP foo_seconds_total Some text and \n some \" escaping
539543
```
540544

541545
There MUST NOT be more than one of each type of metadata line for a MetricFamily. The ordering SHOULD be TYPE, UNIT, HELP.
@@ -546,8 +550,10 @@ Aside from this metadata and the EOF line at the end of the message, you MUST NO
546550

547551
Metrics MUST NOT be interleaved.
548552

549-
See the example in "Text format -> MetricPoint".
550-
Labels
553+
See the example in [MetricPoint](#metricpoint).
554+
555+
##### Labels
556+
551557
A sample without labels or a timestamp and the value 0 MUST be rendered either like:
552558

553559
```openmetrics-add-eof
@@ -574,6 +580,7 @@ MetricPoints MUST NOT be interleaved.
574580

575581
A correct example where there were multiple MetricPoints and Samples within a MetricFamily would be:
576582

583+
TODO(bwplotka): foo_seconds breaks MetricFamily rule until complex types are introduced.
577584
```openmetrics-add-eof
578585
# TYPE foo_seconds summary
579586
# UNIT foo_seconds seconds
@@ -589,6 +596,7 @@ foo_seconds_sum{a="ccc"} 0 456
589596

590597
An incorrect example where Metrics are interleaved:
591598

599+
TODO(bwplotka): foo_seconds breaks MetricFamily rule until complex types are introduced.
592600
```
593601
# TYPE foo_seconds summary
594602
# UNIT foo_seconds seconds
@@ -600,6 +608,7 @@ foo_seconds_count{a="ccc"} 0 456
600608

601609
An incorrect example where MetricPoints are interleaved:
602610

611+
TODO(bwplotka): foo_seconds breaks MetricFamily rule until complex types are introduced.
603612
```
604613
# TYPE foo_seconds summary
605614
# UNIT foo_seconds seconds
@@ -613,8 +622,6 @@ foo_seconds_sum{a="bb"} 0 456
613622

614623
##### Gauge
615624

616-
The Sample MetricName for the value of a MetricPoint for a MetricFamily of type Gauge MUST NOT have a suffix.
617-
618625
An example MetricFamily with a Metric with no labels and a MetricPoint with no timestamp:
619626

620627
```openmetrics-add-eof
@@ -660,35 +667,37 @@ foo 18.0 456
660667

661668
##### Counter
662669

663-
The MetricPoint's Total Value Sample MetricName SHOULD have the suffix `_total`. If present, the MetricPoint's Start Timestamp MUST be inlined with the Metric point with a `st@` prefix. If the value's timestamp is present, the Start Timestamp MUST be added right after it. If exemplar is present, the Start Timestamp MUST be added before it.
670+
The Counter MetricPoint's MetricName SHOULD have the suffix `_total`. Be aware that exposing metrics
671+
without `_total` suffix may reduce the usability due to confusion about what the metric's type is.
664672

665-
Be aware that exposing metrics without `_total` being a suffix of the MetricFamily name directly to end-users may reduce the usability due to confusion about what the metric's type is.
673+
// TODO Shouldn't it be before t@?
674+
If present, the MetricPoint's Start Timestamp MUST be inlined with the Metric point with a `st@` prefix, right after the MetricPoint's Timestamp if any, and before any MetricPoint's Exemplar.
666675

667676
An example with a Metric with no labels, and a MetricPoint with no timestamp and no Start Timestamp:
668677

669678
```openmetrics-add-eof
670-
# TYPE foo counter
679+
# TYPE foo_total counter
671680
foo_total 17.0
672681
```
673682

674683
An example with a Metric with no labels, and a MetricPoint with a timestamp and no Start Timestamp:
675684

676685
```openmetrics-add-eof
677-
# TYPE foo counter
686+
# TYPE foo_total counter
678687
foo_total 17.0 1520879607.789
679688
```
680689

681690
An example with a Metric with no labels, and a MetricPoint with no timestamp and a Start Timestamp:
682691

683692
```openmetrics-add-eof
684-
# TYPE foo counter
693+
# TYPE foo_total counter
685694
foo_total 17.0 [email protected]
686695
```
687696

688697
An example with a Metric with no labels, and a MetricPoint with a timestamp and a Start Timestamp:
689698

690699
```openmetrics-add-eof
691-
# TYPE foo counter
700+
# TYPE foo_total counter
692701
foo_total 17.0 1520879607.789 [email protected]
693702
```
694703

@@ -699,19 +708,17 @@ An example with a Metric with no labels, and a MetricPoint without the `_total`
699708
foo 17.0 1520879607.789 [email protected]
700709
```
701710

702-
Exemplars MAY be attached to the MetricPoint's Total sample.
711+
Exemplars MAY be attached to the MetricPoint's sample.
703712

704713
An example with a Metric with no labels, and a MetricPoint with a timestamp and a Start Timestamp and an exemplar:
705714

706715
```openmetrics-add-eof
707-
# TYPE foo counter
716+
# TYPE foo_total counter
708717
foo_total 17.0 1520879607.789 [email protected] # {trace_id="KOO5S4vxi0o"} 0.67
709718
```
710719

711720
##### StateSet
712721

713-
The Sample MetricName for the value of a MetricPoint for a MetricFamily of type StateSet MUST NOT have a suffix.
714-
715722
StateSets MUST have one sample per State in the MetricPoint. Each State's sample MUST have a label with the MetricFamily name as the label name and the State name as the label value. The State sample's value MUST be 1 if the State is true and MUST be 0 if the State is false.
716723

717724
An example with the states "a", "bb", and "ccc" in which only the value bb is enabled and the metric name is foo:
@@ -737,19 +744,21 @@ foo{entity="replica",foo="ccc"} 1.0
737744

738745
##### Info
739746

740-
The Sample MetricName for the value of a MetricPoint for a MetricFamily of type Info MUST have the suffix `_info`. The Sample value MUST always be 1.
747+
The Info MetricPoint's MetricName MUST have the suffix `_info`. // TODO(bwplotka): Shouldn't this "SHOULD"?
748+
749+
The Info MetricPoint's value MUST always be 1.
741750

742751
An example of a Metric with no labels, and one MetricPoint value with "name" and "version" labels:
743752

744753
```openmetrics-add-eof
745-
# TYPE foo info
754+
# TYPE foo_info info
746755
foo_info{name="pretty name",version="8.2.7"} 1
747756
```
748757

749758
An example of a Metric with label "entity" and one MetricPoint value with “name” and “version” labels:
750759

751760
```openmetrics-add-eof
752-
# TYPE foo info
761+
# TYPE foo_info info
753762
foo_info{entity="controller",name="pretty name",version="8.2.7"} 1.0
754763
foo_info{entity="replica",name="prettier name",version="8.1.9"} 1.0
755764
```
@@ -764,6 +773,7 @@ If present the MetricPoint's Start Timestamp MUST be inlined with the Metric poi
764773

765774
An example of a Metric with no labels and a MetricPoint with Sum, Count and Start Timestamp values:
766775

776+
TODO(bwplotka): foo breaks MetricFamily rule until complex types are introduced.
767777
```openmetrics-add-eof
768778
# TYPE foo summary
769779
foo_count 17.0 [email protected]
@@ -772,6 +782,7 @@ foo_sum 324789.3 [email protected]
772782

773783
An example of a Metric with no labels and a MetricPoint with two quantiles and Start Timestamp values:
774784

785+
TODO(bwplotka): foo breaks MetricFamily rule until complex types are introduced.
775786
```openmetrics-add-eof
776787
# TYPE foo summary
777788
foo{quantile="0.95"} 123.7 [email protected]
@@ -792,6 +803,7 @@ Buckets MUST be sorted in number increasing order of "le", and the value of the
792803

793804
An example of a Metric with no labels and a MetricPoint with Sum, Count, and Start Timestamp values, and with 12 buckets. A wide and atypical but valid variety of “le” values is shown on purpose:
794805

806+
TODO(bwplotka): foo breaks MetricFamily rule until complex types are introduced.
795807
```openmetrics-add-eof
796808
# TYPE foo histogram
797809
foo_bucket{le="0.0"} 0 [email protected]
@@ -816,6 +828,7 @@ Exemplars without Labels MUST represent an empty LabelSet as {}.
816828
An example of Exemplars showcasing several valid cases:
817829
The "0.01" bucket has no Exemplar. The 0.1 bucket has an Exemplar with no Labels. The 1 bucket has an Exemplar with one Label. The 10 bucket has an Exemplar with a Label and a timestamp. In practice all buckets SHOULD have the same style of Exemplars.
818830

831+
TODO(bwplotka): foo breaks MetricFamily rule until complex types are introduced.
819832
```openmetrics-add-eof
820833
# TYPE foo histogram
821834
foo_bucket{le="0.01"} 0 [email protected]
@@ -836,6 +849,7 @@ Buckets MUST be sorted in number increasing order of "le", and the value of the
836849

837850
An example of a Metric with no labels, and one MetricPoint value with no Exemplar with no Exemplars in the buckets:
838851

852+
TODO(bwplotka): foo breaks MetricFamily rule until complex types are introduced.
839853
```openmetrics-add-eof
840854
# TYPE foo gaugehistogram
841855
foo_bucket{le="0.01"} 20.0
@@ -849,8 +863,6 @@ foo_gsum 3289.3
849863

850864
##### Unknown
851865

852-
The sample metric name for the value of the MetricPoint for a MetricFamily of type Unknown MUST NOT have a suffix.
853-
854866
An example with a Metric with no labels and a MetricPoint with no timestamp:
855867

856868
```openmetrics-add-eof
@@ -1067,8 +1079,8 @@ One approach would be for push-style ingestors to provide target metadata based
10671079
The preferred solution is to provide this target metadata as part of the exposition, but in a way that does not impact on the exposition as a whole. Info MetricFamilies are designed for this. An exposer may include an Info MetricFamily called "target" with a single Metric with no labels with the metadata. An example in the text format might be:
10681080

10691081
```
1070-
# TYPE target info
1071-
# HELP target Target metadata
1082+
# TYPE target_info info
1083+
# HELP target_info Target metadata
10721084
target_info{env="prod",hostname="myhost",datacenter="sdc",region="europe",owner="frontend"} 1
10731085
```
10741086

@@ -1117,25 +1129,25 @@ All of this is to say that, in general, MetricPoint timestamps should not be exp
11171129
Presume you had a counter my_counter which was initialized, and then later incremented by 1 at time 123. This would be a correct way to expose it in the text format:
11181130

11191131
```
1120-
# HELP my_counter Good increment example
1121-
# TYPE my_counter counter
1132+
# HELP my_counter_total Good increment example
1133+
# TYPE my_counter_total counter
11221134
my_counter_total 1
11231135
```
11241136

11251137
As per the parent section, ingestors should be free to attach their own timestamps, so this would be incorrect:
11261138

11271139
```
1128-
# HELP my_counter Bad increment example
1129-
# TYPE my_counter counter
1140+
# HELP my_counter_total Bad increment example
1141+
# TYPE my_counter_total counter
11301142
my_counter_total 1 123
11311143
```
11321144

11331145

11341146
In case the specific time of the last change of a counter matters, this would be the correct way:
11351147

11361148
```
1137-
# HELP my_counter Good increment example
1138-
# TYPE my_counter counter
1149+
# HELP my_counter_total Good increment example
1150+
# TYPE my_counter_total counter
11391151
my_counter_total 1
11401152
# HELP my_counter_last_increment_timestamp_seconds When my_counter was last incremented
11411153
# TYPE my_counter_last_increment_timestamp_seconds gauge

0 commit comments

Comments
 (0)