| 87 | } |
| 88 | |
| 89 | func (qf *Engine) NewInstantQuery(ctx context.Context, q storage.Queryable, opts promql.QueryOpts, qs string, ts time.Time) (promql.Query, error) { |
| 90 | if engineType := GetEngineType(ctx); engineType == Prometheus { |
| 91 | qf.engineSwitchQueriesTotal.WithLabelValues(string(Prometheus)).Inc() |
| 92 | goto prom |
| 93 | } else if engineType == Thanos { |
| 94 | qf.engineSwitchQueriesTotal.WithLabelValues(string(Thanos)).Inc() |
| 95 | } |
| 96 | |
| 97 | if qf.thanosEngine != nil { |
| 98 | res, err := qf.thanosEngine.MakeInstantQuery(ctx, q, fromPromQLOpts(opts), qs, ts) |
| 99 | if err != nil { |
| 100 | if thanosengine.IsUnimplemented(err) { |
| 101 | // fallback to use prometheus engine |
| 102 | qf.fallbackQueriesTotal.Inc() |
| 103 | goto prom |
| 104 | } |
| 105 | return nil, err |
| 106 | } |
| 107 | return res, nil |
| 108 | } |
| 109 | |
| 110 | prom: |
| 111 | return qf.prometheusEngine.NewInstantQuery(ctx, q, opts, qs, ts) |
| 112 | } |
| 113 | |
| 114 | func (qf *Engine) NewRangeQuery(ctx context.Context, q storage.Queryable, opts promql.QueryOpts, qs string, start, end time.Time, interval time.Duration) (promql.Query, error) { |
| 115 | if engineType := GetEngineType(ctx); engineType == Prometheus { |