MCPcopy Create free account
hub / github.com/cortexproject/cortex / Test_Ingester_Query

Function Test_Ingester_Query

pkg/ingester/ingester_test.go:3189–3318  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

3187}
3188
3189func Test_Ingester_Query(t *testing.T) {
3190 series := []struct {
3191 lbls labels.Labels
3192 value float64
3193 timestamp int64
3194 }{
3195 {labels.FromStrings("__name__", "test_1", "route", "get_user", "status", "200"), 1, 100000},
3196 {labels.FromStrings("__name__", "test_1", "route", "get_user", "status", "500"), 1, 110000},
3197 {labels.FromStrings("__name__", "test_2"), 2, 200000},
3198 }
3199
3200 tests := map[string]struct {
3201 from int64
3202 to int64
3203 matchers []*client.LabelMatcher
3204 expected []cortexpb.TimeSeries
3205 }{
3206 "should return an empty response if no metric matches": {
3207 from: math.MinInt64,
3208 to: math.MaxInt64,
3209 matchers: []*client.LabelMatcher{
3210 {Type: client.EQUAL, Name: model.MetricNameLabel, Value: "unknown"},
3211 },
3212 expected: []cortexpb.TimeSeries{},
3213 },
3214 "should filter series by == matcher": {
3215 from: math.MinInt64,
3216 to: math.MaxInt64,
3217 matchers: []*client.LabelMatcher{
3218 {Type: client.EQUAL, Name: model.MetricNameLabel, Value: "test_1"},
3219 },
3220 expected: []cortexpb.TimeSeries{
3221 {Labels: cortexpb.FromLabelsToLabelAdapters(series[0].lbls), Samples: []cortexpb.Sample{{Value: 1, TimestampMs: 100000}}},
3222 {Labels: cortexpb.FromLabelsToLabelAdapters(series[1].lbls), Samples: []cortexpb.Sample{{Value: 1, TimestampMs: 110000}}},
3223 },
3224 },
3225 "should filter series by != matcher": {
3226 from: math.MinInt64,
3227 to: math.MaxInt64,
3228 matchers: []*client.LabelMatcher{
3229 {Type: client.NOT_EQUAL, Name: model.MetricNameLabel, Value: "test_1"},
3230 },
3231 expected: []cortexpb.TimeSeries{
3232 {Labels: cortexpb.FromLabelsToLabelAdapters(series[2].lbls), Samples: []cortexpb.Sample{{Value: 2, TimestampMs: 200000}}},
3233 },
3234 },
3235 "should filter series by =~ matcher": {
3236 from: math.MinInt64,
3237 to: math.MaxInt64,
3238 matchers: []*client.LabelMatcher{
3239 {Type: client.REGEX_MATCH, Name: model.MetricNameLabel, Value: ".*_1"},
3240 },
3241 expected: []cortexpb.TimeSeries{
3242 {Labels: cortexpb.FromLabelsToLabelAdapters(series[0].lbls), Samples: []cortexpb.Sample{{Value: 1, TimestampMs: 100000}}},
3243 {Labels: cortexpb.FromLabelsToLabelAdapters(series[1].lbls), Samples: []cortexpb.Sample{{Value: 1, TimestampMs: 110000}}},
3244 },
3245 },
3246 "should filter series by !~ matcher": {

Callers

nothing calls this directly

Calls 13

StartAndAwaitRunningFunction · 0.92
StopAndAwaitTerminatedFunction · 0.92
PollFunction · 0.92
SeriesSetToQueryResponseFunction · 0.92
mockWriteRequestFunction · 0.70
PushMethod · 0.65
RunMethod · 0.65
QueryStreamMethod · 0.65

Tested by

no test coverage detected