From cd18da36058aee37c237d765864a1a59f263bb96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20=C5=A0tibran=C3=BD?= Date: Thu, 31 Mar 2022 20:18:53 +0200 Subject: [PATCH] Fix OpenMetrics parser to sort uppercase labels correctly. (#10510) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Peter Štibraný --- model/textparse/openmetricsparse.go | 5 ++--- model/textparse/openmetricsparse_test.go | 5 +++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/model/textparse/openmetricsparse.go b/model/textparse/openmetricsparse.go index 38656e519..6c5fde78c 100644 --- a/model/textparse/openmetricsparse.go +++ b/model/textparse/openmetricsparse.go @@ -175,9 +175,8 @@ func (p *OpenMetricsParser) Metric(l *labels.Labels) string { *l = append(*l, labels.Label{Name: s[a:b], Value: s[c:d]}) } - // Sort labels. We can skip the first entry since the metric name is - // already at the right place. - sort.Sort((*l)[1:]) + // Sort labels. + sort.Sort(*l) return s } diff --git a/model/textparse/openmetricsparse_test.go b/model/textparse/openmetricsparse_test.go index 534dc6082..350523829 100644 --- a/model/textparse/openmetricsparse_test.go +++ b/model/textparse/openmetricsparse_test.go @@ -52,6 +52,7 @@ ii{foo="bar"} 1 # TYPE ss stateset ss{ss="foo"} 1 ss{ss="bar"} 0 +ss{A="a"} 0 # TYPE un unknown _metric_starting_with_underscore 1 testmetric{_label_starting_with_underscore="foo"} 1 @@ -177,6 +178,10 @@ foo_total 17.0 1520879607.789 # {xx="yy"} 5` m: `ss{ss="bar"}`, v: 0, lset: labels.FromStrings("__name__", "ss", "ss", "bar"), + }, { + m: `ss{A="a"}`, + v: 0, + lset: labels.FromStrings("A", "a", "__name__", "ss"), }, { m: "un", typ: MetricTypeUnknown,