Fix labels comparison, fetch correct labels

This commit is contained in:
Fabian Reinartz 2016-12-20 14:54:52 +01:00
parent ce7f4106c2
commit cddc29fa17
3 changed files with 17 additions and 1 deletions

View file

@ -370,6 +370,9 @@ func compareLabels(a, b Labels) int {
if d := strings.Compare(a[i].Name, b[i].Name); d != 0 {
return d
}
if d := strings.Compare(a[i].Value, b[i].Value); d != 0 {
return d
}
}
// If all labels so far were in common, the set with fewer labels comes first.
return len(a) - len(b)

View file

@ -211,6 +211,19 @@ func TestCompareLabels(t *testing.T) {
b: []Label{{"aa", ""}, {"ab", ""}},
res: 1,
},
{
a: []Label{
{"__name__", "go_gc_duration_seconds"},
{"job", "prometheus"},
{"quantile", "0.75"},
},
b: []Label{
{"__name__", "go_gc_duration_seconds"},
{"job", "prometheus"},
{"quantile", "1"},
},
res: -1,
},
}
for _, c := range cases {
// Use constructor to ensure sortedness.

View file

@ -271,7 +271,7 @@ func (r *indexReader) Series(ref uint32, mint, maxt int64) (Series, error) {
// the underlying strings.
labels := make(Labels, 0, k)
for i := 0; i < int(k); i += 2 {
for i := 0; i < len(offsets); i += 2 {
n, err := r.lookupSymbol(offsets[i])
if err != nil {
return nil, errors.Wrap(err, "symbol lookup")