mirror of
https://github.com/prometheus/prometheus.git
synced 2025-02-01 16:11:11 -08:00
Add suggestions to labelValues test
Signed-off-by: Jesus Vazquez <jesus.vazquez@grafana.com>
This commit is contained in:
parent
14ec85d4d2
commit
6bff0d9113
|
@ -367,41 +367,88 @@ func TestOOOHeadChunkReader_LabelValues(t *testing.T) {
|
|||
|
||||
// Add in-order samples
|
||||
_, err := app.Append(0, labels.Labels{
|
||||
{Name: "foo", Value: fmt.Sprintf("bar1")},
|
||||
{Name: "foo", Value: "bar1"},
|
||||
}, 100, 1)
|
||||
require.NoError(t, err)
|
||||
_, err = app.Append(0, labels.Labels{
|
||||
{Name: "foo", Value: fmt.Sprintf("bar2")},
|
||||
{Name: "foo", Value: "bar2"},
|
||||
}, 100, 2)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Add ooo samples for those series
|
||||
_, err = app.Append(0, labels.Labels{
|
||||
{Name: "foo", Value: fmt.Sprintf("bar1")},
|
||||
{Name: "foo", Value: "bar1"},
|
||||
}, 90, 1)
|
||||
require.NoError(t, err)
|
||||
_, err = app.Append(0, labels.Labels{
|
||||
{Name: "foo", Value: fmt.Sprintf("bar2")},
|
||||
{Name: "foo", Value: "bar2"},
|
||||
}, 90, 2)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.NoError(t, app.Commit())
|
||||
|
||||
oh := NewOOOHeadIndexReader(head, math.MinInt64, math.MaxInt64)
|
||||
matchers := []*labels.Matcher{labels.MustNewMatcher(labels.MatchEqual, "foo", "bar1")}
|
||||
values, err := oh.LabelValues("foo", matchers...)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, []string{"bar1"}, values)
|
||||
cases := []struct {
|
||||
name string
|
||||
queryMinT int64
|
||||
queryMaxT int64
|
||||
expValues1 []string
|
||||
expValues2 []string
|
||||
expValues3 []string
|
||||
expValues4 []string
|
||||
}{
|
||||
{
|
||||
name: "LabelValues calls when ooo head has max query range",
|
||||
queryMinT: math.MinInt64,
|
||||
queryMaxT: math.MaxInt64,
|
||||
expValues1: []string{"bar1"},
|
||||
expValues2: []string{},
|
||||
expValues3: []string{"bar1", "bar2"},
|
||||
expValues4: []string{"bar1", "bar2"},
|
||||
},
|
||||
{
|
||||
name: "LabelValues calls with ooo head query range not overlapping in-order data",
|
||||
queryMinT: 90,
|
||||
queryMaxT: 90,
|
||||
expValues1: []string{"bar1"},
|
||||
expValues2: []string{},
|
||||
expValues3: []string{"bar1", "bar2"},
|
||||
expValues4: []string{"bar1", "bar2"},
|
||||
},
|
||||
{
|
||||
name: "LabelValues calls with ooo head query range not overlapping out-of-order data",
|
||||
queryMinT: 100,
|
||||
queryMaxT: 100,
|
||||
expValues1: []string{},
|
||||
expValues2: []string{},
|
||||
expValues3: []string{},
|
||||
expValues4: []string{},
|
||||
},
|
||||
}
|
||||
|
||||
matchers = []*labels.Matcher{labels.MustNewMatcher(labels.MatchNotRegexp, "foo", "^bar.")}
|
||||
values, err = oh.LabelValues("foo", matchers...)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, []string{}, values)
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
// We first want to test using a head index reader that covers the biggest query interval
|
||||
oh := NewOOOHeadIndexReader(head, tc.queryMinT, tc.queryMaxT)
|
||||
matchers := []*labels.Matcher{labels.MustNewMatcher(labels.MatchEqual, "foo", "bar1")}
|
||||
values, err := oh.LabelValues("foo", matchers...)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, tc.expValues1, values)
|
||||
|
||||
matchers = []*labels.Matcher{labels.MustNewMatcher(labels.MatchRegexp, "foo", "bar.")}
|
||||
values, err = oh.LabelValues("foo", matchers...)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, []string{"bar1", "bar2"}, values)
|
||||
matchers = []*labels.Matcher{labels.MustNewMatcher(labels.MatchNotRegexp, "foo", "^bar.")}
|
||||
values, err = oh.LabelValues("foo", matchers...)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, tc.expValues2, values)
|
||||
|
||||
matchers = []*labels.Matcher{labels.MustNewMatcher(labels.MatchRegexp, "foo", "bar.")}
|
||||
values, err = oh.LabelValues("foo", matchers...)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, tc.expValues3, values)
|
||||
|
||||
values, err = oh.LabelValues("foo")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, tc.expValues4, values)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestOOOHeadChunkReader_Chunk tests that the Chunk method works as expected.
|
||||
|
|
Loading…
Reference in a new issue