(t *testing.T)
| 24 | ) |
| 25 | |
| 26 | func 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 | |
| 64 | func TestEngine_Switch(t *testing.T) { |
| 65 | ctx := context.Background() |
nothing calls this directly
no test coverage detected