mirror of
https://github.com/prometheus/prometheus.git
synced 2025-08-06 22:27:17 +02:00
Merge pull request #14923 from prometheus/njpm/fix-mockIndex
tsdb tests: fix `mockIndex` implementation of `LabelValues` and `LabelNames`
This commit is contained in:
commit
f1c6fab7e1
@ -20,6 +20,7 @@ import (
|
|||||||
"math"
|
"math"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"slices"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
@ -2274,15 +2275,19 @@ func (m mockIndex) LabelValues(_ context.Context, name string, hints *storage.La
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, series := range m.series {
|
for _, series := range m.series {
|
||||||
|
matches := true
|
||||||
for _, matcher := range matchers {
|
for _, matcher := range matchers {
|
||||||
if matcher.Matches(series.l.Get(matcher.Name)) {
|
matches = matches && matcher.Matches(series.l.Get(matcher.Name))
|
||||||
// TODO(colega): shouldn't we check all the matchers before adding this to the values?
|
if !matches {
|
||||||
values = append(values, series.l.Get(name))
|
break
|
||||||
if hints != nil && hints.Limit > 0 && len(values) >= hints.Limit {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if matches && !slices.Contains(values, series.l.Get(name)) {
|
||||||
|
values = append(values, series.l.Get(name))
|
||||||
|
}
|
||||||
|
if hints != nil && hints.Limit > 0 && len(values) >= hints.Limit {
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return values, nil
|
return values, nil
|
||||||
@ -2392,7 +2397,7 @@ func (m mockIndex) LabelNames(_ context.Context, matchers ...*labels.Matcher) ([
|
|||||||
for _, series := range m.series {
|
for _, series := range m.series {
|
||||||
matches := true
|
matches := true
|
||||||
for _, matcher := range matchers {
|
for _, matcher := range matchers {
|
||||||
matches = matches || matcher.Matches(series.l.Get(matcher.Name))
|
matches = matches && matcher.Matches(series.l.Get(matcher.Name))
|
||||||
if !matches {
|
if !matches {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user