2017-05-10 02:44:13 -07:00
|
|
|
// Copyright 2017 The Prometheus Authors
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package remote
|
|
|
|
|
|
|
|
import (
|
2017-10-23 03:51:48 -07:00
|
|
|
"context"
|
2019-12-12 12:47:23 -08:00
|
|
|
"io/ioutil"
|
|
|
|
"net/url"
|
|
|
|
"os"
|
2017-05-10 02:44:13 -07:00
|
|
|
"reflect"
|
|
|
|
"sort"
|
|
|
|
"testing"
|
|
|
|
|
2019-12-12 12:47:23 -08:00
|
|
|
config_util "github.com/prometheus/common/config"
|
|
|
|
"github.com/prometheus/prometheus/config"
|
2017-05-10 02:44:13 -07:00
|
|
|
"github.com/prometheus/prometheus/pkg/labels"
|
2017-10-09 05:37:58 -07:00
|
|
|
"github.com/prometheus/prometheus/prompb"
|
|
|
|
"github.com/prometheus/prometheus/storage"
|
2019-12-12 12:47:23 -08:00
|
|
|
"github.com/prometheus/prometheus/util/testutil"
|
2017-05-10 02:44:13 -07:00
|
|
|
)
|
|
|
|
|
2019-12-12 12:47:23 -08:00
|
|
|
func TestNoDuplicateReadConfigs(t *testing.T) {
|
|
|
|
dir, err := ioutil.TempDir("", "TestNoDuplicateReadConfigs")
|
|
|
|
testutil.Ok(t, err)
|
|
|
|
defer os.RemoveAll(dir)
|
|
|
|
|
|
|
|
cfg1 := config.RemoteReadConfig{
|
|
|
|
Name: "write-1",
|
|
|
|
URL: &config_util.URL{
|
|
|
|
URL: &url.URL{
|
|
|
|
Scheme: "http",
|
|
|
|
Host: "localhost",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
cfg2 := config.RemoteReadConfig{
|
|
|
|
Name: "write-2",
|
|
|
|
URL: &config_util.URL{
|
|
|
|
URL: &url.URL{
|
|
|
|
Scheme: "http",
|
|
|
|
Host: "localhost",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
cfg3 := config.RemoteReadConfig{
|
|
|
|
URL: &config_util.URL{
|
|
|
|
URL: &url.URL{
|
|
|
|
Scheme: "http",
|
|
|
|
Host: "localhost",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
type testcase struct {
|
|
|
|
cfgs []*config.RemoteReadConfig
|
|
|
|
err bool
|
|
|
|
}
|
|
|
|
|
|
|
|
cases := []testcase{
|
|
|
|
{ // Duplicates but with different names, we should not get an error.
|
|
|
|
cfgs: []*config.RemoteReadConfig{
|
|
|
|
&cfg1,
|
|
|
|
&cfg2,
|
|
|
|
},
|
|
|
|
err: false,
|
|
|
|
},
|
|
|
|
{ // Duplicates but one with no name, we should not get an error.
|
|
|
|
cfgs: []*config.RemoteReadConfig{
|
|
|
|
&cfg1,
|
|
|
|
&cfg3,
|
|
|
|
},
|
|
|
|
err: false,
|
|
|
|
},
|
|
|
|
{ // Duplicates both with no name, we should get an error.
|
|
|
|
cfgs: []*config.RemoteReadConfig{
|
|
|
|
&cfg3,
|
|
|
|
&cfg3,
|
|
|
|
},
|
|
|
|
err: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range cases {
|
2020-02-03 13:47:03 -08:00
|
|
|
s := NewStorage(nil, nil, nil, dir, defaultFlushDeadline)
|
2019-12-12 12:47:23 -08:00
|
|
|
conf := &config.Config{
|
|
|
|
GlobalConfig: config.DefaultGlobalConfig,
|
|
|
|
RemoteReadConfigs: tc.cfgs,
|
|
|
|
}
|
|
|
|
err := s.ApplyConfig(conf)
|
|
|
|
gotError := err != nil
|
|
|
|
testutil.Equals(t, tc.err, gotError)
|
|
|
|
|
|
|
|
err = s.Close()
|
|
|
|
testutil.Ok(t, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-11 17:15:27 -08:00
|
|
|
func TestExternalLabelsQuerierSelect(t *testing.T) {
|
|
|
|
matchers := []*labels.Matcher{
|
2019-11-18 11:53:33 -08:00
|
|
|
labels.MustNewMatcher(labels.MatchEqual, "job", "api-server"),
|
2017-11-11 17:15:27 -08:00
|
|
|
}
|
|
|
|
q := &externalLabelsQuerier{
|
2019-03-08 08:29:25 -08:00
|
|
|
Querier: mockQuerier{},
|
|
|
|
externalLabels: labels.Labels{
|
|
|
|
{Name: "region", Value: "europe"},
|
|
|
|
},
|
2017-11-11 17:15:27 -08:00
|
|
|
}
|
|
|
|
want := newSeriesSetFilter(mockSeriesSet{}, q.externalLabels)
|
2019-01-02 03:10:13 -08:00
|
|
|
have, _, err := q.Select(nil, matchers...)
|
2017-11-23 04:50:06 -08:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(want, have) {
|
2017-11-11 17:15:27 -08:00
|
|
|
t.Errorf("expected series set %+v, got %+v", want, have)
|
|
|
|
}
|
2019-03-13 03:02:36 -07:00
|
|
|
}
|
2017-11-11 17:15:27 -08:00
|
|
|
|
|
|
|
func TestExternalLabelsQuerierAddExternalLabels(t *testing.T) {
|
2017-05-10 02:44:13 -07:00
|
|
|
tests := []struct {
|
2019-03-08 08:29:25 -08:00
|
|
|
el labels.Labels
|
2017-05-10 02:44:13 -07:00
|
|
|
inMatchers []*labels.Matcher
|
|
|
|
outMatchers []*labels.Matcher
|
2019-03-13 03:02:36 -07:00
|
|
|
added labels.Labels
|
2017-05-10 02:44:13 -07:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
inMatchers: []*labels.Matcher{
|
2019-11-18 11:53:33 -08:00
|
|
|
labels.MustNewMatcher(labels.MatchEqual, "job", "api-server"),
|
2017-05-10 02:44:13 -07:00
|
|
|
},
|
|
|
|
outMatchers: []*labels.Matcher{
|
2019-11-18 11:53:33 -08:00
|
|
|
labels.MustNewMatcher(labels.MatchEqual, "job", "api-server"),
|
2017-05-10 02:44:13 -07:00
|
|
|
},
|
2019-03-13 03:02:36 -07:00
|
|
|
added: labels.Labels{},
|
2017-05-10 02:44:13 -07:00
|
|
|
},
|
|
|
|
{
|
2019-03-08 08:29:25 -08:00
|
|
|
el: labels.Labels{
|
|
|
|
{Name: "dc", Value: "berlin-01"},
|
2019-03-13 03:02:36 -07:00
|
|
|
{Name: "region", Value: "europe"},
|
2019-03-08 08:29:25 -08:00
|
|
|
},
|
2017-05-10 02:44:13 -07:00
|
|
|
inMatchers: []*labels.Matcher{
|
2019-11-18 11:53:33 -08:00
|
|
|
labels.MustNewMatcher(labels.MatchEqual, "job", "api-server"),
|
2017-05-10 02:44:13 -07:00
|
|
|
},
|
|
|
|
outMatchers: []*labels.Matcher{
|
2019-11-18 11:53:33 -08:00
|
|
|
labels.MustNewMatcher(labels.MatchEqual, "job", "api-server"),
|
|
|
|
labels.MustNewMatcher(labels.MatchEqual, "region", "europe"),
|
|
|
|
labels.MustNewMatcher(labels.MatchEqual, "dc", "berlin-01"),
|
2017-05-10 02:44:13 -07:00
|
|
|
},
|
2019-03-13 03:02:36 -07:00
|
|
|
added: labels.Labels{
|
|
|
|
{Name: "dc", Value: "berlin-01"},
|
|
|
|
{Name: "region", Value: "europe"},
|
|
|
|
},
|
2017-05-10 02:44:13 -07:00
|
|
|
},
|
|
|
|
{
|
2019-03-08 08:29:25 -08:00
|
|
|
el: labels.Labels{
|
|
|
|
{Name: "region", Value: "europe"},
|
|
|
|
{Name: "dc", Value: "berlin-01"},
|
|
|
|
},
|
2017-05-10 02:44:13 -07:00
|
|
|
inMatchers: []*labels.Matcher{
|
2019-11-18 11:53:33 -08:00
|
|
|
labels.MustNewMatcher(labels.MatchEqual, "job", "api-server"),
|
|
|
|
labels.MustNewMatcher(labels.MatchEqual, "dc", "munich-02"),
|
2017-05-10 02:44:13 -07:00
|
|
|
},
|
|
|
|
outMatchers: []*labels.Matcher{
|
2019-11-18 11:53:33 -08:00
|
|
|
labels.MustNewMatcher(labels.MatchEqual, "job", "api-server"),
|
|
|
|
labels.MustNewMatcher(labels.MatchEqual, "region", "europe"),
|
|
|
|
labels.MustNewMatcher(labels.MatchEqual, "dc", "munich-02"),
|
2017-05-10 02:44:13 -07:00
|
|
|
},
|
2019-03-13 03:02:36 -07:00
|
|
|
added: labels.Labels{
|
|
|
|
{Name: "region", Value: "europe"},
|
|
|
|
},
|
2017-05-10 02:44:13 -07:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, test := range tests {
|
2017-11-11 17:15:27 -08:00
|
|
|
q := &externalLabelsQuerier{Querier: mockQuerier{}, externalLabels: test.el}
|
2017-05-10 02:44:13 -07:00
|
|
|
matchers, added := q.addExternalLabels(test.inMatchers)
|
|
|
|
|
|
|
|
sort.Slice(test.outMatchers, func(i, j int) bool { return test.outMatchers[i].Name < test.outMatchers[j].Name })
|
|
|
|
sort.Slice(matchers, func(i, j int) bool { return matchers[i].Name < matchers[j].Name })
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(matchers, test.outMatchers) {
|
|
|
|
t.Fatalf("%d. unexpected matchers; want %v, got %v", i, test.outMatchers, matchers)
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(added, test.added) {
|
|
|
|
t.Fatalf("%d. unexpected added labels; want %v, got %v", i, test.added, added)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-10-09 05:37:58 -07:00
|
|
|
|
2017-10-26 05:50:39 -07:00
|
|
|
func TestSeriesSetFilter(t *testing.T) {
|
2017-10-21 00:29:03 -07:00
|
|
|
tests := []struct {
|
2017-10-23 13:28:17 -07:00
|
|
|
in *prompb.QueryResult
|
2019-03-13 03:02:36 -07:00
|
|
|
toRemove labels.Labels
|
2017-10-23 13:28:17 -07:00
|
|
|
|
|
|
|
expected *prompb.QueryResult
|
2017-10-21 00:29:03 -07:00
|
|
|
}{
|
|
|
|
{
|
2019-03-13 03:02:36 -07:00
|
|
|
toRemove: labels.Labels{{Name: "foo", Value: "bar"}},
|
2017-10-23 13:28:17 -07:00
|
|
|
in: &prompb.QueryResult{
|
|
|
|
Timeseries: []*prompb.TimeSeries{
|
2019-08-12 09:22:02 -07:00
|
|
|
{Labels: labelsToLabelsProto(labels.FromStrings("foo", "bar", "a", "b"), nil), Samples: []prompb.Sample{}},
|
2017-10-23 13:28:17 -07:00
|
|
|
},
|
|
|
|
},
|
|
|
|
expected: &prompb.QueryResult{
|
|
|
|
Timeseries: []*prompb.TimeSeries{
|
2019-08-12 09:22:02 -07:00
|
|
|
{Labels: labelsToLabelsProto(labels.FromStrings("a", "b"), nil), Samples: []prompb.Sample{}},
|
2017-10-23 13:28:17 -07:00
|
|
|
},
|
|
|
|
},
|
2017-10-21 00:29:03 -07:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2017-10-23 13:28:17 -07:00
|
|
|
for i, tc := range tests {
|
|
|
|
filtered := newSeriesSetFilter(FromQueryResult(tc.in), tc.toRemove)
|
2018-09-05 06:50:50 -07:00
|
|
|
have, err := ToQueryResult(filtered, 1e6)
|
2017-10-23 13:28:17 -07:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
2017-10-21 00:29:03 -07:00
|
|
|
}
|
|
|
|
|
2017-10-23 13:28:17 -07:00
|
|
|
if !reflect.DeepEqual(have, tc.expected) {
|
|
|
|
t.Fatalf("%d. unexpected labels; want %v, got %v", i, tc.expected, have)
|
|
|
|
}
|
2017-10-09 05:37:58 -07:00
|
|
|
}
|
|
|
|
}
|
2017-10-18 04:08:14 -07:00
|
|
|
|
2017-11-11 17:23:20 -08:00
|
|
|
type mockQuerier struct {
|
2017-11-11 17:15:27 -08:00
|
|
|
ctx context.Context
|
|
|
|
mint, maxt int64
|
2017-10-18 04:08:14 -07:00
|
|
|
|
2017-11-11 17:15:27 -08:00
|
|
|
storage.Querier
|
|
|
|
}
|
|
|
|
|
2017-11-11 17:23:20 -08:00
|
|
|
type mockSeriesSet struct {
|
|
|
|
storage.SeriesSet
|
|
|
|
}
|
|
|
|
|
2019-01-02 03:10:13 -08:00
|
|
|
func (mockQuerier) Select(*storage.SelectParams, ...*labels.Matcher) (storage.SeriesSet, storage.Warnings, error) {
|
2018-11-30 06:27:12 -08:00
|
|
|
return mockSeriesSet{}, nil, nil
|
2017-11-11 17:23:20 -08:00
|
|
|
}
|
|
|
|
|
2017-11-11 17:15:27 -08:00
|
|
|
func TestPreferLocalStorageFilter(t *testing.T) {
|
|
|
|
ctx := context.Background()
|
2017-10-18 04:08:14 -07:00
|
|
|
|
|
|
|
tests := []struct {
|
2017-11-11 17:15:27 -08:00
|
|
|
localStartTime int64
|
|
|
|
mint int64
|
|
|
|
maxt int64
|
|
|
|
querier storage.Querier
|
2017-10-18 04:08:14 -07:00
|
|
|
}{
|
|
|
|
{
|
2017-11-11 17:15:27 -08:00
|
|
|
localStartTime: int64(100),
|
|
|
|
mint: int64(0),
|
|
|
|
maxt: int64(50),
|
2017-11-11 17:23:20 -08:00
|
|
|
querier: mockQuerier{ctx: ctx, mint: 0, maxt: 50},
|
2017-11-11 17:15:27 -08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
localStartTime: int64(20),
|
|
|
|
mint: int64(0),
|
|
|
|
maxt: int64(50),
|
2017-11-11 17:23:20 -08:00
|
|
|
querier: mockQuerier{ctx: ctx, mint: 0, maxt: 20},
|
2017-10-18 04:08:14 -07:00
|
|
|
},
|
|
|
|
{
|
2017-11-11 17:15:27 -08:00
|
|
|
localStartTime: int64(20),
|
|
|
|
mint: int64(30),
|
|
|
|
maxt: int64(50),
|
|
|
|
querier: storage.NoopQuerier(),
|
2017-10-18 04:08:14 -07:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, test := range tests {
|
2017-11-11 17:15:27 -08:00
|
|
|
f := PreferLocalStorageFilter(
|
|
|
|
storage.QueryableFunc(func(ctx context.Context, mint, maxt int64) (storage.Querier, error) {
|
2017-11-11 17:23:20 -08:00
|
|
|
return mockQuerier{ctx: ctx, mint: mint, maxt: maxt}, nil
|
2017-11-11 17:15:27 -08:00
|
|
|
}),
|
|
|
|
func() (int64, error) { return test.localStartTime, nil },
|
|
|
|
)
|
|
|
|
|
|
|
|
q, err := f.Querier(ctx, test.mint, test.maxt)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
2017-10-18 04:08:14 -07:00
|
|
|
}
|
|
|
|
|
2017-11-11 17:15:27 -08:00
|
|
|
if test.querier != q {
|
2020-01-02 06:54:09 -08:00
|
|
|
t.Errorf("%d. expected querier %+v, got %+v", i, test.querier, q)
|
2017-10-18 04:08:14 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-11-11 17:23:20 -08:00
|
|
|
|
|
|
|
func TestRequiredMatchersFilter(t *testing.T) {
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
f := RequiredMatchersFilter(
|
|
|
|
storage.QueryableFunc(func(ctx context.Context, mint, maxt int64) (storage.Querier, error) {
|
|
|
|
return mockQuerier{ctx: ctx, mint: mint, maxt: maxt}, nil
|
|
|
|
}),
|
2019-11-18 11:53:33 -08:00
|
|
|
[]*labels.Matcher{labels.MustNewMatcher(labels.MatchEqual, "special", "label")},
|
2017-11-11 17:23:20 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
want := &requiredMatchersQuerier{
|
|
|
|
Querier: mockQuerier{ctx: ctx, mint: 0, maxt: 50},
|
2019-11-18 11:53:33 -08:00
|
|
|
requiredMatchers: []*labels.Matcher{labels.MustNewMatcher(labels.MatchEqual, "special", "label")},
|
2017-11-11 17:23:20 -08:00
|
|
|
}
|
|
|
|
have, err := f.Querier(ctx, 0, 50)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(want, have) {
|
2020-01-02 06:54:09 -08:00
|
|
|
t.Errorf("expected querier %+v, got %+v", want, have)
|
2017-11-11 17:23:20 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRequiredLabelsQuerierSelect(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
requiredMatchers []*labels.Matcher
|
|
|
|
matchers []*labels.Matcher
|
|
|
|
seriesSet storage.SeriesSet
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
requiredMatchers: []*labels.Matcher{},
|
|
|
|
matchers: []*labels.Matcher{
|
2019-11-18 11:53:33 -08:00
|
|
|
labels.MustNewMatcher(labels.MatchEqual, "special", "label"),
|
2017-11-11 17:23:20 -08:00
|
|
|
},
|
|
|
|
seriesSet: mockSeriesSet{},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
requiredMatchers: []*labels.Matcher{
|
2019-11-18 11:53:33 -08:00
|
|
|
labels.MustNewMatcher(labels.MatchEqual, "special", "label"),
|
2017-11-11 17:23:20 -08:00
|
|
|
},
|
|
|
|
matchers: []*labels.Matcher{
|
2019-11-18 11:53:33 -08:00
|
|
|
labels.MustNewMatcher(labels.MatchEqual, "special", "label"),
|
2017-11-11 17:23:20 -08:00
|
|
|
},
|
|
|
|
seriesSet: mockSeriesSet{},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
requiredMatchers: []*labels.Matcher{
|
2019-11-18 11:53:33 -08:00
|
|
|
labels.MustNewMatcher(labels.MatchEqual, "special", "label"),
|
2017-11-11 17:23:20 -08:00
|
|
|
},
|
|
|
|
matchers: []*labels.Matcher{
|
2019-11-18 11:53:33 -08:00
|
|
|
labels.MustNewMatcher(labels.MatchRegexp, "special", "label"),
|
2017-11-11 17:23:20 -08:00
|
|
|
},
|
|
|
|
seriesSet: storage.NoopSeriesSet(),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
requiredMatchers: []*labels.Matcher{
|
2019-11-18 11:53:33 -08:00
|
|
|
labels.MustNewMatcher(labels.MatchEqual, "special", "label"),
|
2017-11-11 17:23:20 -08:00
|
|
|
},
|
|
|
|
matchers: []*labels.Matcher{
|
2019-11-18 11:53:33 -08:00
|
|
|
labels.MustNewMatcher(labels.MatchEqual, "special", "different"),
|
2017-11-11 17:23:20 -08:00
|
|
|
},
|
|
|
|
seriesSet: storage.NoopSeriesSet(),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
requiredMatchers: []*labels.Matcher{
|
2019-11-18 11:53:33 -08:00
|
|
|
labels.MustNewMatcher(labels.MatchEqual, "special", "label"),
|
2017-11-11 17:23:20 -08:00
|
|
|
},
|
|
|
|
matchers: []*labels.Matcher{
|
2019-11-18 11:53:33 -08:00
|
|
|
labels.MustNewMatcher(labels.MatchEqual, "special", "label"),
|
|
|
|
labels.MustNewMatcher(labels.MatchEqual, "foo", "bar"),
|
2017-11-11 17:23:20 -08:00
|
|
|
},
|
|
|
|
seriesSet: mockSeriesSet{},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
requiredMatchers: []*labels.Matcher{
|
2019-11-18 11:53:33 -08:00
|
|
|
labels.MustNewMatcher(labels.MatchEqual, "special", "label"),
|
|
|
|
labels.MustNewMatcher(labels.MatchEqual, "foo", "bar"),
|
2017-11-11 17:23:20 -08:00
|
|
|
},
|
|
|
|
matchers: []*labels.Matcher{
|
2019-11-18 11:53:33 -08:00
|
|
|
labels.MustNewMatcher(labels.MatchEqual, "special", "label"),
|
|
|
|
labels.MustNewMatcher(labels.MatchEqual, "foo", "baz"),
|
2017-11-11 17:23:20 -08:00
|
|
|
},
|
|
|
|
seriesSet: storage.NoopSeriesSet(),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
requiredMatchers: []*labels.Matcher{
|
2019-11-18 11:53:33 -08:00
|
|
|
labels.MustNewMatcher(labels.MatchEqual, "special", "label"),
|
|
|
|
labels.MustNewMatcher(labels.MatchEqual, "foo", "bar"),
|
2017-11-11 17:23:20 -08:00
|
|
|
},
|
|
|
|
matchers: []*labels.Matcher{
|
2019-11-18 11:53:33 -08:00
|
|
|
labels.MustNewMatcher(labels.MatchEqual, "special", "label"),
|
|
|
|
labels.MustNewMatcher(labels.MatchEqual, "foo", "bar"),
|
2017-11-11 17:23:20 -08:00
|
|
|
},
|
|
|
|
seriesSet: mockSeriesSet{},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, test := range tests {
|
|
|
|
q := &requiredMatchersQuerier{
|
|
|
|
Querier: mockQuerier{},
|
|
|
|
requiredMatchers: test.requiredMatchers,
|
|
|
|
}
|
|
|
|
|
2019-01-02 03:10:13 -08:00
|
|
|
have, _, err := q.Select(nil, test.matchers...)
|
2017-11-23 04:50:06 -08:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
if want := test.seriesSet; want != have {
|
2017-11-11 17:23:20 -08:00
|
|
|
t.Errorf("%d. expected series set %+v, got %+v", i, want, have)
|
|
|
|
}
|
|
|
|
if want, have := test.requiredMatchers, q.requiredMatchers; !reflect.DeepEqual(want, have) {
|
|
|
|
t.Errorf("%d. requiredMatchersQuerier.Select() has modified the matchers", i)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|