1package querier 2 3import ( 4 "context" 5 6 "github.com/grafana/dskit/flagext" 7 "github.com/prometheus/common/model" 8 "github.com/prometheus/prometheus/pkg/labels" 9 "github.com/prometheus/prometheus/scrape" 10 "github.com/stretchr/testify/mock" 11 12 "github.com/cortexproject/cortex/pkg/ingester/client" 13 "github.com/cortexproject/cortex/pkg/prom1/storage/metric" 14 "github.com/cortexproject/cortex/pkg/util/validation" 15) 16 17type MockDistributor struct { 18 mock.Mock 19} 20 21func (m *MockDistributor) Query(ctx context.Context, from, to model.Time, matchers ...*labels.Matcher) (model.Matrix, error) { 22 args := m.Called(ctx, from, to, matchers) 23 return args.Get(0).(model.Matrix), args.Error(1) 24} 25func (m *MockDistributor) QueryExemplars(ctx context.Context, from, to model.Time, matchers ...[]*labels.Matcher) (*client.ExemplarQueryResponse, error) { 26 args := m.Called(ctx, from, to, matchers) 27 return args.Get(0).(*client.ExemplarQueryResponse), args.Error(1) 28} 29func (m *MockDistributor) QueryStream(ctx context.Context, from, to model.Time, matchers ...*labels.Matcher) (*client.QueryStreamResponse, error) { 30 args := m.Called(ctx, from, to, matchers) 31 return args.Get(0).(*client.QueryStreamResponse), args.Error(1) 32} 33func (m *MockDistributor) LabelValuesForLabelName(ctx context.Context, from, to model.Time, lbl model.LabelName, matchers ...*labels.Matcher) ([]string, error) { 34 args := m.Called(ctx, from, to, lbl, matchers) 35 return args.Get(0).([]string), args.Error(1) 36} 37func (m *MockDistributor) LabelNames(ctx context.Context, from, to model.Time) ([]string, error) { 38 args := m.Called(ctx, from, to) 39 return args.Get(0).([]string), args.Error(1) 40} 41func (m *MockDistributor) MetricsForLabelMatchers(ctx context.Context, from, to model.Time, matchers ...*labels.Matcher) ([]metric.Metric, error) { 42 args := m.Called(ctx, from, to, matchers) 43 return args.Get(0).([]metric.Metric), args.Error(1) 44} 45 46func (m *MockDistributor) MetricsMetadata(ctx context.Context) ([]scrape.MetricMetadata, error) { 47 args := m.Called(ctx) 48 return args.Get(0).([]scrape.MetricMetadata), args.Error(1) 49} 50 51type TestConfig struct { 52 Cfg Config 53 Distributor Distributor 54 Stores []QueryableWithFilter 55} 56 57func DefaultQuerierConfig() Config { 58 querierCfg := Config{} 59 flagext.DefaultValues(&querierCfg) 60 return querierCfg 61} 62 63func DefaultLimitsConfig() validation.Limits { 64 limits := validation.Limits{} 65 flagext.DefaultValues(&limits) 66 return limits 67} 68