| 
									
										
										
										
											2019-12-24 16:48:28 +08:00
										 |  |  | // Copyright 2017 The Prometheus Authors
 | 
					
						
							| 
									
										
										
										
											2018-10-05 00:57:47 +08:00
										 |  |  | // Licensed under the Apache License, Version 2.0 (the "License");
 | 
					
						
							|  |  |  | // you may not use this file except in compliance with the License.
 | 
					
						
							|  |  |  | // You may obtain a copy of the License at
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // http://www.apache.org/licenses/LICENSE-2.0
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // Unless required by applicable law or agreed to in writing, software
 | 
					
						
							|  |  |  | // distributed under the License is distributed on an "AS IS" BASIS,
 | 
					
						
							|  |  |  | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
					
						
							|  |  |  | // See the License for the specific language governing permissions and
 | 
					
						
							|  |  |  | // limitations under the License.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | package textparse | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							| 
									
										
										
										
											2024-10-10 19:01:13 +08:00
										 |  |  | 	"fmt" | 
					
						
							| 
									
										
										
										
											2018-10-05 00:57:47 +08:00
										 |  |  | 	"io" | 
					
						
							|  |  |  | 	"testing" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-22 22:39:21 +08:00
										 |  |  | 	"github.com/prometheus/common/model" | 
					
						
							| 
									
										
										
										
											2020-10-29 17:43:23 +08:00
										 |  |  | 	"github.com/stretchr/testify/require" | 
					
						
							| 
									
										
										
										
											2020-10-22 17:00:08 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-08 22:23:17 +08:00
										 |  |  | 	"github.com/prometheus/prometheus/model/exemplar" | 
					
						
							|  |  |  | 	"github.com/prometheus/prometheus/model/labels" | 
					
						
							| 
									
										
										
										
											2018-10-05 00:57:47 +08:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-08 19:35:35 +08:00
										 |  |  | func int64p(x int64) *int64 { return &x } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-09 21:09:44 +08:00
										 |  |  | func TestOpenMetricsParse(t *testing.T) { | 
					
						
							| 
									
										
										
										
											2018-10-05 00:57:47 +08:00
										 |  |  | 	input := `# HELP go_gc_duration_seconds A summary of the GC invocation durations. | 
					
						
							|  |  |  | # TYPE go_gc_duration_seconds summary | 
					
						
							|  |  |  | # UNIT go_gc_duration_seconds seconds | 
					
						
							|  |  |  | go_gc_duration_seconds{quantile="0"} 4.9351e-05 | 
					
						
							|  |  |  | go_gc_duration_seconds{quantile="0.25"} 7.424100000000001e-05 | 
					
						
							|  |  |  | go_gc_duration_seconds{quantile="0.5",a="b"} 8.3835e-05 | 
					
						
							|  |  |  | # HELP nohelp1  | 
					
						
							|  |  |  | # HELP help2 escape \ \n \\ \" \x chars | 
					
						
							|  |  |  | # UNIT nounit  | 
					
						
							|  |  |  | go_gc_duration_seconds{quantile="1.0",a="b"} 8.3835e-05 | 
					
						
							|  |  |  | go_gc_duration_seconds_count 99 | 
					
						
							|  |  |  | some:aggregate:rate5m{a_b="c"} 1 | 
					
						
							|  |  |  | # HELP go_goroutines Number of goroutines that currently exist. | 
					
						
							|  |  |  | # TYPE go_goroutines gauge | 
					
						
							|  |  |  | go_goroutines 33 123.123 | 
					
						
							|  |  |  | # TYPE hh histogram | 
					
						
							| 
									
										
										
										
											2019-11-19 17:33:30 +08:00
										 |  |  | hh_bucket{le="+Inf"} 1 | 
					
						
							| 
									
										
										
										
											2018-10-05 00:57:47 +08:00
										 |  |  | # TYPE gh gaugehistogram | 
					
						
							| 
									
										
										
										
											2019-11-19 17:33:30 +08:00
										 |  |  | gh_bucket{le="+Inf"} 1 | 
					
						
							|  |  |  | # TYPE hhh histogram | 
					
						
							| 
									
										
										
										
											2023-02-17 11:25:54 +08:00
										 |  |  | hhh_bucket{le="+Inf"} 1 # {id="histogram-bucket-test"} 4 | 
					
						
							|  |  |  | hhh_count 1 # {id="histogram-count-test"} 4 | 
					
						
							| 
									
										
										
										
											2019-11-19 17:33:30 +08:00
										 |  |  | # TYPE ggh gaugehistogram | 
					
						
							| 
									
										
										
										
											2023-02-17 11:25:54 +08:00
										 |  |  | ggh_bucket{le="+Inf"} 1 # {id="gaugehistogram-bucket-test",xx="yy"} 4 123.123 | 
					
						
							|  |  |  | ggh_count 1 # {id="gaugehistogram-count-test",xx="yy"} 4 123.123 | 
					
						
							|  |  |  | # TYPE smr_seconds summary | 
					
						
							|  |  |  | smr_seconds_count 2.0 # {id="summary-count-test"} 1 123.321 | 
					
						
							|  |  |  | smr_seconds_sum 42.0 # {id="summary-sum-test"} 1 123.321 | 
					
						
							| 
									
										
										
										
											2018-10-05 00:57:47 +08:00
										 |  |  | # TYPE ii info | 
					
						
							|  |  |  | ii{foo="bar"} 1 | 
					
						
							|  |  |  | # TYPE ss stateset | 
					
						
							|  |  |  | ss{ss="foo"} 1 | 
					
						
							|  |  |  | ss{ss="bar"} 0 | 
					
						
							| 
									
										
										
										
											2022-04-01 02:18:53 +08:00
										 |  |  | ss{A="a"} 0 | 
					
						
							| 
									
										
										
										
											2018-10-05 00:57:47 +08:00
										 |  |  | # TYPE un unknown | 
					
						
							|  |  |  | _metric_starting_with_underscore 1 | 
					
						
							|  |  |  | testmetric{_label_starting_with_underscore="foo"} 1 | 
					
						
							| 
									
										
										
										
											2019-11-19 17:33:30 +08:00
										 |  |  | testmetric{label="\"bar\""} 1 | 
					
						
							| 
									
										
										
										
											2024-08-08 19:35:35 +08:00
										 |  |  | # HELP foo Counter with and without labels to certify CT is parsed for both cases | 
					
						
							| 
									
										
										
										
											2019-11-19 17:33:30 +08:00
										 |  |  | # TYPE foo counter | 
					
						
							| 
									
										
										
										
											2024-08-08 19:35:35 +08:00
										 |  |  | foo_total 17.0 1520879607.789 # {id="counter-test"} 5 | 
					
						
							| 
									
										
										
										
											2024-10-02 18:52:03 +08:00
										 |  |  | foo_created 1520872607.123 | 
					
						
							| 
									
										
										
										
											2024-08-08 19:35:35 +08:00
										 |  |  | foo_total{a="b"} 17.0 1520879607.789 # {id="counter-test"} 5 | 
					
						
							| 
									
										
										
										
											2024-10-02 18:52:03 +08:00
										 |  |  | foo_created{a="b"} 1520872607.123 | 
					
						
							| 
									
										
										
										
											2024-10-10 19:01:13 +08:00
										 |  |  | foo_total{le="c"} 21.0 | 
					
						
							|  |  |  | foo_created{le="c"} 1520872621.123 | 
					
						
							| 
									
										
										
										
											2024-10-15 22:23:27 +08:00
										 |  |  | foo_total{le="1"} 10.0 | 
					
						
							| 
									
										
										
										
											2024-08-08 19:35:35 +08:00
										 |  |  | # HELP bar Summary with CT at the end, making sure we find CT even if it's multiple lines a far | 
					
						
							|  |  |  | # TYPE bar summary | 
					
						
							|  |  |  | bar_count 17.0 | 
					
						
							|  |  |  | bar_sum 324789.3 | 
					
						
							|  |  |  | bar{quantile="0.95"} 123.7 | 
					
						
							|  |  |  | bar{quantile="0.99"} 150.0 | 
					
						
							| 
									
										
										
										
											2024-10-04 20:11:02 +08:00
										 |  |  | bar_created 1520872608.124 | 
					
						
							| 
									
										
										
										
											2024-08-08 19:35:35 +08:00
										 |  |  | # HELP baz Histogram with the same objective as above's summary | 
					
						
							|  |  |  | # TYPE baz histogram | 
					
						
							|  |  |  | baz_bucket{le="0.0"} 0 | 
					
						
							|  |  |  | baz_bucket{le="+Inf"} 17 | 
					
						
							|  |  |  | baz_count 17 | 
					
						
							|  |  |  | baz_sum 324789.3 | 
					
						
							| 
									
										
										
										
											2024-10-04 20:11:02 +08:00
										 |  |  | baz_created 1520872609.125 | 
					
						
							| 
									
										
										
										
											2024-08-08 19:35:35 +08:00
										 |  |  | # HELP fizz_created Gauge which shouldn't be parsed as CT | 
					
						
							|  |  |  | # TYPE fizz_created gauge | 
					
						
							| 
									
										
										
										
											2024-10-04 20:11:02 +08:00
										 |  |  | fizz_created 17.0 | 
					
						
							|  |  |  | # HELP something Histogram with _created between buckets and summary | 
					
						
							|  |  |  | # TYPE something histogram | 
					
						
							|  |  |  | something_count 18 | 
					
						
							|  |  |  | something_sum 324789.4 | 
					
						
							|  |  |  | something_created 1520430001 | 
					
						
							|  |  |  | something_bucket{le="0.0"} 1 | 
					
						
							| 
									
										
										
										
											2024-10-15 22:23:27 +08:00
										 |  |  | something_bucket{le="1"} 2 | 
					
						
							| 
									
										
										
										
											2024-10-04 20:11:02 +08:00
										 |  |  | something_bucket{le="+Inf"} 18 | 
					
						
							|  |  |  | # HELP yum Summary with _created between sum and quantiles | 
					
						
							|  |  |  | # TYPE yum summary | 
					
						
							|  |  |  | yum_count 20 | 
					
						
							|  |  |  | yum_sum 324789.5 | 
					
						
							|  |  |  | yum_created 1520430003 | 
					
						
							|  |  |  | yum{quantile="0.95"} 123.7 | 
					
						
							|  |  |  | yum{quantile="0.99"} 150.0 | 
					
						
							|  |  |  | # HELP foobar Summary with _created as the first line | 
					
						
							|  |  |  | # TYPE foobar summary | 
					
						
							|  |  |  | foobar_count 21 | 
					
						
							|  |  |  | foobar_created 1520430004 | 
					
						
							|  |  |  | foobar_sum 324789.6 | 
					
						
							|  |  |  | foobar{quantile="0.95"} 123.8 | 
					
						
							|  |  |  | foobar{quantile="0.99"} 150.1` | 
					
						
							| 
									
										
										
										
											2018-10-05 00:57:47 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	input += "\n# HELP metric foo\x00bar" | 
					
						
							|  |  |  | 	input += "\nnull_byte_metric{a=\"abc\x00\"} 1" | 
					
						
							|  |  |  | 	input += "\n# EOF\n" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-07 19:17:44 +08:00
										 |  |  | 	exp := []parsedEntry{ | 
					
						
							| 
									
										
										
										
											2018-10-05 00:57:47 +08:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			m:    "go_gc_duration_seconds", | 
					
						
							|  |  |  | 			help: "A summary of the GC invocation durations.", | 
					
						
							|  |  |  | 		}, { | 
					
						
							|  |  |  | 			m:   "go_gc_duration_seconds", | 
					
						
							| 
									
										
										
										
											2023-11-22 22:39:21 +08:00
										 |  |  | 			typ: model.MetricTypeSummary, | 
					
						
							| 
									
										
										
										
											2018-10-05 00:57:47 +08:00
										 |  |  | 		}, { | 
					
						
							|  |  |  | 			m:    "go_gc_duration_seconds", | 
					
						
							|  |  |  | 			unit: "seconds", | 
					
						
							|  |  |  | 		}, { | 
					
						
							|  |  |  | 			m:    `go_gc_duration_seconds{quantile="0"}`, | 
					
						
							|  |  |  | 			v:    4.9351e-05, | 
					
						
							| 
									
										
										
										
											2024-10-15 22:23:27 +08:00
										 |  |  | 			lset: labels.FromStrings("__name__", "go_gc_duration_seconds", "quantile", "0.0"), | 
					
						
							| 
									
										
										
										
											2018-10-05 00:57:47 +08:00
										 |  |  | 		}, { | 
					
						
							|  |  |  | 			m:    `go_gc_duration_seconds{quantile="0.25"}`, | 
					
						
							|  |  |  | 			v:    7.424100000000001e-05, | 
					
						
							|  |  |  | 			lset: labels.FromStrings("__name__", "go_gc_duration_seconds", "quantile", "0.25"), | 
					
						
							|  |  |  | 		}, { | 
					
						
							|  |  |  | 			m:    `go_gc_duration_seconds{quantile="0.5",a="b"}`, | 
					
						
							|  |  |  | 			v:    8.3835e-05, | 
					
						
							|  |  |  | 			lset: labels.FromStrings("__name__", "go_gc_duration_seconds", "quantile", "0.5", "a", "b"), | 
					
						
							|  |  |  | 		}, { | 
					
						
							|  |  |  | 			m:    "nohelp1", | 
					
						
							|  |  |  | 			help: "", | 
					
						
							|  |  |  | 		}, { | 
					
						
							|  |  |  | 			m:    "help2", | 
					
						
							|  |  |  | 			help: "escape \\ \n \\ \" \\x chars", | 
					
						
							|  |  |  | 		}, { | 
					
						
							|  |  |  | 			m:    "nounit", | 
					
						
							|  |  |  | 			unit: "", | 
					
						
							|  |  |  | 		}, { | 
					
						
							|  |  |  | 			m:    `go_gc_duration_seconds{quantile="1.0",a="b"}`, | 
					
						
							|  |  |  | 			v:    8.3835e-05, | 
					
						
							|  |  |  | 			lset: labels.FromStrings("__name__", "go_gc_duration_seconds", "quantile", "1.0", "a", "b"), | 
					
						
							|  |  |  | 		}, { | 
					
						
							|  |  |  | 			m:    `go_gc_duration_seconds_count`, | 
					
						
							|  |  |  | 			v:    99, | 
					
						
							|  |  |  | 			lset: labels.FromStrings("__name__", "go_gc_duration_seconds_count"), | 
					
						
							|  |  |  | 		}, { | 
					
						
							|  |  |  | 			m:    `some:aggregate:rate5m{a_b="c"}`, | 
					
						
							|  |  |  | 			v:    1, | 
					
						
							|  |  |  | 			lset: labels.FromStrings("__name__", "some:aggregate:rate5m", "a_b", "c"), | 
					
						
							|  |  |  | 		}, { | 
					
						
							|  |  |  | 			m:    "go_goroutines", | 
					
						
							|  |  |  | 			help: "Number of goroutines that currently exist.", | 
					
						
							|  |  |  | 		}, { | 
					
						
							|  |  |  | 			m:   "go_goroutines", | 
					
						
							| 
									
										
										
										
											2023-11-22 22:39:21 +08:00
										 |  |  | 			typ: model.MetricTypeGauge, | 
					
						
							| 
									
										
										
										
											2018-10-05 00:57:47 +08:00
										 |  |  | 		}, { | 
					
						
							|  |  |  | 			m:    `go_goroutines`, | 
					
						
							|  |  |  | 			v:    33, | 
					
						
							|  |  |  | 			t:    int64p(123123), | 
					
						
							|  |  |  | 			lset: labels.FromStrings("__name__", "go_goroutines"), | 
					
						
							|  |  |  | 		}, { | 
					
						
							|  |  |  | 			m:   "hh", | 
					
						
							| 
									
										
										
										
											2023-11-22 22:39:21 +08:00
										 |  |  | 			typ: model.MetricTypeHistogram, | 
					
						
							| 
									
										
										
										
											2018-10-05 00:57:47 +08:00
										 |  |  | 		}, { | 
					
						
							|  |  |  | 			m:    `hh_bucket{le="+Inf"}`, | 
					
						
							|  |  |  | 			v:    1, | 
					
						
							|  |  |  | 			lset: labels.FromStrings("__name__", "hh_bucket", "le", "+Inf"), | 
					
						
							|  |  |  | 		}, { | 
					
						
							|  |  |  | 			m:   "gh", | 
					
						
							| 
									
										
										
										
											2023-11-22 22:39:21 +08:00
										 |  |  | 			typ: model.MetricTypeGaugeHistogram, | 
					
						
							| 
									
										
										
										
											2018-10-05 00:57:47 +08:00
										 |  |  | 		}, { | 
					
						
							|  |  |  | 			m:    `gh_bucket{le="+Inf"}`, | 
					
						
							|  |  |  | 			v:    1, | 
					
						
							|  |  |  | 			lset: labels.FromStrings("__name__", "gh_bucket", "le", "+Inf"), | 
					
						
							| 
									
										
										
										
											2019-11-19 17:33:30 +08:00
										 |  |  | 		}, { | 
					
						
							|  |  |  | 			m:   "hhh", | 
					
						
							| 
									
										
										
										
											2023-11-22 22:39:21 +08:00
										 |  |  | 			typ: model.MetricTypeHistogram, | 
					
						
							| 
									
										
										
										
											2019-11-19 17:33:30 +08:00
										 |  |  | 		}, { | 
					
						
							|  |  |  | 			m:    `hhh_bucket{le="+Inf"}`, | 
					
						
							|  |  |  | 			v:    1, | 
					
						
							|  |  |  | 			lset: labels.FromStrings("__name__", "hhh_bucket", "le", "+Inf"), | 
					
						
							| 
									
										
										
										
											2024-10-07 19:17:44 +08:00
										 |  |  | 			es: []exemplar.Exemplar{ | 
					
						
							|  |  |  | 				{Labels: labels.FromStrings("id", "histogram-bucket-test"), Value: 4}, | 
					
						
							|  |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2023-02-17 11:25:54 +08:00
										 |  |  | 		}, { | 
					
						
							|  |  |  | 			m:    `hhh_count`, | 
					
						
							|  |  |  | 			v:    1, | 
					
						
							|  |  |  | 			lset: labels.FromStrings("__name__", "hhh_count"), | 
					
						
							| 
									
										
										
										
											2024-10-07 19:17:44 +08:00
										 |  |  | 			es: []exemplar.Exemplar{ | 
					
						
							|  |  |  | 				{Labels: labels.FromStrings("id", "histogram-count-test"), Value: 4}, | 
					
						
							|  |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2019-11-19 17:33:30 +08:00
										 |  |  | 		}, { | 
					
						
							|  |  |  | 			m:   "ggh", | 
					
						
							| 
									
										
										
										
											2023-11-22 22:39:21 +08:00
										 |  |  | 			typ: model.MetricTypeGaugeHistogram, | 
					
						
							| 
									
										
										
										
											2019-11-19 17:33:30 +08:00
										 |  |  | 		}, { | 
					
						
							|  |  |  | 			m:    `ggh_bucket{le="+Inf"}`, | 
					
						
							|  |  |  | 			v:    1, | 
					
						
							|  |  |  | 			lset: labels.FromStrings("__name__", "ggh_bucket", "le", "+Inf"), | 
					
						
							| 
									
										
										
										
											2024-10-07 19:17:44 +08:00
										 |  |  | 			es: []exemplar.Exemplar{ | 
					
						
							|  |  |  | 				{Labels: labels.FromStrings("id", "gaugehistogram-bucket-test", "xx", "yy"), Value: 4, HasTs: true, Ts: 123123}, | 
					
						
							|  |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2023-02-17 11:25:54 +08:00
										 |  |  | 		}, { | 
					
						
							|  |  |  | 			m:    `ggh_count`, | 
					
						
							|  |  |  | 			v:    1, | 
					
						
							|  |  |  | 			lset: labels.FromStrings("__name__", "ggh_count"), | 
					
						
							| 
									
										
										
										
											2024-10-07 19:17:44 +08:00
										 |  |  | 			es: []exemplar.Exemplar{ | 
					
						
							|  |  |  | 				{Labels: labels.FromStrings("id", "gaugehistogram-count-test", "xx", "yy"), Value: 4, HasTs: true, Ts: 123123}, | 
					
						
							|  |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2023-02-17 11:25:54 +08:00
										 |  |  | 		}, { | 
					
						
							|  |  |  | 			m:   "smr_seconds", | 
					
						
							| 
									
										
										
										
											2023-11-22 22:39:21 +08:00
										 |  |  | 			typ: model.MetricTypeSummary, | 
					
						
							| 
									
										
										
										
											2023-02-17 11:25:54 +08:00
										 |  |  | 		}, { | 
					
						
							|  |  |  | 			m:    `smr_seconds_count`, | 
					
						
							|  |  |  | 			v:    2, | 
					
						
							|  |  |  | 			lset: labels.FromStrings("__name__", "smr_seconds_count"), | 
					
						
							| 
									
										
										
										
											2024-10-07 19:17:44 +08:00
										 |  |  | 			es: []exemplar.Exemplar{ | 
					
						
							|  |  |  | 				{Labels: labels.FromStrings("id", "summary-count-test"), Value: 1, HasTs: true, Ts: 123321}, | 
					
						
							|  |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2023-02-17 11:25:54 +08:00
										 |  |  | 		}, { | 
					
						
							|  |  |  | 			m:    `smr_seconds_sum`, | 
					
						
							|  |  |  | 			v:    42, | 
					
						
							|  |  |  | 			lset: labels.FromStrings("__name__", "smr_seconds_sum"), | 
					
						
							| 
									
										
										
										
											2024-10-07 19:17:44 +08:00
										 |  |  | 			es: []exemplar.Exemplar{ | 
					
						
							|  |  |  | 				{Labels: labels.FromStrings("id", "summary-sum-test"), Value: 1, HasTs: true, Ts: 123321}, | 
					
						
							|  |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2018-10-05 00:57:47 +08:00
										 |  |  | 		}, { | 
					
						
							|  |  |  | 			m:   "ii", | 
					
						
							| 
									
										
										
										
											2023-11-22 22:39:21 +08:00
										 |  |  | 			typ: model.MetricTypeInfo, | 
					
						
							| 
									
										
										
										
											2018-10-05 00:57:47 +08:00
										 |  |  | 		}, { | 
					
						
							|  |  |  | 			m:    `ii{foo="bar"}`, | 
					
						
							|  |  |  | 			v:    1, | 
					
						
							|  |  |  | 			lset: labels.FromStrings("__name__", "ii", "foo", "bar"), | 
					
						
							|  |  |  | 		}, { | 
					
						
							|  |  |  | 			m:   "ss", | 
					
						
							| 
									
										
										
										
											2023-11-22 22:39:21 +08:00
										 |  |  | 			typ: model.MetricTypeStateset, | 
					
						
							| 
									
										
										
										
											2018-10-05 00:57:47 +08:00
										 |  |  | 		}, { | 
					
						
							|  |  |  | 			m:    `ss{ss="foo"}`, | 
					
						
							|  |  |  | 			v:    1, | 
					
						
							|  |  |  | 			lset: labels.FromStrings("__name__", "ss", "ss", "foo"), | 
					
						
							|  |  |  | 		}, { | 
					
						
							|  |  |  | 			m:    `ss{ss="bar"}`, | 
					
						
							|  |  |  | 			v:    0, | 
					
						
							|  |  |  | 			lset: labels.FromStrings("__name__", "ss", "ss", "bar"), | 
					
						
							| 
									
										
										
										
											2022-04-01 02:18:53 +08:00
										 |  |  | 		}, { | 
					
						
							|  |  |  | 			m:    `ss{A="a"}`, | 
					
						
							|  |  |  | 			v:    0, | 
					
						
							|  |  |  | 			lset: labels.FromStrings("A", "a", "__name__", "ss"), | 
					
						
							| 
									
										
										
										
											2018-10-05 00:57:47 +08:00
										 |  |  | 		}, { | 
					
						
							|  |  |  | 			m:   "un", | 
					
						
							| 
									
										
										
										
											2023-11-22 22:39:21 +08:00
										 |  |  | 			typ: model.MetricTypeUnknown, | 
					
						
							| 
									
										
										
										
											2018-10-05 00:57:47 +08:00
										 |  |  | 		}, { | 
					
						
							|  |  |  | 			m:    "_metric_starting_with_underscore", | 
					
						
							|  |  |  | 			v:    1, | 
					
						
							|  |  |  | 			lset: labels.FromStrings("__name__", "_metric_starting_with_underscore"), | 
					
						
							|  |  |  | 		}, { | 
					
						
							|  |  |  | 			m:    "testmetric{_label_starting_with_underscore=\"foo\"}", | 
					
						
							|  |  |  | 			v:    1, | 
					
						
							|  |  |  | 			lset: labels.FromStrings("__name__", "testmetric", "_label_starting_with_underscore", "foo"), | 
					
						
							|  |  |  | 		}, { | 
					
						
							|  |  |  | 			m:    "testmetric{label=\"\\\"bar\\\"\"}", | 
					
						
							|  |  |  | 			v:    1, | 
					
						
							|  |  |  | 			lset: labels.FromStrings("__name__", "testmetric", "label", `"bar"`), | 
					
						
							| 
									
										
										
										
											2024-08-08 19:35:35 +08:00
										 |  |  | 		}, { | 
					
						
							|  |  |  | 			m:    "foo", | 
					
						
							|  |  |  | 			help: "Counter with and without labels to certify CT is parsed for both cases", | 
					
						
							| 
									
										
										
										
											2019-11-19 17:33:30 +08:00
										 |  |  | 		}, { | 
					
						
							|  |  |  | 			m:   "foo", | 
					
						
							| 
									
										
										
										
											2023-11-22 22:39:21 +08:00
										 |  |  | 			typ: model.MetricTypeCounter, | 
					
						
							| 
									
										
										
										
											2019-11-19 17:33:30 +08:00
										 |  |  | 		}, { | 
					
						
							|  |  |  | 			m:    "foo_total", | 
					
						
							|  |  |  | 			v:    17, | 
					
						
							|  |  |  | 			lset: labels.FromStrings("__name__", "foo_total"), | 
					
						
							|  |  |  | 			t:    int64p(1520879607789), | 
					
						
							| 
									
										
										
										
											2024-10-07 19:17:44 +08:00
										 |  |  | 			es: []exemplar.Exemplar{ | 
					
						
							|  |  |  | 				{Labels: labels.FromStrings("id", "counter-test"), Value: 5}, | 
					
						
							|  |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2025-03-07 20:43:13 +08:00
										 |  |  | 			ct: 1520872607123, | 
					
						
							| 
									
										
										
										
											2024-08-08 19:35:35 +08:00
										 |  |  | 		}, { | 
					
						
							|  |  |  | 			m:    `foo_total{a="b"}`, | 
					
						
							|  |  |  | 			v:    17.0, | 
					
						
							|  |  |  | 			lset: labels.FromStrings("__name__", "foo_total", "a", "b"), | 
					
						
							|  |  |  | 			t:    int64p(1520879607789), | 
					
						
							| 
									
										
										
										
											2024-10-07 19:17:44 +08:00
										 |  |  | 			es: []exemplar.Exemplar{ | 
					
						
							|  |  |  | 				{Labels: labels.FromStrings("id", "counter-test"), Value: 5}, | 
					
						
							|  |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2025-03-07 20:43:13 +08:00
										 |  |  | 			ct: 1520872607123, | 
					
						
							| 
									
										
										
										
											2024-10-10 19:01:13 +08:00
										 |  |  | 		}, { | 
					
						
							|  |  |  | 			m:    `foo_total{le="c"}`, | 
					
						
							|  |  |  | 			v:    21.0, | 
					
						
							|  |  |  | 			lset: labels.FromStrings("__name__", "foo_total", "le", "c"), | 
					
						
							| 
									
										
										
										
											2025-03-07 20:43:13 +08:00
										 |  |  | 			ct:   1520872621123, | 
					
						
							| 
									
										
										
										
											2024-10-15 22:23:27 +08:00
										 |  |  | 		}, { | 
					
						
							|  |  |  | 			m:    `foo_total{le="1"}`, | 
					
						
							|  |  |  | 			v:    10.0, | 
					
						
							|  |  |  | 			lset: labels.FromStrings("__name__", "foo_total", "le", "1"), | 
					
						
							| 
									
										
										
										
											2024-08-08 19:35:35 +08:00
										 |  |  | 		}, { | 
					
						
							|  |  |  | 			m:    "bar", | 
					
						
							|  |  |  | 			help: "Summary with CT at the end, making sure we find CT even if it's multiple lines a far", | 
					
						
							|  |  |  | 		}, { | 
					
						
							|  |  |  | 			m:   "bar", | 
					
						
							|  |  |  | 			typ: model.MetricTypeSummary, | 
					
						
							|  |  |  | 		}, { | 
					
						
							|  |  |  | 			m:    "bar_count", | 
					
						
							|  |  |  | 			v:    17.0, | 
					
						
							|  |  |  | 			lset: labels.FromStrings("__name__", "bar_count"), | 
					
						
							| 
									
										
										
										
											2025-03-07 20:43:13 +08:00
										 |  |  | 			ct:   1520872608124, | 
					
						
							| 
									
										
										
										
											2024-08-08 19:35:35 +08:00
										 |  |  | 		}, { | 
					
						
							|  |  |  | 			m:    "bar_sum", | 
					
						
							|  |  |  | 			v:    324789.3, | 
					
						
							|  |  |  | 			lset: labels.FromStrings("__name__", "bar_sum"), | 
					
						
							| 
									
										
										
										
											2025-03-07 20:43:13 +08:00
										 |  |  | 			ct:   1520872608124, | 
					
						
							| 
									
										
										
										
											2024-08-08 19:35:35 +08:00
										 |  |  | 		}, { | 
					
						
							|  |  |  | 			m:    `bar{quantile="0.95"}`, | 
					
						
							|  |  |  | 			v:    123.7, | 
					
						
							|  |  |  | 			lset: labels.FromStrings("__name__", "bar", "quantile", "0.95"), | 
					
						
							| 
									
										
										
										
											2025-03-07 20:43:13 +08:00
										 |  |  | 			ct:   1520872608124, | 
					
						
							| 
									
										
										
										
											2024-08-08 19:35:35 +08:00
										 |  |  | 		}, { | 
					
						
							|  |  |  | 			m:    `bar{quantile="0.99"}`, | 
					
						
							|  |  |  | 			v:    150.0, | 
					
						
							|  |  |  | 			lset: labels.FromStrings("__name__", "bar", "quantile", "0.99"), | 
					
						
							| 
									
										
										
										
											2025-03-07 20:43:13 +08:00
										 |  |  | 			ct:   1520872608124, | 
					
						
							| 
									
										
										
										
											2024-08-08 19:35:35 +08:00
										 |  |  | 		}, { | 
					
						
							|  |  |  | 			m:    "baz", | 
					
						
							|  |  |  | 			help: "Histogram with the same objective as above's summary", | 
					
						
							|  |  |  | 		}, { | 
					
						
							|  |  |  | 			m:   "baz", | 
					
						
							|  |  |  | 			typ: model.MetricTypeHistogram, | 
					
						
							|  |  |  | 		}, { | 
					
						
							|  |  |  | 			m:    `baz_bucket{le="0.0"}`, | 
					
						
							|  |  |  | 			v:    0, | 
					
						
							|  |  |  | 			lset: labels.FromStrings("__name__", "baz_bucket", "le", "0.0"), | 
					
						
							| 
									
										
										
										
											2025-03-07 20:43:13 +08:00
										 |  |  | 			ct:   1520872609125, | 
					
						
							| 
									
										
										
										
											2024-08-08 19:35:35 +08:00
										 |  |  | 		}, { | 
					
						
							|  |  |  | 			m:    `baz_bucket{le="+Inf"}`, | 
					
						
							|  |  |  | 			v:    17, | 
					
						
							|  |  |  | 			lset: labels.FromStrings("__name__", "baz_bucket", "le", "+Inf"), | 
					
						
							| 
									
										
										
										
											2025-03-07 20:43:13 +08:00
										 |  |  | 			ct:   1520872609125, | 
					
						
							| 
									
										
										
										
											2024-08-08 19:35:35 +08:00
										 |  |  | 		}, { | 
					
						
							|  |  |  | 			m:    `baz_count`, | 
					
						
							|  |  |  | 			v:    17, | 
					
						
							|  |  |  | 			lset: labels.FromStrings("__name__", "baz_count"), | 
					
						
							| 
									
										
										
										
											2025-03-07 20:43:13 +08:00
										 |  |  | 			ct:   1520872609125, | 
					
						
							| 
									
										
										
										
											2024-08-08 19:35:35 +08:00
										 |  |  | 		}, { | 
					
						
							|  |  |  | 			m:    `baz_sum`, | 
					
						
							|  |  |  | 			v:    324789.3, | 
					
						
							|  |  |  | 			lset: labels.FromStrings("__name__", "baz_sum"), | 
					
						
							| 
									
										
										
										
											2025-03-07 20:43:13 +08:00
										 |  |  | 			ct:   1520872609125, | 
					
						
							| 
									
										
										
										
											2024-08-08 19:35:35 +08:00
										 |  |  | 		}, { | 
					
						
							|  |  |  | 			m:    "fizz_created", | 
					
						
							|  |  |  | 			help: "Gauge which shouldn't be parsed as CT", | 
					
						
							|  |  |  | 		}, { | 
					
						
							|  |  |  | 			m:   "fizz_created", | 
					
						
							|  |  |  | 			typ: model.MetricTypeGauge, | 
					
						
							|  |  |  | 		}, { | 
					
						
							|  |  |  | 			m:    `fizz_created`, | 
					
						
							|  |  |  | 			v:    17, | 
					
						
							|  |  |  | 			lset: labels.FromStrings("__name__", "fizz_created"), | 
					
						
							| 
									
										
										
										
											2024-10-04 20:11:02 +08:00
										 |  |  | 		}, { | 
					
						
							|  |  |  | 			m:    "something", | 
					
						
							|  |  |  | 			help: "Histogram with _created between buckets and summary", | 
					
						
							|  |  |  | 		}, { | 
					
						
							|  |  |  | 			m:   "something", | 
					
						
							|  |  |  | 			typ: model.MetricTypeHistogram, | 
					
						
							|  |  |  | 		}, { | 
					
						
							|  |  |  | 			m:    `something_count`, | 
					
						
							|  |  |  | 			v:    18, | 
					
						
							|  |  |  | 			lset: labels.FromStrings("__name__", "something_count"), | 
					
						
							| 
									
										
										
										
											2025-03-07 20:43:13 +08:00
										 |  |  | 			ct:   1520430001000, | 
					
						
							| 
									
										
										
										
											2024-10-04 20:11:02 +08:00
										 |  |  | 		}, { | 
					
						
							|  |  |  | 			m:    `something_sum`, | 
					
						
							|  |  |  | 			v:    324789.4, | 
					
						
							|  |  |  | 			lset: labels.FromStrings("__name__", "something_sum"), | 
					
						
							| 
									
										
										
										
											2025-03-07 20:43:13 +08:00
										 |  |  | 			ct:   1520430001000, | 
					
						
							| 
									
										
										
										
											2024-10-04 20:11:02 +08:00
										 |  |  | 		}, { | 
					
						
							|  |  |  | 			m:    `something_bucket{le="0.0"}`, | 
					
						
							|  |  |  | 			v:    1, | 
					
						
							|  |  |  | 			lset: labels.FromStrings("__name__", "something_bucket", "le", "0.0"), | 
					
						
							| 
									
										
										
										
											2025-03-07 20:43:13 +08:00
										 |  |  | 			ct:   1520430001000, | 
					
						
							| 
									
										
										
										
											2024-10-15 22:23:27 +08:00
										 |  |  | 		}, { | 
					
						
							|  |  |  | 			m:    `something_bucket{le="1"}`, | 
					
						
							|  |  |  | 			v:    2, | 
					
						
							|  |  |  | 			lset: labels.FromStrings("__name__", "something_bucket", "le", "1.0"), | 
					
						
							| 
									
										
										
										
											2025-03-07 20:43:13 +08:00
										 |  |  | 			ct:   1520430001000, | 
					
						
							| 
									
										
										
										
											2024-10-04 20:11:02 +08:00
										 |  |  | 		}, { | 
					
						
							|  |  |  | 			m:    `something_bucket{le="+Inf"}`, | 
					
						
							|  |  |  | 			v:    18, | 
					
						
							|  |  |  | 			lset: labels.FromStrings("__name__", "something_bucket", "le", "+Inf"), | 
					
						
							| 
									
										
										
										
											2025-03-07 20:43:13 +08:00
										 |  |  | 			ct:   1520430001000, | 
					
						
							| 
									
										
										
										
											2024-10-04 20:11:02 +08:00
										 |  |  | 		}, { | 
					
						
							|  |  |  | 			m:    "yum", | 
					
						
							|  |  |  | 			help: "Summary with _created between sum and quantiles", | 
					
						
							|  |  |  | 		}, { | 
					
						
							|  |  |  | 			m:   "yum", | 
					
						
							|  |  |  | 			typ: model.MetricTypeSummary, | 
					
						
							|  |  |  | 		}, { | 
					
						
							|  |  |  | 			m:    `yum_count`, | 
					
						
							|  |  |  | 			v:    20, | 
					
						
							|  |  |  | 			lset: labels.FromStrings("__name__", "yum_count"), | 
					
						
							| 
									
										
										
										
											2025-03-07 20:43:13 +08:00
										 |  |  | 			ct:   1520430003000, | 
					
						
							| 
									
										
										
										
											2024-10-04 20:11:02 +08:00
										 |  |  | 		}, { | 
					
						
							|  |  |  | 			m:    `yum_sum`, | 
					
						
							|  |  |  | 			v:    324789.5, | 
					
						
							|  |  |  | 			lset: labels.FromStrings("__name__", "yum_sum"), | 
					
						
							| 
									
										
										
										
											2025-03-07 20:43:13 +08:00
										 |  |  | 			ct:   1520430003000, | 
					
						
							| 
									
										
										
										
											2024-10-04 20:11:02 +08:00
										 |  |  | 		}, { | 
					
						
							|  |  |  | 			m:    `yum{quantile="0.95"}`, | 
					
						
							|  |  |  | 			v:    123.7, | 
					
						
							|  |  |  | 			lset: labels.FromStrings("__name__", "yum", "quantile", "0.95"), | 
					
						
							| 
									
										
										
										
											2025-03-07 20:43:13 +08:00
										 |  |  | 			ct:   1520430003000, | 
					
						
							| 
									
										
										
										
											2024-10-04 20:11:02 +08:00
										 |  |  | 		}, { | 
					
						
							|  |  |  | 			m:    `yum{quantile="0.99"}`, | 
					
						
							|  |  |  | 			v:    150.0, | 
					
						
							|  |  |  | 			lset: labels.FromStrings("__name__", "yum", "quantile", "0.99"), | 
					
						
							| 
									
										
										
										
											2025-03-07 20:43:13 +08:00
										 |  |  | 			ct:   1520430003000, | 
					
						
							| 
									
										
										
										
											2024-10-04 20:11:02 +08:00
										 |  |  | 		}, { | 
					
						
							|  |  |  | 			m:    "foobar", | 
					
						
							|  |  |  | 			help: "Summary with _created as the first line", | 
					
						
							|  |  |  | 		}, { | 
					
						
							|  |  |  | 			m:   "foobar", | 
					
						
							|  |  |  | 			typ: model.MetricTypeSummary, | 
					
						
							|  |  |  | 		}, { | 
					
						
							|  |  |  | 			m:    `foobar_count`, | 
					
						
							|  |  |  | 			v:    21, | 
					
						
							|  |  |  | 			lset: labels.FromStrings("__name__", "foobar_count"), | 
					
						
							| 
									
										
										
										
											2025-03-07 20:43:13 +08:00
										 |  |  | 			ct:   1520430004000, | 
					
						
							| 
									
										
										
										
											2024-10-04 20:11:02 +08:00
										 |  |  | 		}, { | 
					
						
							|  |  |  | 			m:    `foobar_sum`, | 
					
						
							|  |  |  | 			v:    324789.6, | 
					
						
							|  |  |  | 			lset: labels.FromStrings("__name__", "foobar_sum"), | 
					
						
							| 
									
										
										
										
											2025-03-07 20:43:13 +08:00
										 |  |  | 			ct:   1520430004000, | 
					
						
							| 
									
										
										
										
											2024-10-04 20:11:02 +08:00
										 |  |  | 		}, { | 
					
						
							|  |  |  | 			m:    `foobar{quantile="0.95"}`, | 
					
						
							|  |  |  | 			v:    123.8, | 
					
						
							|  |  |  | 			lset: labels.FromStrings("__name__", "foobar", "quantile", "0.95"), | 
					
						
							| 
									
										
										
										
											2025-03-07 20:43:13 +08:00
										 |  |  | 			ct:   1520430004000, | 
					
						
							| 
									
										
										
										
											2024-10-04 20:11:02 +08:00
										 |  |  | 		}, { | 
					
						
							|  |  |  | 			m:    `foobar{quantile="0.99"}`, | 
					
						
							|  |  |  | 			v:    150.1, | 
					
						
							|  |  |  | 			lset: labels.FromStrings("__name__", "foobar", "quantile", "0.99"), | 
					
						
							| 
									
										
										
										
											2025-03-07 20:43:13 +08:00
										 |  |  | 			ct:   1520430004000, | 
					
						
							| 
									
										
										
										
											2018-10-05 00:57:47 +08:00
										 |  |  | 		}, { | 
					
						
							|  |  |  | 			m:    "metric", | 
					
						
							|  |  |  | 			help: "foo\x00bar", | 
					
						
							|  |  |  | 		}, { | 
					
						
							|  |  |  | 			m:    "null_byte_metric{a=\"abc\x00\"}", | 
					
						
							|  |  |  | 			v:    1, | 
					
						
							|  |  |  | 			lset: labels.FromStrings("__name__", "null_byte_metric", "a", "abc\x00"), | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-08 19:35:35 +08:00
										 |  |  | 	p := NewOpenMetricsParser([]byte(input), labels.NewSymbolTable(), WithOMParserCTSeriesSkipped()) | 
					
						
							| 
									
										
										
										
											2024-10-07 19:17:44 +08:00
										 |  |  | 	got := testParse(t, p) | 
					
						
							|  |  |  | 	requireEntries(t, exp, got) | 
					
						
							| 
									
										
										
										
											2018-10-05 00:57:47 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-16 03:25:12 +08:00
										 |  |  | func TestUTF8OpenMetricsParse(t *testing.T) { | 
					
						
							|  |  |  | 	input := `# HELP "go.gc_duration_seconds" A summary of the GC invocation durations. | 
					
						
							|  |  |  | # TYPE "go.gc_duration_seconds" summary | 
					
						
							|  |  |  | # UNIT "go.gc_duration_seconds" seconds | 
					
						
							|  |  |  | {"go.gc_duration_seconds",quantile="0"} 4.9351e-05 | 
					
						
							|  |  |  | {"go.gc_duration_seconds",quantile="0.25"} 7.424100000000001e-05 | 
					
						
							| 
									
										
										
										
											2024-10-02 18:52:03 +08:00
										 |  |  | {"go.gc_duration_seconds_created"} 1520872607.123 | 
					
						
							| 
									
										
										
										
											2024-02-16 03:25:12 +08:00
										 |  |  | {"go.gc_duration_seconds",quantile="0.5",a="b"} 8.3835e-05 | 
					
						
							|  |  |  | {"http.status",q="0.9",a="b"} 8.3835e-05 | 
					
						
							|  |  |  | {"http.status",q="0.9",a="b"} 8.3835e-05 | 
					
						
							|  |  |  | {q="0.9","http.status",a="b"} 8.3835e-05 | 
					
						
							|  |  |  | {"go.gc_duration_seconds_sum"} 0.004304266 | 
					
						
							| 
									
										
										
										
											2024-11-02 00:24:31 +08:00
										 |  |  | {"Heizölrückstoßabdämpfung 10€ metric with \"interesting\" {character\nchoices}","strange©™\n'quoted' \"name\""="6"} 10.0 | 
					
						
							|  |  |  | quotedexemplar_count 1 # {"id.thing"="histogram-count-test"} 4 | 
					
						
							|  |  |  | quotedexemplar2_count 1 # {"id.thing"="histogram-count-test",other="hello"} 4 | 
					
						
							|  |  |  | ` | 
					
						
							| 
									
										
										
										
											2024-02-16 03:25:12 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-02 00:24:31 +08:00
										 |  |  | 	input += "# EOF\n" | 
					
						
							| 
									
										
										
										
											2024-02-16 03:25:12 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-07 19:17:44 +08:00
										 |  |  | 	exp := []parsedEntry{ | 
					
						
							| 
									
										
										
										
											2024-02-16 03:25:12 +08:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			m:    "go.gc_duration_seconds", | 
					
						
							|  |  |  | 			help: "A summary of the GC invocation durations.", | 
					
						
							|  |  |  | 		}, { | 
					
						
							|  |  |  | 			m:   "go.gc_duration_seconds", | 
					
						
							|  |  |  | 			typ: model.MetricTypeSummary, | 
					
						
							|  |  |  | 		}, { | 
					
						
							|  |  |  | 			m:    "go.gc_duration_seconds", | 
					
						
							|  |  |  | 			unit: "seconds", | 
					
						
							|  |  |  | 		}, { | 
					
						
							|  |  |  | 			m:    `{"go.gc_duration_seconds",quantile="0"}`, | 
					
						
							|  |  |  | 			v:    4.9351e-05, | 
					
						
							| 
									
										
										
										
											2024-10-15 22:23:27 +08:00
										 |  |  | 			lset: labels.FromStrings("__name__", "go.gc_duration_seconds", "quantile", "0.0"), | 
					
						
							| 
									
										
										
										
											2025-03-07 20:43:13 +08:00
										 |  |  | 			ct:   1520872607123, | 
					
						
							| 
									
										
										
										
											2024-02-16 03:25:12 +08:00
										 |  |  | 		}, { | 
					
						
							|  |  |  | 			m:    `{"go.gc_duration_seconds",quantile="0.25"}`, | 
					
						
							|  |  |  | 			v:    7.424100000000001e-05, | 
					
						
							|  |  |  | 			lset: labels.FromStrings("__name__", "go.gc_duration_seconds", "quantile", "0.25"), | 
					
						
							| 
									
										
										
										
											2025-03-07 20:43:13 +08:00
										 |  |  | 			ct:   1520872607123, | 
					
						
							| 
									
										
										
										
											2024-02-16 03:25:12 +08:00
										 |  |  | 		}, { | 
					
						
							|  |  |  | 			m:    `{"go.gc_duration_seconds",quantile="0.5",a="b"}`, | 
					
						
							|  |  |  | 			v:    8.3835e-05, | 
					
						
							|  |  |  | 			lset: labels.FromStrings("__name__", "go.gc_duration_seconds", "quantile", "0.5", "a", "b"), | 
					
						
							|  |  |  | 		}, { | 
					
						
							|  |  |  | 			m:    `{"http.status",q="0.9",a="b"}`, | 
					
						
							|  |  |  | 			v:    8.3835e-05, | 
					
						
							|  |  |  | 			lset: labels.FromStrings("__name__", "http.status", "q", "0.9", "a", "b"), | 
					
						
							|  |  |  | 		}, { | 
					
						
							|  |  |  | 			m:    `{"http.status",q="0.9",a="b"}`, | 
					
						
							|  |  |  | 			v:    8.3835e-05, | 
					
						
							|  |  |  | 			lset: labels.FromStrings("__name__", "http.status", "q", "0.9", "a", "b"), | 
					
						
							|  |  |  | 		}, { | 
					
						
							|  |  |  | 			m:    `{q="0.9","http.status",a="b"}`, | 
					
						
							|  |  |  | 			v:    8.3835e-05, | 
					
						
							|  |  |  | 			lset: labels.FromStrings("__name__", "http.status", "q", "0.9", "a", "b"), | 
					
						
							|  |  |  | 		}, { | 
					
						
							|  |  |  | 			m:    `{"go.gc_duration_seconds_sum"}`, | 
					
						
							|  |  |  | 			v:    0.004304266, | 
					
						
							|  |  |  | 			lset: labels.FromStrings("__name__", "go.gc_duration_seconds_sum"), | 
					
						
							|  |  |  | 		}, { | 
					
						
							|  |  |  | 			m: `{"Heizölrückstoßabdämpfung 10€ metric with \"interesting\" {character\nchoices}","strange©™\n'quoted' \"name\""="6"}`, | 
					
						
							|  |  |  | 			v: 10.0, | 
					
						
							|  |  |  | 			lset: labels.FromStrings("__name__", `Heizölrückstoßabdämpfung 10€ metric with "interesting" {character | 
					
						
							|  |  |  | choices}`, "strange©™\n'quoted' \"name\"", "6"), | 
					
						
							| 
									
										
										
										
											2024-11-02 00:24:31 +08:00
										 |  |  | 		}, { | 
					
						
							|  |  |  | 			m:    `quotedexemplar_count`, | 
					
						
							|  |  |  | 			v:    1, | 
					
						
							|  |  |  | 			lset: labels.FromStrings("__name__", "quotedexemplar_count"), | 
					
						
							|  |  |  | 			es: []exemplar.Exemplar{ | 
					
						
							|  |  |  | 				{Labels: labels.FromStrings("id.thing", "histogram-count-test"), Value: 4}, | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 		}, { | 
					
						
							|  |  |  | 			m:    `quotedexemplar2_count`, | 
					
						
							|  |  |  | 			v:    1, | 
					
						
							|  |  |  | 			lset: labels.FromStrings("__name__", "quotedexemplar2_count"), | 
					
						
							|  |  |  | 			es: []exemplar.Exemplar{ | 
					
						
							|  |  |  | 				{Labels: labels.FromStrings("id.thing", "histogram-count-test", "other", "hello"), Value: 4}, | 
					
						
							|  |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2024-02-16 03:25:12 +08:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-08 19:35:35 +08:00
										 |  |  | 	p := NewOpenMetricsParser([]byte(input), labels.NewSymbolTable(), WithOMParserCTSeriesSkipped()) | 
					
						
							| 
									
										
										
										
											2024-10-07 19:17:44 +08:00
										 |  |  | 	got := testParse(t, p) | 
					
						
							|  |  |  | 	requireEntries(t, exp, got) | 
					
						
							| 
									
										
										
										
											2024-02-16 03:25:12 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-09 21:09:44 +08:00
										 |  |  | func TestOpenMetricsParseErrors(t *testing.T) { | 
					
						
							| 
									
										
										
										
											2018-10-05 00:57:47 +08:00
										 |  |  | 	cases := []struct { | 
					
						
							|  |  |  | 		input string | 
					
						
							|  |  |  | 		err   string | 
					
						
							|  |  |  | 	}{ | 
					
						
							| 
									
										
										
										
											2019-12-24 16:48:28 +08:00
										 |  |  | 		// Happy cases. EOF is returned by the parser at the end of valid
 | 
					
						
							|  |  |  | 		// data.
 | 
					
						
							| 
									
										
										
										
											2018-10-05 00:57:47 +08:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2019-12-24 16:48:28 +08:00
										 |  |  | 			input: "# EOF", | 
					
						
							| 
									
										
										
										
											2019-11-19 17:33:30 +08:00
										 |  |  | 			err:   "EOF", | 
					
						
							| 
									
										
										
										
											2018-10-05 00:57:47 +08:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2019-12-24 16:48:28 +08:00
										 |  |  | 			input: "# EOF\n", | 
					
						
							|  |  |  | 			err:   "EOF", | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		// Unhappy cases.
 | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			input: "", | 
					
						
							|  |  |  | 			err:   "data does not end with # EOF", | 
					
						
							| 
									
										
										
										
											2018-10-05 00:57:47 +08:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			input: "\n", | 
					
						
							| 
									
										
										
										
											2023-02-03 23:50:15 +08:00
										 |  |  | 			err:   "expected a valid start token, got \"\\n\" (\"INVALID\") while parsing: \"\\n\"", | 
					
						
							| 
									
										
										
										
											2018-10-05 00:57:47 +08:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2019-12-24 16:48:28 +08:00
										 |  |  | 			input: "metric", | 
					
						
							| 
									
										
										
										
											2023-02-03 23:50:15 +08:00
										 |  |  | 			err:   "expected value after metric, got \"metric\" (\"EOF\") while parsing: \"metric\"", | 
					
						
							| 
									
										
										
										
											2019-12-24 16:48:28 +08:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			input: "metric 1", | 
					
						
							|  |  |  | 			err:   "data does not end with # EOF", | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			input: "metric 1\n", | 
					
						
							|  |  |  | 			err:   "data does not end with # EOF", | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			input: "metric_total 1 # {aa=\"bb\"} 4", | 
					
						
							|  |  |  | 			err:   "data does not end with # EOF", | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			input: "a\n#EOF\n", | 
					
						
							| 
									
										
										
										
											2023-02-03 23:50:15 +08:00
										 |  |  | 			err:   "expected value after metric, got \"\\n\" (\"INVALID\") while parsing: \"a\\n\"", | 
					
						
							| 
									
										
										
										
											2019-12-24 16:48:28 +08:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			input: "\n\n#EOF\n", | 
					
						
							| 
									
										
										
										
											2023-02-03 23:50:15 +08:00
										 |  |  | 			err:   "expected a valid start token, got \"\\n\" (\"INVALID\") while parsing: \"\\n\"", | 
					
						
							| 
									
										
										
										
											2019-12-24 16:48:28 +08:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			input: " a 1\n#EOF\n", | 
					
						
							| 
									
										
										
										
											2023-02-03 23:50:15 +08:00
										 |  |  | 			err:   "expected a valid start token, got \" \" (\"INVALID\") while parsing: \" \"", | 
					
						
							| 
									
										
										
										
											2018-10-05 00:57:47 +08:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2019-12-24 16:48:28 +08:00
										 |  |  | 			input: "9\n#EOF\n", | 
					
						
							| 
									
										
										
										
											2023-02-03 23:50:15 +08:00
										 |  |  | 			err:   "expected a valid start token, got \"9\" (\"INVALID\") while parsing: \"9\"", | 
					
						
							| 
									
										
										
										
											2018-10-05 00:57:47 +08:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2019-12-24 16:48:28 +08:00
										 |  |  | 			input: "# TYPE u untyped\n#EOF\n", | 
					
						
							| 
									
										
										
										
											2018-10-05 00:57:47 +08:00
										 |  |  | 			err:   "invalid metric type \"untyped\"", | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2019-12-24 16:48:28 +08:00
										 |  |  | 			input: "# TYPE c counter \n#EOF\n", | 
					
						
							| 
									
										
										
										
											2018-10-05 00:57:47 +08:00
										 |  |  | 			err:   "invalid metric type \"counter \"", | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2019-12-24 16:48:28 +08:00
										 |  |  | 			input: "#  TYPE c counter\n#EOF\n", | 
					
						
							| 
									
										
										
										
											2023-02-03 23:50:15 +08:00
										 |  |  | 			err:   "expected a valid start token, got \"#  \" (\"INVALID\") while parsing: \"#  \"", | 
					
						
							| 
									
										
										
										
											2018-10-05 00:57:47 +08:00
										 |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2022-03-08 21:04:11 +08:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			input: "# TYPE \n#EOF\n", | 
					
						
							| 
									
										
										
										
											2023-02-03 23:50:15 +08:00
										 |  |  | 			err:   "expected metric name after TYPE, got \"\\n\" (\"INVALID\") while parsing: \"# TYPE \\n\"", | 
					
						
							| 
									
										
										
										
											2022-03-08 21:04:11 +08:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			input: "# TYPE m\n#EOF\n", | 
					
						
							|  |  |  | 			err:   "expected text in TYPE", | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2018-10-05 00:57:47 +08:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2019-12-24 16:48:28 +08:00
										 |  |  | 			input: "# UNIT metric suffix\n#EOF\n", | 
					
						
							| 
									
										
										
										
											2023-02-03 23:50:15 +08:00
										 |  |  | 			err:   "unit \"suffix\" not a suffix of metric \"metric\"", | 
					
						
							| 
									
										
										
										
											2018-10-05 00:57:47 +08:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2019-12-24 16:48:28 +08:00
										 |  |  | 			input: "# UNIT metricsuffix suffix\n#EOF\n", | 
					
						
							| 
									
										
										
										
											2023-02-03 23:50:15 +08:00
										 |  |  | 			err:   "unit \"suffix\" not a suffix of metric \"metricsuffix\"", | 
					
						
							| 
									
										
										
										
											2018-10-05 00:57:47 +08:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2019-12-24 16:48:28 +08:00
										 |  |  | 			input: "# UNIT m suffix\n#EOF\n", | 
					
						
							| 
									
										
										
										
											2023-02-03 23:50:15 +08:00
										 |  |  | 			err:   "unit \"suffix\" not a suffix of metric \"m\"", | 
					
						
							| 
									
										
										
										
											2018-10-05 00:57:47 +08:00
										 |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2022-03-08 21:04:11 +08:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			input: "# UNIT \n#EOF\n", | 
					
						
							| 
									
										
										
										
											2023-02-03 23:50:15 +08:00
										 |  |  | 			err:   "expected metric name after UNIT, got \"\\n\" (\"INVALID\") while parsing: \"# UNIT \\n\"", | 
					
						
							| 
									
										
										
										
											2022-03-08 21:04:11 +08:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			input: "# UNIT m\n#EOF\n", | 
					
						
							|  |  |  | 			err:   "expected text in UNIT", | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			input: "# HELP \n#EOF\n", | 
					
						
							| 
									
										
										
										
											2023-02-03 23:50:15 +08:00
										 |  |  | 			err:   "expected metric name after HELP, got \"\\n\" (\"INVALID\") while parsing: \"# HELP \\n\"", | 
					
						
							| 
									
										
										
										
											2022-03-08 21:04:11 +08:00
										 |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2018-10-05 00:57:47 +08:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2019-12-24 16:48:28 +08:00
										 |  |  | 			input: "# HELP m\n#EOF\n", | 
					
						
							| 
									
										
										
										
											2022-03-08 21:04:11 +08:00
										 |  |  | 			err:   "expected text in HELP", | 
					
						
							| 
									
										
										
										
											2018-10-05 00:57:47 +08:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2019-12-24 16:48:28 +08:00
										 |  |  | 			input: "a\t1\n#EOF\n", | 
					
						
							| 
									
										
										
										
											2023-02-03 23:50:15 +08:00
										 |  |  | 			err:   "expected value after metric, got \"\\t\" (\"INVALID\") while parsing: \"a\\t\"", | 
					
						
							| 
									
										
										
										
											2018-10-05 00:57:47 +08:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2019-12-24 16:48:28 +08:00
										 |  |  | 			input: "a 1\t2\n#EOF\n", | 
					
						
							| 
									
										
										
										
											2023-02-03 23:50:15 +08:00
										 |  |  | 			err:   "strconv.ParseFloat: parsing \"1\\t2\": invalid syntax while parsing: \"a 1\\t2\"", | 
					
						
							| 
									
										
										
										
											2018-10-05 00:57:47 +08:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2019-12-24 16:48:28 +08:00
										 |  |  | 			input: "a 1 2 \n#EOF\n", | 
					
						
							| 
									
										
										
										
											2023-02-03 23:50:15 +08:00
										 |  |  | 			err:   "expected next entry after timestamp, got \" \\n\" (\"INVALID\") while parsing: \"a 1 2 \\n\"", | 
					
						
							| 
									
										
										
										
											2018-10-05 00:57:47 +08:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2019-12-24 16:48:28 +08:00
										 |  |  | 			input: "a 1 2 #\n#EOF\n", | 
					
						
							| 
									
										
										
										
											2023-02-03 23:50:15 +08:00
										 |  |  | 			err:   "expected next entry after timestamp, got \" #\\n\" (\"TIMESTAMP\") while parsing: \"a 1 2 #\\n\"", | 
					
						
							| 
									
										
										
										
											2018-10-05 00:57:47 +08:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2019-12-24 16:48:28 +08:00
										 |  |  | 			input: "a 1 1z\n#EOF\n", | 
					
						
							| 
									
										
										
										
											2023-02-03 23:50:15 +08:00
										 |  |  | 			err:   "strconv.ParseFloat: parsing \"1z\": invalid syntax while parsing: \"a 1 1z\"", | 
					
						
							| 
									
										
										
										
											2018-10-05 00:57:47 +08:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			input: " # EOF\n", | 
					
						
							| 
									
										
										
										
											2023-02-03 23:50:15 +08:00
										 |  |  | 			err:   "expected a valid start token, got \" \" (\"INVALID\") while parsing: \" \"", | 
					
						
							| 
									
										
										
										
											2018-10-05 00:57:47 +08:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			input: "# EOF\na 1", | 
					
						
							|  |  |  | 			err:   "unexpected data after # EOF", | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			input: "# EOF\n\n", | 
					
						
							|  |  |  | 			err:   "unexpected data after # EOF", | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			input: "# EOFa 1", | 
					
						
							|  |  |  | 			err:   "unexpected data after # EOF", | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			input: "#\tTYPE c counter\n", | 
					
						
							| 
									
										
										
										
											2023-02-03 23:50:15 +08:00
										 |  |  | 			err:   "expected a valid start token, got \"#\\t\" (\"INVALID\") while parsing: \"#\\t\"", | 
					
						
							| 
									
										
										
										
											2018-10-05 00:57:47 +08:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			input: "# TYPE c  counter\n", | 
					
						
							|  |  |  | 			err:   "invalid metric type \" counter\"", | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2019-12-24 16:48:28 +08:00
										 |  |  | 			input: "a 1 1 1\n# EOF\n", | 
					
						
							| 
									
										
										
										
											2023-02-03 23:50:15 +08:00
										 |  |  | 			err:   "expected next entry after timestamp, got \" 1\\n\" (\"TIMESTAMP\") while parsing: \"a 1 1 1\\n\"", | 
					
						
							| 
									
										
										
										
											2018-10-05 00:57:47 +08:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2019-12-24 16:48:28 +08:00
										 |  |  | 			input: "a{b='c'} 1\n# EOF\n", | 
					
						
							| 
									
										
										
										
											2023-02-03 23:50:15 +08:00
										 |  |  | 			err:   "expected label value, got \"'\" (\"INVALID\") while parsing: \"a{b='\"", | 
					
						
							| 
									
										
										
										
											2018-10-05 00:57:47 +08:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2019-12-24 16:48:28 +08:00
										 |  |  | 			input: "a{,b=\"c\"} 1\n# EOF\n", | 
					
						
							| 
									
										
										
										
											2024-02-16 03:25:12 +08:00
										 |  |  | 			err:   "expected label name, got \",b\" (\"COMMA\") while parsing: \"a{,b\"", | 
					
						
							| 
									
										
										
										
											2018-10-05 00:57:47 +08:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2019-12-24 16:48:28 +08:00
										 |  |  | 			input: "a{b=\"c\"d=\"e\"} 1\n# EOF\n", | 
					
						
							| 
									
										
										
										
											2024-02-16 03:25:12 +08:00
										 |  |  | 			err:   "expected comma or brace close, got \"d=\" (\"LNAME\") while parsing: \"a{b=\\\"c\\\"d=\"", | 
					
						
							| 
									
										
										
										
											2018-10-05 00:57:47 +08:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2019-12-24 16:48:28 +08:00
										 |  |  | 			input: "a{b=\"c\",,d=\"e\"} 1\n# EOF\n", | 
					
						
							| 
									
										
										
										
											2023-02-03 23:50:15 +08:00
										 |  |  | 			err:   "expected label name, got \",d\" (\"COMMA\") while parsing: \"a{b=\\\"c\\\",,d\"", | 
					
						
							| 
									
										
										
										
											2018-10-05 00:57:47 +08:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2019-12-24 16:48:28 +08:00
										 |  |  | 			input: "a{b=\n# EOF\n", | 
					
						
							| 
									
										
										
										
											2023-02-03 23:50:15 +08:00
										 |  |  | 			err:   "expected label value, got \"\\n\" (\"INVALID\") while parsing: \"a{b=\\n\"", | 
					
						
							| 
									
										
										
										
											2018-10-05 00:57:47 +08:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2019-12-24 16:48:28 +08:00
										 |  |  | 			input: "a{\xff=\"foo\"} 1\n# EOF\n", | 
					
						
							| 
									
										
										
										
											2024-02-16 03:25:12 +08:00
										 |  |  | 			err:   "expected label name, got \"\\xff\" (\"INVALID\") while parsing: \"a{\\xff\"", | 
					
						
							| 
									
										
										
										
											2018-10-05 00:57:47 +08:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2019-12-24 16:48:28 +08:00
										 |  |  | 			input: "a{b=\"\xff\"} 1\n# EOF\n", | 
					
						
							| 
									
										
										
										
											2023-02-03 23:50:15 +08:00
										 |  |  | 			err:   "invalid UTF-8 label value: \"\\\"\\xff\\\"\"", | 
					
						
							| 
									
										
										
										
											2018-10-05 00:57:47 +08:00
										 |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2024-02-16 03:25:12 +08:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			input: `{"a","b = "c"} | 
					
						
							|  |  |  | # EOF | 
					
						
							|  |  |  | `, | 
					
						
							|  |  |  | 			err: "expected equal, got \"c\\\"\" (\"LNAME\") while parsing: \"{\\\"a\\\",\\\"b = \\\"c\\\"\"", | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			input: `{"a",b\nc="d"} 1 | 
					
						
							|  |  |  | # EOF | 
					
						
							|  |  |  | `, | 
					
						
							|  |  |  | 			err: "expected equal, got \"\\\\\" (\"INVALID\") while parsing: \"{\\\"a\\\",b\\\\\"", | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2018-10-05 00:57:47 +08:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			input: "a true\n", | 
					
						
							| 
									
										
										
										
											2023-02-03 23:50:15 +08:00
										 |  |  | 			err:   "strconv.ParseFloat: parsing \"true\": invalid syntax while parsing: \"a true\"", | 
					
						
							| 
									
										
										
										
											2018-10-05 00:57:47 +08:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2019-12-24 16:48:28 +08:00
										 |  |  | 			input: "something_weird{problem=\"\n# EOF\n", | 
					
						
							| 
									
										
										
										
											2023-02-03 23:50:15 +08:00
										 |  |  | 			err:   "expected label value, got \"\\\"\\n\" (\"INVALID\") while parsing: \"something_weird{problem=\\\"\\n\"", | 
					
						
							| 
									
										
										
										
											2018-10-05 00:57:47 +08:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2019-12-24 16:48:28 +08:00
										 |  |  | 			input: "empty_label_name{=\"\"} 0\n# EOF\n", | 
					
						
							| 
									
										
										
										
											2024-02-16 03:25:12 +08:00
										 |  |  | 			err:   "expected label name, got \"=\\\"\" (\"EQUAL\") while parsing: \"empty_label_name{=\\\"\"", | 
					
						
							| 
									
										
										
										
											2018-10-05 00:57:47 +08:00
										 |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2019-09-05 22:18:18 +08:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2019-12-24 16:48:28 +08:00
										 |  |  | 			input: "foo 1_2\n\n# EOF\n", | 
					
						
							| 
									
										
										
										
											2023-02-03 23:50:15 +08:00
										 |  |  | 			err:   "unsupported character in float while parsing: \"foo 1_2\"", | 
					
						
							| 
									
										
										
										
											2019-09-05 22:18:18 +08:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2019-12-24 16:48:28 +08:00
										 |  |  | 			input: "foo 0x1p-3\n\n# EOF\n", | 
					
						
							| 
									
										
										
										
											2023-02-03 23:50:15 +08:00
										 |  |  | 			err:   "unsupported character in float while parsing: \"foo 0x1p-3\"", | 
					
						
							| 
									
										
										
										
											2019-09-05 22:18:18 +08:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2019-12-24 16:48:28 +08:00
										 |  |  | 			input: "foo 0x1P-3\n\n# EOF\n", | 
					
						
							| 
									
										
										
										
											2023-02-03 23:50:15 +08:00
										 |  |  | 			err:   "unsupported character in float while parsing: \"foo 0x1P-3\"", | 
					
						
							| 
									
										
										
										
											2019-09-05 22:18:18 +08:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2019-12-24 16:48:28 +08:00
										 |  |  | 			input: "foo 0 1_2\n\n# EOF\n", | 
					
						
							| 
									
										
										
										
											2023-02-03 23:50:15 +08:00
										 |  |  | 			err:   "unsupported character in float while parsing: \"foo 0 1_2\"", | 
					
						
							| 
									
										
										
										
											2019-09-05 22:18:18 +08:00
										 |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2019-11-19 17:33:30 +08:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2019-12-24 16:48:28 +08:00
										 |  |  | 			input: "custom_metric_total 1 # {aa=bb}\n# EOF\n", | 
					
						
							| 
									
										
										
										
											2023-02-03 23:50:15 +08:00
										 |  |  | 			err:   "expected label value, got \"b\" (\"INVALID\") while parsing: \"custom_metric_total 1 # {aa=b\"", | 
					
						
							| 
									
										
										
										
											2019-11-19 17:33:30 +08:00
										 |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2019-12-24 16:48:28 +08:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			input: "custom_metric_total 1 # {aa=\"bb\"}\n# EOF\n", | 
					
						
							| 
									
										
										
										
											2023-02-03 23:50:15 +08:00
										 |  |  | 			err:   "expected value after exemplar labels, got \"\\n\" (\"INVALID\") while parsing: \"custom_metric_total 1 # {aa=\\\"bb\\\"}\\n\"", | 
					
						
							| 
									
										
										
										
											2019-12-24 16:48:28 +08:00
										 |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2019-11-19 17:33:30 +08:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			input: `custom_metric_total 1 # {aa="bb"}`, | 
					
						
							| 
									
										
										
										
											2023-02-03 23:50:15 +08:00
										 |  |  | 			err:   "expected value after exemplar labels, got \"}\" (\"EOF\") while parsing: \"custom_metric_total 1 # {aa=\\\"bb\\\"}\"", | 
					
						
							| 
									
										
										
										
											2019-11-19 17:33:30 +08:00
										 |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2024-02-16 03:25:12 +08:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			input: `custom_metric_total 1 # {bb}`, | 
					
						
							|  |  |  | 			err:   "expected label name, got \"}\" (\"BCLOSE\") while parsing: \"custom_metric_total 1 # {bb}\"", | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			input: `custom_metric_total 1 # {bb, a="dd"}`, | 
					
						
							|  |  |  | 			err:   "expected label name, got \", \" (\"COMMA\") while parsing: \"custom_metric_total 1 # {bb, \"", | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2019-11-19 17:33:30 +08:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			input: `custom_metric_total 1 # {aa="bb",,cc="dd"} 1`, | 
					
						
							| 
									
										
										
										
											2023-02-03 23:50:15 +08:00
										 |  |  | 			err:   "expected label name, got \",c\" (\"COMMA\") while parsing: \"custom_metric_total 1 # {aa=\\\"bb\\\",,c\"", | 
					
						
							| 
									
										
										
										
											2019-11-19 17:33:30 +08:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			input: `custom_metric_total 1 # {aa="bb"} 1_2`, | 
					
						
							| 
									
										
										
										
											2023-02-03 23:50:15 +08:00
										 |  |  | 			err:   "unsupported character in float while parsing: \"custom_metric_total 1 # {aa=\\\"bb\\\"} 1_2\"", | 
					
						
							| 
									
										
										
										
											2019-11-19 17:33:30 +08:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			input: `custom_metric_total 1 # {aa="bb"} 0x1p-3`, | 
					
						
							| 
									
										
										
										
											2023-02-03 23:50:15 +08:00
										 |  |  | 			err:   "unsupported character in float while parsing: \"custom_metric_total 1 # {aa=\\\"bb\\\"} 0x1p-3\"", | 
					
						
							| 
									
										
										
										
											2019-11-19 17:33:30 +08:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			input: `custom_metric_total 1 # {aa="bb"} true`, | 
					
						
							| 
									
										
										
										
											2023-02-03 23:50:15 +08:00
										 |  |  | 			err:   "strconv.ParseFloat: parsing \"true\": invalid syntax while parsing: \"custom_metric_total 1 # {aa=\\\"bb\\\"} true\"", | 
					
						
							| 
									
										
										
										
											2019-11-19 17:33:30 +08:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			input: `custom_metric_total 1 # {aa="bb",cc=}`, | 
					
						
							| 
									
										
										
										
											2023-02-03 23:50:15 +08:00
										 |  |  | 			err:   "expected label value, got \"}\" (\"INVALID\") while parsing: \"custom_metric_total 1 # {aa=\\\"bb\\\",cc=}\"", | 
					
						
							| 
									
										
										
										
											2019-11-19 17:33:30 +08:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			input: `custom_metric_total 1 # {aa=\"\xff\"} 9.0`, | 
					
						
							| 
									
										
										
										
											2023-02-03 23:50:15 +08:00
										 |  |  | 			err:   "expected label value, got \"\\\\\" (\"INVALID\") while parsing: \"custom_metric_total 1 # {aa=\\\\\"", | 
					
						
							| 
									
										
										
										
											2019-11-19 17:33:30 +08:00
										 |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2020-03-02 15:18:05 +08:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			input: `{b="c",} 1`, | 
					
						
							| 
									
										
										
										
											2024-02-16 03:25:12 +08:00
										 |  |  | 			err:   "metric name not set while parsing: \"{b=\\\"c\\\",} 1\"", | 
					
						
							| 
									
										
										
										
											2020-03-02 15:18:05 +08:00
										 |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2021-06-29 08:54:50 +08:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			input: `a 1 NaN`, | 
					
						
							| 
									
										
										
										
											2023-02-03 23:50:15 +08:00
										 |  |  | 			err:   `invalid timestamp NaN`, | 
					
						
							| 
									
										
										
										
											2021-06-29 08:54:50 +08:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			input: `a 1 -Inf`, | 
					
						
							| 
									
										
										
										
											2023-02-03 23:50:15 +08:00
										 |  |  | 			err:   `invalid timestamp -Inf`, | 
					
						
							| 
									
										
										
										
											2021-06-29 08:54:50 +08:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			input: `a 1 Inf`, | 
					
						
							| 
									
										
										
										
											2023-02-03 23:50:15 +08:00
										 |  |  | 			err:   `invalid timestamp +Inf`, | 
					
						
							| 
									
										
										
										
											2021-06-29 08:54:50 +08:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			input: "# TYPE hhh histogram\nhhh_bucket{le=\"+Inf\"} 1 # {aa=\"bb\"} 4 NaN", | 
					
						
							| 
									
										
										
										
											2023-02-03 23:50:15 +08:00
										 |  |  | 			err:   `invalid exemplar timestamp NaN`, | 
					
						
							| 
									
										
										
										
											2021-06-29 08:54:50 +08:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			input: "# TYPE hhh histogram\nhhh_bucket{le=\"+Inf\"} 1 # {aa=\"bb\"} 4 -Inf", | 
					
						
							| 
									
										
										
										
											2023-02-03 23:50:15 +08:00
										 |  |  | 			err:   `invalid exemplar timestamp -Inf`, | 
					
						
							| 
									
										
										
										
											2021-06-29 08:54:50 +08:00
										 |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2018-10-05 00:57:47 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for i, c := range cases { | 
					
						
							| 
									
										
										
										
											2024-10-02 18:52:03 +08:00
										 |  |  | 		p := NewOpenMetricsParser([]byte(c.input), labels.NewSymbolTable(), WithOMParserCTSeriesSkipped()) | 
					
						
							| 
									
										
										
										
											2018-10-05 00:57:47 +08:00
										 |  |  | 		var err error | 
					
						
							|  |  |  | 		for err == nil { | 
					
						
							|  |  |  | 			_, err = p.Next() | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2024-10-10 19:01:13 +08:00
										 |  |  | 		require.Equal(t, c.err, err.Error(), "test %d: %s", i, c.input) | 
					
						
							| 
									
										
										
										
											2018-10-05 00:57:47 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func TestOMNullByteHandling(t *testing.T) { | 
					
						
							|  |  |  | 	cases := []struct { | 
					
						
							|  |  |  | 		input string | 
					
						
							|  |  |  | 		err   string | 
					
						
							|  |  |  | 	}{ | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			input: "null_byte_metric{a=\"abc\x00\"} 1\n# EOF\n", | 
					
						
							|  |  |  | 			err:   "", | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			input: "a{b=\"\x00ss\"} 1\n# EOF\n", | 
					
						
							|  |  |  | 			err:   "", | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			input: "a{b=\"\x00\"} 1\n# EOF\n", | 
					
						
							|  |  |  | 			err:   "", | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			input: "a{b=\"\x00\"} 1\n# EOF", | 
					
						
							|  |  |  | 			err:   "", | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			input: "a{b=\x00\"ssss\"} 1\n# EOF\n", | 
					
						
							| 
									
										
										
										
											2023-02-03 23:50:15 +08:00
										 |  |  | 			err:   "expected label value, got \"\\x00\" (\"INVALID\") while parsing: \"a{b=\\x00\"", | 
					
						
							| 
									
										
										
										
											2018-10-05 00:57:47 +08:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			input: "a{b=\"\x00", | 
					
						
							| 
									
										
										
										
											2023-02-03 23:50:15 +08:00
										 |  |  | 			err:   "expected label value, got \"\\\"\\x00\" (\"INVALID\") while parsing: \"a{b=\\\"\\x00\"", | 
					
						
							| 
									
										
										
										
											2018-10-05 00:57:47 +08:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			input: "a{b\x00=\"hiih\"}	1", | 
					
						
							| 
									
										
										
										
											2023-02-03 23:50:15 +08:00
										 |  |  | 			err:   "expected equal, got \"\\x00\" (\"INVALID\") while parsing: \"a{b\\x00\"", | 
					
						
							| 
									
										
										
										
											2018-10-05 00:57:47 +08:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			input: "a\x00{b=\"ddd\"} 1", | 
					
						
							| 
									
										
										
										
											2023-02-03 23:50:15 +08:00
										 |  |  | 			err:   "expected value after metric, got \"\\x00\" (\"INVALID\") while parsing: \"a\\x00\"", | 
					
						
							| 
									
										
										
										
											2018-10-05 00:57:47 +08:00
										 |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2019-08-23 22:44:16 +08:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			input: "#", | 
					
						
							| 
									
										
										
										
											2023-02-03 23:50:15 +08:00
										 |  |  | 			err:   "expected a valid start token, got \"#\" (\"INVALID\") while parsing: \"#\"", | 
					
						
							| 
									
										
										
										
											2019-08-23 22:44:16 +08:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			input: "# H", | 
					
						
							| 
									
										
										
										
											2023-02-03 23:50:15 +08:00
										 |  |  | 			err:   "expected a valid start token, got \"# H\" (\"INVALID\") while parsing: \"# H\"", | 
					
						
							| 
									
										
										
										
											2019-08-23 22:44:16 +08:00
										 |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2019-11-19 17:33:30 +08:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			input: "custom_metric_total 1 # {b=\x00\"ssss\"} 1\n", | 
					
						
							| 
									
										
										
										
											2023-02-03 23:50:15 +08:00
										 |  |  | 			err:   "expected label value, got \"\\x00\" (\"INVALID\") while parsing: \"custom_metric_total 1 # {b=\\x00\"", | 
					
						
							| 
									
										
										
										
											2019-11-19 17:33:30 +08:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			input: "custom_metric_total 1 # {b=\"\x00ss\"} 1\n", | 
					
						
							| 
									
										
										
										
											2023-02-03 23:50:15 +08:00
										 |  |  | 			err:   "expected label value, got \"\\\"\\x00\" (\"INVALID\") while parsing: \"custom_metric_total 1 # {b=\\\"\\x00\"", | 
					
						
							| 
									
										
										
										
											2019-11-19 17:33:30 +08:00
										 |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2018-10-05 00:57:47 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for i, c := range cases { | 
					
						
							| 
									
										
										
										
											2024-10-02 18:52:03 +08:00
										 |  |  | 		p := NewOpenMetricsParser([]byte(c.input), labels.NewSymbolTable(), WithOMParserCTSeriesSkipped()) | 
					
						
							| 
									
										
										
										
											2018-10-05 00:57:47 +08:00
										 |  |  | 		var err error | 
					
						
							|  |  |  | 		for err == nil { | 
					
						
							|  |  |  | 			_, err = p.Next() | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if c.err == "" { | 
					
						
							| 
									
										
										
										
											2024-10-07 00:35:29 +08:00
										 |  |  | 			require.ErrorIs(t, err, io.EOF, "test %d", i) | 
					
						
							| 
									
										
										
										
											2018-10-05 00:57:47 +08:00
										 |  |  | 			continue | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-07 00:35:29 +08:00
										 |  |  | 		require.EqualError(t, err, c.err, "test %d", i) | 
					
						
							| 
									
										
										
										
											2018-10-05 00:57:47 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2024-08-08 19:35:35 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-07 19:17:44 +08:00
										 |  |  | // TestCTParseFailures tests known failure edge cases, we know does not work due
 | 
					
						
							|  |  |  | // current OM spec limitations or clients with broken OM format.
 | 
					
						
							| 
									
										
										
										
											2024-08-08 19:35:35 +08:00
										 |  |  | // TODO(maniktherana): Make sure OM 1.1/2.0 pass CT via metadata or exemplar-like to avoid this.
 | 
					
						
							|  |  |  | func TestCTParseFailures(t *testing.T) { | 
					
						
							| 
									
										
										
										
											2024-10-10 19:01:13 +08:00
										 |  |  | 	for _, tcase := range []struct { | 
					
						
							|  |  |  | 		name     string | 
					
						
							|  |  |  | 		input    string | 
					
						
							|  |  |  | 		expected []parsedEntry | 
					
						
							|  |  |  | 	}{ | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			name: "_created line is a first one", | 
					
						
							|  |  |  | 			input: `# HELP thing histogram with _created as first line | 
					
						
							| 
									
										
										
										
											2024-08-08 19:35:35 +08:00
										 |  |  | # TYPE thing histogram | 
					
						
							| 
									
										
										
										
											2024-10-02 18:52:03 +08:00
										 |  |  | thing_created 1520872607.123 | 
					
						
							| 
									
										
										
										
											2024-08-08 19:35:35 +08:00
										 |  |  | thing_count 17 | 
					
						
							|  |  |  | thing_sum 324789.3 | 
					
						
							|  |  |  | thing_bucket{le="0.0"} 0 | 
					
						
							| 
									
										
										
										
											2024-10-10 19:01:13 +08:00
										 |  |  | thing_bucket{le="+Inf"} 17 | 
					
						
							|  |  |  | # HELP thing_c counter with _created as first line | 
					
						
							|  |  |  | # TYPE thing_c counter | 
					
						
							|  |  |  | thing_c_created 1520872607.123 | 
					
						
							|  |  |  | thing_c_total 14123.232 | 
					
						
							|  |  |  | # EOF | 
					
						
							|  |  |  | `, | 
					
						
							|  |  |  | 			expected: []parsedEntry{ | 
					
						
							|  |  |  | 				{ | 
					
						
							|  |  |  | 					m:    "thing", | 
					
						
							|  |  |  | 					help: "histogram with _created as first line", | 
					
						
							|  |  |  | 				}, | 
					
						
							|  |  |  | 				{ | 
					
						
							|  |  |  | 					m:   "thing", | 
					
						
							|  |  |  | 					typ: model.MetricTypeHistogram, | 
					
						
							|  |  |  | 				}, | 
					
						
							|  |  |  | 				{ | 
					
						
							|  |  |  | 					m:  `thing_count`, | 
					
						
							| 
									
										
										
										
											2025-03-07 20:43:13 +08:00
										 |  |  | 					ct: 0, // Should be int64p(1520872607123).
 | 
					
						
							| 
									
										
										
										
											2024-10-10 19:01:13 +08:00
										 |  |  | 				}, | 
					
						
							|  |  |  | 				{ | 
					
						
							|  |  |  | 					m:  `thing_sum`, | 
					
						
							| 
									
										
										
										
											2025-03-07 20:43:13 +08:00
										 |  |  | 					ct: 0, // Should be int64p(1520872607123).
 | 
					
						
							| 
									
										
										
										
											2024-10-10 19:01:13 +08:00
										 |  |  | 				}, | 
					
						
							|  |  |  | 				{ | 
					
						
							|  |  |  | 					m:  `thing_bucket{le="0.0"}`, | 
					
						
							| 
									
										
										
										
											2025-03-07 20:43:13 +08:00
										 |  |  | 					ct: 0, // Should be int64p(1520872607123).
 | 
					
						
							| 
									
										
										
										
											2024-10-10 19:01:13 +08:00
										 |  |  | 				}, | 
					
						
							|  |  |  | 				{ | 
					
						
							|  |  |  | 					m:  `thing_bucket{le="+Inf"}`, | 
					
						
							| 
									
										
										
										
											2025-03-07 20:43:13 +08:00
										 |  |  | 					ct: 0, // Should be int64p(1520872607123),
 | 
					
						
							| 
									
										
										
										
											2024-10-10 19:01:13 +08:00
										 |  |  | 				}, | 
					
						
							|  |  |  | 				{ | 
					
						
							|  |  |  | 					m:    "thing_c", | 
					
						
							|  |  |  | 					help: "counter with _created as first line", | 
					
						
							|  |  |  | 				}, | 
					
						
							|  |  |  | 				{ | 
					
						
							|  |  |  | 					m:   "thing_c", | 
					
						
							|  |  |  | 					typ: model.MetricTypeCounter, | 
					
						
							|  |  |  | 				}, | 
					
						
							|  |  |  | 				{ | 
					
						
							|  |  |  | 					m:  `thing_c_total`, | 
					
						
							| 
									
										
										
										
											2025-03-07 20:43:13 +08:00
										 |  |  | 					ct: 0, // Should be int64p(1520872607123).
 | 
					
						
							| 
									
										
										
										
											2024-10-10 19:01:13 +08:00
										 |  |  | 				}, | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2024-08-08 19:35:35 +08:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2024-10-10 19:01:13 +08:00
										 |  |  | 			// TODO(bwplotka): Kind of correct bevaviour? If yes, let's move to the OK tests above.
 | 
					
						
							|  |  |  | 			name: "maybe counter with no meta", | 
					
						
							|  |  |  | 			input: `foo_total 17.0 | 
					
						
							|  |  |  | foo_created 1520872607.123 | 
					
						
							|  |  |  | foo_total{a="b"} 17.0 | 
					
						
							|  |  |  | foo_created{a="b"} 1520872608.123 | 
					
						
							|  |  |  | # EOF | 
					
						
							|  |  |  | `, | 
					
						
							|  |  |  | 			expected: []parsedEntry{ | 
					
						
							|  |  |  | 				{ | 
					
						
							|  |  |  | 					m: `foo_total`, | 
					
						
							|  |  |  | 				}, | 
					
						
							|  |  |  | 				{ | 
					
						
							|  |  |  | 					m: `foo_created`, | 
					
						
							|  |  |  | 				}, | 
					
						
							|  |  |  | 				{ | 
					
						
							|  |  |  | 					m: `foo_total{a="b"}`, | 
					
						
							|  |  |  | 				}, | 
					
						
							|  |  |  | 				{ | 
					
						
							|  |  |  | 					m: `foo_created{a="b"}`, | 
					
						
							|  |  |  | 				}, | 
					
						
							|  |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2024-08-08 19:35:35 +08:00
										 |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2024-10-10 19:01:13 +08:00
										 |  |  | 	} { | 
					
						
							|  |  |  | 		t.Run(fmt.Sprintf("case=%v", tcase.name), func(t *testing.T) { | 
					
						
							|  |  |  | 			p := NewOpenMetricsParser([]byte(tcase.input), labels.NewSymbolTable(), WithOMParserCTSeriesSkipped()) | 
					
						
							|  |  |  | 			got := testParse(t, p) | 
					
						
							|  |  |  | 			resetValAndLset(got) // Keep this test focused on metric, basic entries and CT only.
 | 
					
						
							|  |  |  | 			requireEntries(t, tcase.expected, got) | 
					
						
							|  |  |  | 		}) | 
					
						
							| 
									
										
										
										
											2024-08-08 19:35:35 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2024-10-07 19:17:44 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2024-08-08 19:35:35 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-07 19:17:44 +08:00
										 |  |  | func resetValAndLset(e []parsedEntry) { | 
					
						
							|  |  |  | 	for i := range e { | 
					
						
							|  |  |  | 		e[i].v = 0 | 
					
						
							|  |  |  | 		e[i].lset = labels.EmptyLabels() | 
					
						
							| 
									
										
										
										
											2024-08-08 19:35:35 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | } |