Fix OpenMetrics parser to sort uppercase labels correctly. (#10510)

Signed-off-by: Peter Štibraný <pstibrany@gmail.com>
pull/10511/head
Peter Štibraný 3 years ago committed by GitHub
parent ed0c68224e
commit cd18da3605
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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]}) *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 // Sort labels.
// already at the right place. sort.Sort(*l)
sort.Sort((*l)[1:])
return s return s
} }

@ -52,6 +52,7 @@ ii{foo="bar"} 1
# TYPE ss stateset # TYPE ss stateset
ss{ss="foo"} 1 ss{ss="foo"} 1
ss{ss="bar"} 0 ss{ss="bar"} 0
ss{A="a"} 0
# TYPE un unknown # TYPE un unknown
_metric_starting_with_underscore 1 _metric_starting_with_underscore 1
testmetric{_label_starting_with_underscore="foo"} 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"}`, m: `ss{ss="bar"}`,
v: 0, v: 0,
lset: labels.FromStrings("__name__", "ss", "ss", "bar"), lset: labels.FromStrings("__name__", "ss", "ss", "bar"),
}, {
m: `ss{A="a"}`,
v: 0,
lset: labels.FromStrings("A", "a", "__name__", "ss"),
}, { }, {
m: "un", m: "un",
typ: MetricTypeUnknown, typ: MetricTypeUnknown,

Loading…
Cancel
Save