Skip to content

Commit 377f77f

Browse files
authored
Merge pull request #2672 from prometheus/krajo/om2-verify-fix-examples
test(om2): test that examples follow the spec and fix if not
2 parents f52f7a0 + 37c1486 commit 377f77f

File tree

2 files changed

+26
-21
lines changed

2 files changed

+26
-21
lines changed

docs/specs/om/open_metrics_spec_2_0.md

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -590,42 +590,42 @@ The Sample MetricName for the value of a MetricPoint for a MetricFamily of type
590590

591591
An example MetricFamily with a Metric with no labels and a MetricPoint with no timestamp:
592592

593-
```
593+
```openmetrics-add-eof
594594
# TYPE foo gauge
595595
foo 17.0
596596
```
597597

598598
An example of a MetricFamily with two Metrics with a label and MetricPoints with no timestamp:
599599

600-
```
600+
```openmetrics-add-eof
601601
# TYPE foo gauge
602602
foo{a="bb"} 17.0
603603
foo{a="ccc"} 17.0
604604
```
605605

606606
An example of a MetricFamily with no Metrics:
607607

608-
```
608+
```openmetrics-add-eof
609609
# TYPE foo gauge
610610
```
611611

612612
An example with a Metric with a label and a MetricPoint with a timestamp:
613613

614-
```
614+
```openmetrics-add-eof
615615
# TYPE foo gauge
616616
foo{a="b"} 17.0 1520879607.789
617617
```
618618

619619
An example with a Metric with no labels and MetricPoint with a timestamp:
620620

621-
```
621+
```openmetrics-add-eof
622622
# TYPE foo gauge
623623
foo 17.0 1520879607.789
624624
```
625625

626626
An example with a Metric with no labels and two MetricPoints with timestamps:
627627

628-
```
628+
```openmetrics-add-eof
629629
# TYPE foo gauge
630630
foo 17.0 123
631631
foo 18.0 456
@@ -637,29 +637,29 @@ The MetricPoint's Total Value Sample MetricName MUST have the suffix `_total`. I
637637

638638
An example with a Metric with no labels, and a MetricPoint with no timestamp and no created:
639639

640-
```
640+
```openmetrics-add-eof
641641
# TYPE foo counter
642642
foo_total 17.0
643643
```
644644

645645
An example with a Metric with no labels, and a MetricPoint with a timestamp and no created:
646646

647-
```
647+
```openmetrics-add-eof
648648
# TYPE foo counter
649649
foo_total 17.0 1520879607.789
650650
```
651651

652652
An example with a Metric with no labels, and a MetricPoint with no timestamp and a created:
653653

654-
```
654+
```openmetrics-add-eof
655655
# TYPE foo counter
656656
foo_total 17.0
657657
foo_created 1520430000.123
658658
```
659659

660660
An example with a Metric with no labels, and a MetricPoint with a timestamp and a created:
661661

662-
```
662+
```openmetrics-add-eof
663663
# TYPE foo counter
664664
foo_total 17.0 1520879607.789
665665
foo_created 1520430000.123 1520879607.789
@@ -675,7 +675,7 @@ StateSets MUST have one sample per State in the MetricPoint. Each State's sample
675675

676676
An example with the states "a", "bb", and "ccc" in which only the value bb is enabled and the metric name is foo:
677677

678-
```
678+
```openmetrics-add-eof
679679
# TYPE foo stateset
680680
foo{foo="a"} 0
681681
foo{foo="bb"} 1
@@ -684,7 +684,7 @@ foo{foo="ccc"} 0
684684

685685
An example of an "entity" label on the Metric:
686686

687-
```
687+
```openmetrics-add-eof
688688
# TYPE foo stateset
689689
foo{entity="controller",foo="a"} 1.0
690690
foo{entity="controller",foo="bb"} 0.0
@@ -700,14 +700,14 @@ The Sample MetricName for the value of a MetricPoint for a MetricFamily of type
700700

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

703-
```
703+
```openmetrics-add-eof
704704
# TYPE foo info
705705
foo_info{name="pretty name",version="8.2.7"} 1
706706
```
707707

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

710-
```
710+
```openmetrics-add-eof
711711
# TYPE foo info
712712
foo_info{entity="controller",name="pretty name",version="8.2.7"} 1.0
713713
foo_info{entity="replica",name="prettier name",version="8.1.9"} 1.0
@@ -721,7 +721,7 @@ If present, the MetricPoint's Sum Value Sample MetricName MUST have the suffix `
721721

722722
An example of a Metric with no labels and a MetricPoint with Sum, Count and Created values:
723723

724-
```
724+
```openmetrics-add-eof
725725
# TYPE foo summary
726726
foo_count 17.0
727727
foo_sum 324789.3
@@ -730,7 +730,7 @@ foo_created 1520430000.123
730730

731731
An example of a Metric with no labels and a MetricPoint with two quantiles:
732732

733-
```
733+
```openmetrics-add-eof
734734
# TYPE foo summary
735735
foo{quantile="0.95"} 123.7
736736
foo{quantile="0.99"} 150.0
@@ -747,7 +747,7 @@ Buckets MUST be sorted in number increasing order of "le", and the value of the
747747

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

750-
```
750+
```openmetrics-add-eof
751751
# TYPE foo histogram
752752
foo_bucket{le="0.0"} 0
753753
foo_bucket{le="1e-05"} 0
@@ -772,7 +772,7 @@ Exemplars without Labels MUST represent an empty LabelSet as {}.
772772
An example of Exemplars showcasing several valid cases:
773773
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.
774774

775-
```
775+
```openmetrics-add-eof
776776
# TYPE foo histogram
777777
foo_bucket{le="0.01"} 0
778778
foo_bucket{le="0.1"} 8 # {} 0.054
@@ -781,7 +781,7 @@ foo_bucket{le="10"} 17 # {trace_id="oHg5SJYRHA0"} 9.8 1520879607.789
781781
foo_bucket{le="+Inf"} 17
782782
foo_count 17
783783
foo_sum 324789.3
784-
foo_created 1520430000.123
784+
foo_created 1520430000.123
785785
```
786786

787787
##### GaugeHistogram
@@ -793,7 +793,7 @@ Buckets MUST be sorted in number increasing order of "le", and the value of the
793793

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

796-
```
796+
```openmetrics-add-eof
797797
# TYPE foo gaugehistogram
798798
foo_bucket{le="0.01"} 20.0
799799
foo_bucket{le="0.1"} 25.0
@@ -810,7 +810,7 @@ The sample metric name for the value of the MetricPoint for a MetricFamily of ty
810810

811811
An example with a Metric with no labels and a MetricPoint with no timestamp:
812812

813-
```
813+
```openmetrics-add-eof
814814
# TYPE foo unknown
815815
foo 42.23
816816
```

openmetrics-spec-tests/check_openmetrics_spec.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ def __iter__(self):
6565

6666
def __next__(self):
6767
collecting = False
68+
append_eof = False
6869
start_line = self.line_number
6970
example_lines = []
7071
for line in self.file:
@@ -78,7 +79,11 @@ def __next__(self):
7879
elif line.startswith('```openmetrics'):
7980
start_line = self.line_number
8081
collecting = True
82+
if line.startswith('```openmetrics-add-eof'):
83+
append_eof = True
8184
if len(example_lines) > 0:
85+
if append_eof:
86+
example_lines.append('# EOF')
8287
return example(start_line, ''.join(example_lines).strip())
8388

8489
raise StopIteration("No more examples found.")

0 commit comments

Comments
 (0)