diff --git a/querier.go b/querier.go index 26f839be1f..85bb7e75f3 100644 --- a/querier.go +++ b/querier.go @@ -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) diff --git a/querier_test.go b/querier_test.go index 8e1a6f7364..19644257d0 100644 --- a/querier_test.go +++ b/querier_test.go @@ -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. diff --git a/reader.go b/reader.go index 4621e87d4b..b4faeb4c98 100644 --- a/reader.go +++ b/reader.go @@ -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")