Skip to content

Commit

Permalink
Add FallbackEngine to engine options (#228)
Browse files Browse the repository at this point in the history
Updates the compatibility engine constructor to create an
engine, using the fallback engine provided in the options.

Since promql-engine is in early days and doesnt have any major
versions, it is finalized to use orignal function and add engine
to options.

Changes `prom` in `compatibilityEngine` to `v1.QueryEngine` type
from `promql.Engine`. Since, prom is an fallback engine and any
`QueryEngine` must work with in prom. Also, when thanos creates
a engine it get type casted into `v1.QueryEngine`, that can't
be passed to this constructor as an fallback engine option.

Signed-off-by: Pradyumna Krishna <git@onpy.in>
  • Loading branch information
PradyumnaKrishna committed Apr 8, 2023
1 parent c360ab4 commit 190e5c3
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ type Opts struct {
// EnableXFunctions enables custom xRate, xIncrease and xDelta functions.
// This will default to false.
EnableXFunctions bool

// FallbackEngine
Engine v1.QueryEngine
}

func (o Opts) getLogicalOptimizers() []logicalplan.Optimizer {
Expand Down Expand Up @@ -193,8 +196,15 @@ func New(opts Opts) *compatibilityEngine {
),
}

var engine v1.QueryEngine
if opts.Engine == nil {
engine = promql.NewEngine(opts.EngineOpts)
} else {
engine = opts.Engine
}

return &compatibilityEngine{
prom: promql.NewEngine(opts.EngineOpts),
prom: engine,

debugWriter: opts.DebugWriter,
disableFallback: opts.DisableFallback,
Expand All @@ -208,7 +218,7 @@ func New(opts Opts) *compatibilityEngine {
}

type compatibilityEngine struct {
prom *promql.Engine
prom v1.QueryEngine

debugWriter io.Writer

Expand Down

0 comments on commit 190e5c3

Please sign in to comment.