-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into mhoffm-add-sample-limits
Signed-off-by: Michael Hoffmann <[email protected]>
- Loading branch information
Showing
5 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright (c) The Thanos Community Authors. | ||
// Licensed under the Apache License 2.0. | ||
|
||
package logicalplan | ||
|
||
import ( | ||
"github.com/thanos-io/promql-engine/api" | ||
"github.com/thanos-io/promql-engine/parser" | ||
) | ||
|
||
// PassthroughOptimizer optimizes queries which can be simply passed | ||
// through to a RemoteEngine. | ||
type PassthroughOptimizer struct { | ||
Endpoints api.RemoteEndpoints | ||
} | ||
|
||
func (m PassthroughOptimizer) Optimize(plan parser.Expr, opts *Opts) parser.Expr { | ||
engines := m.Endpoints.Engines() | ||
if len(engines) == 1 { | ||
return RemoteExecution{ | ||
Engine: engines[0], | ||
Query: plan.String(), | ||
QueryRangeStart: opts.Start, | ||
} | ||
} | ||
|
||
return plan | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright (c) The Thanos Community Authors. | ||
// Licensed under the Apache License 2.0. | ||
|
||
package logicalplan | ||
|
||
import ( | ||
"math" | ||
"testing" | ||
"time" | ||
|
||
"github.com/efficientgo/core/testutil" | ||
"github.com/prometheus/prometheus/model/labels" | ||
|
||
"github.com/thanos-io/promql-engine/api" | ||
"github.com/thanos-io/promql-engine/parser" | ||
) | ||
|
||
func TestPassthrough(t *testing.T) { | ||
expr, err := parser.ParseExpr(`time()`) | ||
testutil.Ok(t, err) | ||
|
||
t.Run("optimized with one engine", func(t *testing.T) { | ||
engines := []api.RemoteEngine{ | ||
newEngineMock(math.MinInt64, math.MinInt64, []labels.Labels{labels.FromStrings("region", "east"), labels.FromStrings("region", "south")}), | ||
} | ||
optimizers := []Optimizer{PassthroughOptimizer{Endpoints: api.NewStaticEndpoints(engines)}} | ||
|
||
plan := New(expr, &Opts{Start: time.Unix(0, 0), End: time.Unix(0, 0)}) | ||
optimizedPlan := plan.Optimize(optimizers) | ||
|
||
testutil.Equals(t, "remote(time())", optimizedPlan.Expr().String()) | ||
}) | ||
|
||
t.Run("not optimized with one engine", func(t *testing.T) { | ||
engines := []api.RemoteEngine{ | ||
newEngineMock(math.MinInt64, math.MinInt64, []labels.Labels{labels.FromStrings("region", "east"), labels.FromStrings("region", "south")}), | ||
newEngineMock(math.MinInt64, math.MinInt64, []labels.Labels{labels.FromStrings("region", "west")}), | ||
} | ||
optimizers := []Optimizer{PassthroughOptimizer{Endpoints: api.NewStaticEndpoints(engines)}} | ||
|
||
plan := New(expr, &Opts{Start: time.Unix(0, 0), End: time.Unix(0, 0)}) | ||
optimizedPlan := plan.Optimize(optimizers) | ||
|
||
testutil.Equals(t, "time()", optimizedPlan.Expr().String()) | ||
}) | ||
|
||
} |