MCPcopy Index your code
hub / github.com/cortexproject/cortex / TestEngine_Fallback

Function TestEngine_Fallback

pkg/engine/engine_test.go:26–62  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

24)
25
26func TestEngine_Fallback(t *testing.T) {
27 // add unimplemented function
28 parser.Functions["unimplemented"] = &parser.Function{
29 Name: "unimplemented",
30 ArgTypes: []parser.ValueType{parser.ValueTypeVector},
31 ReturnType: parser.ValueTypeVector,
32 }
33
34 ctx := context.Background()
35 reg := prometheus.NewRegistry()
36
37 now := time.Now()
38 start := time.Now().Add(-time.Minute * 5)
39 step := time.Minute
40 queryable := promqltest.LoadedStorage(t, "")
41 opts := promql.EngineOpts{
42 Logger: utillog.GoKitLogToSlog(log.NewNopLogger()),
43 Reg: reg,
44 }
45 queryEngine := New(opts, ThanosEngineConfig{Enabled: true}, reg)
46
47 // instant query, should go to fallback
48 _, _ = queryEngine.NewInstantQuery(ctx, queryable, nil, "unimplemented(foo)", now)
49 require.NoError(t, testutil.GatherAndCompare(reg, bytes.NewBufferString(`
50 # HELP cortex_thanos_engine_fallback_queries_total Total number of fallback queries due to not implementation in thanos engine
51 # TYPE cortex_thanos_engine_fallback_queries_total counter
52 cortex_thanos_engine_fallback_queries_total 1
53 `), "cortex_thanos_engine_fallback_queries_total"))
54
55 // range query, should go to fallback
56 _, _ = queryEngine.NewRangeQuery(ctx, queryable, nil, "unimplemented(foo)", start, now, step)
57 require.NoError(t, testutil.GatherAndCompare(reg, bytes.NewBufferString(`
58 # HELP cortex_thanos_engine_fallback_queries_total Total number of fallback queries due to not implementation in thanos engine
59 # TYPE cortex_thanos_engine_fallback_queries_total counter
60 cortex_thanos_engine_fallback_queries_total 2
61 `), "cortex_thanos_engine_fallback_queries_total"))
62}
63
64func TestEngine_Switch(t *testing.T) {
65 ctx := context.Background()

Callers

nothing calls this directly

Calls 4

NewInstantQueryMethod · 0.80
NewRangeQueryMethod · 0.80
NewFunction · 0.70
AddMethod · 0.45

Tested by

no test coverage detected