Skip to content

Commit 4da9670

Browse files
committed
test(om2): test that examples follow the spec and fix if not
I did not want to clutter the examples with adding "# EOF" to all, so I made a new marker to explicitly add it on request. There was only one faulty example where we had an extra space, see the Exemplars section. Signed-off-by: György Krajcsovits <[email protected]>
1 parent d95eed7 commit 4da9670

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
@@ -711,42 +711,42 @@ The Sample MetricName for the value of a MetricPoint for a MetricFamily of type
711711

712712
An example MetricFamily with a Metric with no labels and a MetricPoint with no timestamp:
713713

714-
```
714+
```openmetrics-add-eof
715715
# TYPE foo gauge
716716
foo 17.0
717717
```
718718

719719
An example of a MetricFamily with two Metrics with a label and MetricPoints with no timestamp:
720720

721-
```
721+
```openmetrics-add-eof
722722
# TYPE foo gauge
723723
foo{a="bb"} 17.0
724724
foo{a="ccc"} 17.0
725725
```
726726

727727
An example of a MetricFamily with no Metrics:
728728

729-
```
729+
```openmetrics-add-eof
730730
# TYPE foo gauge
731731
```
732732

733733
An example with a Metric with a label and a MetricPoint with a timestamp:
734734

735-
```
735+
```openmetrics-add-eof
736736
# TYPE foo gauge
737737
foo{a="b"} 17.0 1520879607.789
738738
```
739739

740740
An example with a Metric with no labels and MetricPoint with a timestamp:
741741

742-
```
742+
```openmetrics-add-eof
743743
# TYPE foo gauge
744744
foo 17.0 1520879607.789
745745
```
746746

747747
An example with a Metric with no labels and two MetricPoints with timestamps:
748748

749-
```
749+
```openmetrics-add-eof
750750
# TYPE foo gauge
751751
foo 17.0 123
752752
foo 18.0 456
@@ -758,29 +758,29 @@ The MetricPoint's Total Value Sample MetricName MUST have the suffix `_total`. I
758758

759759
An example with a Metric with no labels, and a MetricPoint with no timestamp and no created:
760760

761-
```
761+
```openmetrics-add-eof
762762
# TYPE foo counter
763763
foo_total 17.0
764764
```
765765

766766
An example with a Metric with no labels, and a MetricPoint with a timestamp and no created:
767767

768-
```
768+
```openmetrics-add-eof
769769
# TYPE foo counter
770770
foo_total 17.0 1520879607.789
771771
```
772772

773773
An example with a Metric with no labels, and a MetricPoint with no timestamp and a created:
774774

775-
```
775+
```openmetrics-add-eof
776776
# TYPE foo counter
777777
foo_total 17.0
778778
foo_created 1520430000.123
779779
```
780780

781781
An example with a Metric with no labels, and a MetricPoint with a timestamp and a created:
782782

783-
```
783+
```openmetrics-add-eof
784784
# TYPE foo counter
785785
foo_total 17.0 1520879607.789
786786
foo_created 1520430000.123 1520879607.789
@@ -796,7 +796,7 @@ StateSets MUST have one sample per State in the MetricPoint. Each State's sample
796796

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

799-
```
799+
```openmetrics-add-eof
800800
# TYPE foo stateset
801801
foo{foo="a"} 0
802802
foo{foo="bb"} 1
@@ -805,7 +805,7 @@ foo{foo="ccc"} 0
805805

806806
An example of an "entity" label on the Metric:
807807

808-
```
808+
```openmetrics-add-eof
809809
# TYPE foo stateset
810810
foo{entity="controller",foo="a"} 1.0
811811
foo{entity="controller",foo="bb"} 0.0
@@ -821,14 +821,14 @@ The Sample MetricName for the value of a MetricPoint for a MetricFamily of type
821821

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

824-
```
824+
```openmetrics-add-eof
825825
# TYPE foo info
826826
foo_info{name="pretty name",version="8.2.7"} 1
827827
```
828828

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

831-
```
831+
```openmetrics-add-eof
832832
# TYPE foo info
833833
foo_info{entity="controller",name="pretty name",version="8.2.7"} 1.0
834834
foo_info{entity="replica",name="prettier name",version="8.1.9"} 1.0
@@ -842,7 +842,7 @@ If present, the MetricPoint's Sum Value Sample MetricName MUST have the suffix `
842842

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

845-
```
845+
```openmetrics-add-eof
846846
# TYPE foo summary
847847
foo_count 17.0
848848
foo_sum 324789.3
@@ -851,7 +851,7 @@ foo_created 1520430000.123
851851

852852
An example of a Metric with no labels and a MetricPoint with two quantiles:
853853

854-
```
854+
```openmetrics-add-eof
855855
# TYPE foo summary
856856
foo{quantile="0.95"} 123.7
857857
foo{quantile="0.99"} 150.0
@@ -868,7 +868,7 @@ Buckets MUST be sorted in number increasing order of "le", and the value of the
868868

869869
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:
870870

871-
```
871+
```openmetrics-add-eof
872872
# TYPE foo histogram
873873
foo_bucket{le="0.0"} 0
874874
foo_bucket{le="1e-05"} 0
@@ -948,7 +948,7 @@ Exemplars without Labels MUST represent an empty LabelSet as {}.
948948
An example of Exemplars showcasing several valid cases:
949949
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.
950950

951-
```
951+
```openmetrics-add-eof
952952
# TYPE foo histogram
953953
foo_bucket{le="0.01"} 0
954954
foo_bucket{le="0.1"} 8 # {} 0.054
@@ -957,7 +957,7 @@ foo_bucket{le="10"} 17 # {trace_id="oHg5SJYRHA0"} 9.8 1520879607.789
957957
foo_bucket{le="+Inf"} 17
958958
foo_count 17
959959
foo_sum 324789.3
960-
foo_created 1520430000.123
960+
foo_created 1520430000.123
961961
```
962962

963963
##### GaugeHistogram with classic buckets
@@ -969,7 +969,7 @@ Buckets MUST be sorted in number increasing order of "le", and the value of the
969969

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

972-
```
972+
```openmetrics-add-eof
973973
# TYPE foo gaugehistogram
974974
foo_bucket{le="0.01"} 20.0
975975
foo_bucket{le="0.1"} 25.0
@@ -1000,7 +1000,7 @@ The sample metric name for the value of the MetricPoint for a MetricFamily of ty
10001000

10011001
An example with a Metric with no labels and a MetricPoint with no timestamp:
10021002

1003-
```
1003+
```openmetrics-add-eof
10041004
# TYPE foo unknown
10051005
foo 42.23
10061006
```

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)