Skip to content

Commit 2859ef2

Browse files
authored
feat(om2): switch ABNF from RFC 5234 to RFC 7405 (#2923)
* feat(om2): switch ABNF from RFC 5234 to RFC 7405 for explicit case sensitivity Replace all %d decimal literals with readable %s"..." case-sensitive string literals. Mark inf/infinity/nan as %i"..." to preserve their intentional case-insensitivity. Keeps all semantics identical. Signed-off-by: György Krajcsovits <gyorgy.krajcsovits@grafana.com> Coded with Claude Sonnet 4.6. * refactor(om2): inline eof token in ABNF eof was used only once; inline %s"EOF" directly at the use site and remove the separate definition. Signed-off-by: György Krajcsovits <gyorgy.krajcsovits@grafana.com> Coded with Claude Sonnet 4.6. * refactor(om2): inline single-use ABNF tokens Inline type/help/unit, six metric-type keywords, EQ, and gh-count/gh-sum directly at their use sites. Keep gauge and histogram as named tokens since they are reused in gaugehistogram. Signed-off-by: György Krajcsovits <gyorgy.krajcsovits@grafana.com> Coded with Claude Sonnet 4.6. * refactor(om2): inline gauge and histogram ABNF tokens Use %s"gaugehistogram" directly instead of concatenating gauge and histogram tokens, allowing both to be inlined as well. Signed-off-by: György Krajcsovits <gyorgy.krajcsovits@grafana.com> Coded with Claude Sonnet 4.6. * feat(om2): switch ABNF to RFC 7405 with readable string literals - Update ABNF reference from RFC 5234 to RFC 7405 - Replace all %d decimal literals with %s"..." case-sensitive literals - Mark inf/infinity/nan with %i"..." to preserve case-insensitivity - Inline single-use tokens to reduce ABNF size - Add brief explanation of RFC 7405 notation Signed-off-by: György Krajcsovits <gyorgy.krajcsovits@grafana.com> Coded with Claude Sonnet 4.6. --------- Signed-off-by: György Krajcsovits <gyorgy.krajcsovits@grafana.com>
1 parent c05614c commit 2859ef2

1 file changed

Lines changed: 29 additions & 48 deletions

File tree

docs/specs/om/open_metrics_spec_2_0.md

Lines changed: 29 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -444,23 +444,25 @@ Push-based negotiation is inherently more complex, as the exposer typically init
444444

445445
### ABNF
446446

447-
ABNF as per RFC 5234
447+
ABNF as per RFC 7405.
448+
449+
RFC 7405 is built on RFC 5234, but adds explicit case-sensitivity notation for string literals. The literal `%s"text"` means `text` is case-sensitive, and `%i"text"` means case-insensitive.
448450

449451
"exposition" is the top level token of the ABNF.
450452

451453
```abnf
452-
exposition = metricset HASH SP eof [ LF ]
454+
exposition = metricset HASH SP %s"EOF" [ LF ]
453455
454456
metricset = *metricfamily
455457
456458
metricfamily = *metric-descriptor *sample
457459
458-
metric-descriptor = HASH SP type SP (metricname / metricname-utf8) SP metric-type LF
459-
metric-descriptor =/ HASH SP help SP (metricname / metricname-utf8) SP escaped-string LF
460-
metric-descriptor =/ HASH SP unit SP (metricname / metricname-utf8) SP *metricname-char LF
460+
metric-descriptor = HASH SP %s"TYPE" SP (metricname / metricname-utf8) SP metric-type LF
461+
metric-descriptor =/ HASH SP %s"HELP" SP (metricname / metricname-utf8) SP escaped-string LF
462+
metric-descriptor =/ HASH SP %s"UNIT" SP (metricname / metricname-utf8) SP *metricname-char LF
461463
462-
metric-type = counter / gauge / histogram / gaugehistogram / stateset
463-
metric-type =/ info / summary / unknown
464+
metric-type = %s"counter" / %s"gauge" / %s"histogram" / %s"gaugehistogram" / %s"stateset"
465+
metric-type =/ %s"info" / %s"summary" / %s"unknown"
464466
465467
sample = metricname-and-labels SP value [SP timestamp] [SP start-timestamp] *exemplar LF
466468
@@ -469,21 +471,21 @@ value = number / "{" composite-value "}"
469471
timestamp = realnumber
470472
471473
; Lowercase st @ timestamp
472-
start-timestamp = %d115.116 "@" timestamp
474+
start-timestamp = %s"st" "@" timestamp
473475
474476
exemplar = SP HASH SP labels-in-braces SP number SP timestamp
475477
476478
metricname-and-labels = metricname [labels-in-braces] / name-and-labels-in-braces
477479
labels-in-braces = "{" [label *(COMMA label)] "}"
478480
name-and-labels-in-braces = "{" metricname-utf8 *(COMMA label) "}"
479481
480-
label = label-key EQ DQUOTE escaped-string DQUOTE
482+
label = label-key "=" DQUOTE escaped-string DQUOTE
481483
482484
; Number value
483485
number = realnumber
484486
; Case insensitive
485-
number =/ [SIGN] ("inf" / "infinity")
486-
number =/ "nan"
487+
number =/ [SIGN] (%i"inf" / %i"infinity")
488+
number =/ %i"nan"
487489
488490
; Real floats
489491
; Leading 0s explicitly okay
@@ -497,24 +499,7 @@ non-negative-integer = ["+"] 1*"0" / ["+"] positive-integer
497499
positive-integer = *"0" positive-digit *DIGIT
498500
positive-digit = "1" / "2" / "3" / "4" / "5" / "6" / "7" / "8" / "9"
499501
500-
; RFC 5234 is case insensitive.
501-
; Uppercase
502-
eof = %d69.79.70
503-
type = %d84.89.80.69
504-
help = %d72.69.76.80
505-
unit = %d85.78.73.84
506-
; Lowercase
507-
counter = %d99.111.117.110.116.101.114
508-
gauge = %d103.97.117.103.101
509-
histogram = %d104.105.115.116.111.103.114.97.109
510-
gaugehistogram = gauge histogram
511-
stateset = %d115.116.97.116.101.115.101.116
512-
info = %d105.110.102.111
513-
summary = %d115.117.109.109.97.114.121
514-
unknown = %d117.110.107.110.111.119.110
515-
516502
BS = "\"
517-
EQ = "="
518503
COMMA = ","
519504
HASH = "#"
520505
SIGN = "-" / "+"
@@ -546,47 +531,43 @@ composite-value = histogram-value / gauge-histogram-value / summary-value
546531
547532
; Histograms
548533
histogram-value = h-count "," h-sum "," histogram-buckets
549-
gauge-histogram-value = gh-count "," gh-sum "," histogram-buckets
534+
gauge-histogram-value = %s"g" h-count "," %s"g" h-sum "," histogram-buckets
550535
551536
; count:x
552-
h-count = %d99.111.117.110.116 ":" number
553-
; gcount:x
554-
gh-count = %d103 h-count
537+
h-count = %s"count" ":" number
555538
; sum:f allows real numbers and +-Inf and NaN
556-
h-sum = %d115.117.109 ":" number
557-
; gsum:x
558-
gh-sum = %d103 h-sum
539+
h-sum = %s"sum" ":" number
559540
560541
histogram-buckets = classic-buckets / native-buckets [ "," classic-buckets ]
561542
562543
; bucket:[...,+Inf:v] The +Inf bucket is required.
563-
classic-buckets = %d98.117.99.107.101.116 ":" "[" [ ch-le-counts "," ] ch-pos-inf-bucket "]"
544+
classic-buckets = %s"bucket" ":" "[" [ ch-le-counts "," ] ch-pos-inf-bucket "]"
564545
ch-le-counts = (ch-neg-inf-bucket / ch-le-bucket) *("," ch-le-bucket)
565-
ch-pos-inf-bucket = "+" %d73.110.102 ":" number
566-
ch-neg-inf-bucket = "-" %d73.110.102 ":" number
546+
ch-pos-inf-bucket = "+" %s"Inf" ":" number
547+
ch-neg-inf-bucket = "-" %s"Inf" ":" number
567548
ch-le-bucket = realnumber ":" number
568549
569550
; schema:3,zero_threshold:1e-128,zero_count:2,negative_spans:[1:1],negative_buckets:[2],positive_spanes:[-3:1,2:2],positive_buckets:[3,1,0]
570551
native-buckets = nh-schema "," nh-zero-threshold "," nh-zero-count [ "," nh-negative-spans "," nh-negative-buckets ] [ "," nh-positive-spans "," nh-positive-buckets ]
571552
572553
; schema:i
573-
nh-schema = %d115.99.104.101.109.97 ":" integer
554+
nh-schema = %s"schema" ":" integer
574555
; zero_threshold:f
575-
nh-zero-threshold = %d122.101.114.111 "_" %d116.104.114.101.115.104.111.108.100 ":" realnumber
556+
nh-zero-threshold = %s"zero_threshold" ":" realnumber
576557
; zero_count:x
577-
nh-zero-count = %d122.101.114.111 "_" %d99.111.117.110.116 ":" number
558+
nh-zero-count = %s"zero_count" ":" number
578559
; negative_spans:[1:2,3:4] and positive_spans:[-3:1,2:2]
579-
nh-negative-spans = %d110.101.103.97.116.105.118.101 "_" %d115.112.97.110.115 ":" "[" [nh-spans] "]"
580-
nh-positive-spans = %d112.111.115.105.116.105.118.101 "_" %d115.112.97.110.115 ":" "[" [nh-spans] "]"
560+
nh-negative-spans = %s"negative_spans" ":" "[" [nh-spans] "]"
561+
nh-positive-spans = %s"positive_spans" ":" "[" [nh-spans] "]"
581562
; Spans hold offset and length. The offset can start from any index, even
582563
; negative, however subsequent spans can only advance the index, not decrease it.
583564
nh-spans = nh-start-span *("," nh-span)
584565
nh-start-span = integer ":" non-negative-integer
585566
nh-span = non-negative-integer ":" non-negative-integer
586567
587568
; negative_buckets:[1,2,3] and positive_buckets:[1,2,3]
588-
nh-negative-buckets = %d110.101.103.97.116.105.118.101 "_" %d98.117.99.107.101.116.115 ":" "[" [nh-buckets] "]"
589-
nh-positive-buckets = %d112.111.115.105.116.105.118.101 "_" %d98.117.99.107.101.116.115 ":" "[" [nh-buckets] "]"
569+
nh-negative-buckets = %s"negative_buckets" ":" "[" [nh-buckets] "]"
570+
nh-positive-buckets = %s"positive_buckets" ":" "[" [nh-buckets] "]"
590571
591572
nh-buckets = number *("," number)
592573
@@ -596,11 +577,11 @@ nh-buckets = number *("," number)
596577
summary-value = cs-count "," cs-sum "," cs-quantile
597578
598579
; count:x where x is a number
599-
cs-count = %d99.111.117.110.116 ":" number
580+
cs-count = %s"count" ":" number
600581
; sum:x where x is a real number or +-Inf or NaN
601-
cs-sum = %d115.117.109 ":" number
582+
cs-sum = %s"sum" ":" number
602583
; quantile:[...]
603-
cs-quantile = %d113.117.97.110.116.105.108.101 ":" "[" [ cs-q-counts ] "]"
584+
cs-quantile = %s"quantile" ":" "[" [ cs-q-counts ] "]"
604585
cs-q-counts = cs-q-count *("," cs-q-count)
605586
cs-q-count = realnumber ":" number
606587
```

0 commit comments

Comments
 (0)