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

Method Query

pkg/testexporter/correctness/simple.go:93–138  ·  view source on GitHub ↗
(ctx context.Context, client v1.API, selectors string, start time.Time, duration time.Duration)

Source from the content-addressed store, hash-verified

91}
92
93func (tc *simpleTestCase) Query(ctx context.Context, client v1.API, selectors string, start time.Time, duration time.Duration) ([]model.SamplePair, error) {
94 log, ctx := spanlogger.New(ctx, "simpleTestCase.Query")
95 defer log.Finish()
96
97 metricName := prometheus.BuildFQName(namespace, subsystem, tc.name)
98 query := fmt.Sprintf("%s{%s}[%dm]", metricName, selectors, duration/time.Minute)
99 level.Info(log).Log("query", query)
100
101 value, wrngs, err := client.Query(ctx, query, start)
102 if err != nil {
103 return nil, err
104 }
105 if wrngs != nil {
106 level.Warn(log).Log(
107 "query", query,
108 "start", start,
109 "warnings", wrngs,
110 )
111 }
112 if value.Type() != model.ValMatrix {
113 return nil, fmt.Errorf("didn't get matrix from Prom")
114 }
115
116 ms, ok := value.(model.Matrix)
117 if !ok {
118 return nil, fmt.Errorf("didn't get matrix from Prom")
119 }
120
121 // sort samples belonging to different series by first timestamp of the batch
122 sort.Slice(ms, func(i, j int) bool {
123 if len(ms[i].Values) == 0 {
124 return true
125 }
126 if len(ms[j].Values) == 0 {
127 return true
128 }
129
130 return ms[i].Values[0].Timestamp.Before(ms[j].Values[0].Timestamp)
131 })
132
133 var result []model.SamplePair
134 for _, stream := range ms {
135 result = append(result, stream.Values...)
136 }
137 return result, nil
138}
139
140func (tc *simpleTestCase) Test(ctx context.Context, client v1.API, selectors string, start time.Time, duration time.Duration) (bool, error) {
141 log := spanlogger.FromContext(ctx)

Callers 1

TestMethod · 0.95

Calls 6

NewFunction · 0.92
FinishMethod · 0.80
TypeMethod · 0.80
BeforeMethod · 0.80
QueryMethod · 0.65
LogMethod · 0.45

Tested by

no test coverage detected