(t *testing.T)
| 62 | } |
| 63 | |
| 64 | func TestEngine_Switch(t *testing.T) { |
| 65 | ctx := context.Background() |
| 66 | reg := prometheus.NewRegistry() |
| 67 | |
| 68 | now := time.Now() |
| 69 | start := time.Now().Add(-time.Minute * 5) |
| 70 | step := time.Minute |
| 71 | queryable := promqltest.LoadedStorage(t, "") |
| 72 | opts := promql.EngineOpts{ |
| 73 | Logger: utillog.GoKitLogToSlog(log.NewNopLogger()), |
| 74 | Reg: reg, |
| 75 | } |
| 76 | queryEngine := New(opts, ThanosEngineConfig{Enabled: true}, reg) |
| 77 | |
| 78 | // Query Prometheus engine |
| 79 | r := &http.Request{Header: http.Header{}} |
| 80 | r.Header.Set(TypeHeader, string(Prometheus)) |
| 81 | ctx = AddEngineTypeToContext(ctx, r) |
| 82 | _, _ = queryEngine.NewInstantQuery(ctx, queryable, nil, "foo", now) |
| 83 | _, _ = queryEngine.NewRangeQuery(ctx, queryable, nil, "foo", start, now, step) |
| 84 | |
| 85 | require.NoError(t, testutil.GatherAndCompare(reg, bytes.NewBufferString(` |
| 86 | # HELP cortex_engine_switch_queries_total Total number of queries where engine_type is set explicitly |
| 87 | # TYPE cortex_engine_switch_queries_total counter |
| 88 | cortex_engine_switch_queries_total{engine_type="prometheus"} 2 |
| 89 | `), "cortex_engine_switch_queries_total")) |
| 90 | |
| 91 | // Query Thanos engine |
| 92 | r.Header.Set(TypeHeader, string(Thanos)) |
| 93 | ctx = AddEngineTypeToContext(ctx, r) |
| 94 | _, _ = queryEngine.NewInstantQuery(ctx, queryable, nil, "foo", now) |
| 95 | _, _ = queryEngine.NewRangeQuery(ctx, queryable, nil, "foo", start, now, step) |
| 96 | |
| 97 | require.NoError(t, testutil.GatherAndCompare(reg, bytes.NewBufferString(` |
| 98 | # HELP cortex_engine_switch_queries_total Total number of queries where engine_type is set explicitly |
| 99 | # TYPE cortex_engine_switch_queries_total counter |
| 100 | cortex_engine_switch_queries_total{engine_type="prometheus"} 2 |
| 101 | cortex_engine_switch_queries_total{engine_type="thanos"} 2 |
| 102 | `), "cortex_engine_switch_queries_total")) |
| 103 | } |
| 104 | |
| 105 | func TestEngine_XFunctions(t *testing.T) { |
| 106 | ctx := context.Background() |
nothing calls this directly
no test coverage detected