Skip to content

Commit bbc0cc1

Browse files
committed
Add fallback logic to thanos promql engine
Signed-off-by: SungJin1212 <[email protected]>
1 parent f77525a commit bbc0cc1

File tree

310 files changed

+71594
-425
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

310 files changed

+71594
-425
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* [ENHANCEMENT] Alertmanager: Add receiver validations for msteamsv2 and rocketchat. #6606
1515
* [ENHANCEMENT] Query Frontend: Add a `-frontend.enabled-ruler-query-stats` flag to configure whether to report the query stats log for queries coming from the Ruler. #6504
1616
* [ENHANCEMENT] OTLP: Support otlp metadata ingestion. #6617
17+
* [ENHANCEMENT] Querier: Add a fallback logic when use a thanos promql engine. #6630
1718
* [BUGFIX] Ingester: Avoid error or early throttling when READONLY ingesters are present in the ring #6517
1819
* [BUGFIX] Ingester: Fix labelset data race condition. #6573
1920
* [BUGFIX] Compactor: Cleaner should not put deletion marker for blocks with no-compact marker. #6576

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ require (
5151
github.com/spf13/afero v1.11.0
5252
github.com/stretchr/testify v1.10.0
5353
github.com/thanos-io/objstore v0.0.0-20241111205755-d1dd89d41f97
54-
github.com/thanos-io/promql-engine v0.0.0-20250220213456-fab1185f8c6c
54+
github.com/thanos-io/promql-engine v0.0.0-20250302135832-accbf0891a16
5555
github.com/thanos-io/thanos v0.37.3-0.20250212101700-346d18bb0f80
5656
github.com/uber/jaeger-client-go v2.30.0+incompatible
5757
github.com/weaveworks/common v0.0.0-20230728070032-dd9e68f319d5

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1672,8 +1672,8 @@ github.com/thanos-community/galaxycache v0.0.0-20211122094458-3a32041a1f1e h1:f1
16721672
github.com/thanos-community/galaxycache v0.0.0-20211122094458-3a32041a1f1e/go.mod h1:jXcofnrSln/cLI6/dhlBxPQZEEQHVPCcFaH75M+nSzM=
16731673
github.com/thanos-io/objstore v0.0.0-20241111205755-d1dd89d41f97 h1:VjG0mwhN1DkncwDHFvrpd12/2TLfgYNRmEQA48ikp+0=
16741674
github.com/thanos-io/objstore v0.0.0-20241111205755-d1dd89d41f97/go.mod h1:vyzFrBXgP+fGNG2FopEGWOO/zrIuoy7zt3LpLeezRsw=
1675-
github.com/thanos-io/promql-engine v0.0.0-20250220213456-fab1185f8c6c h1:STCm5S4Aht3hOR0WQ0B3daZv21GQC13uPYIfkcN762U=
1676-
github.com/thanos-io/promql-engine v0.0.0-20250220213456-fab1185f8c6c/go.mod h1:aHSV5hL94fNb7PklN9L0V10j+/RGIlzqbw7OLdNgZFs=
1675+
github.com/thanos-io/promql-engine v0.0.0-20250302135832-accbf0891a16 h1:ezd8hNCWiGQr4kdfCHFa0VCSi+LAO/28Mna264nDs2c=
1676+
github.com/thanos-io/promql-engine v0.0.0-20250302135832-accbf0891a16/go.mod h1:aHSV5hL94fNb7PklN9L0V10j+/RGIlzqbw7OLdNgZFs=
16771677
github.com/thanos-io/thanos v0.37.3-0.20250212101700-346d18bb0f80 h1:mOCRYn9SLBWJCXAdP+qDfgZDc0eqDxDc2HZGKTZ5vzk=
16781678
github.com/thanos-io/thanos v0.37.3-0.20250212101700-346d18bb0f80/go.mod h1:Y7D8la8B5rpzRVKq2HCR4hbYZ4LGroSPqIJjtizgQg8=
16791679
github.com/tjhop/slog-gokit v0.1.2 h1:pmQI4SvU9h4gA0vIQsdhJQSqQg4mOmsPykG2/PM3j1I=

pkg/querier/engine_factory.go

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package querier
2+
3+
import (
4+
"context"
5+
"time"
6+
7+
"github.com/prometheus/prometheus/promql"
8+
"github.com/prometheus/prometheus/storage"
9+
"github.com/thanos-io/promql-engine/engine"
10+
"github.com/thanos-io/promql-engine/logicalplan"
11+
)
12+
13+
type EngineFactory struct {
14+
prometheusEngine *promql.Engine
15+
thanosEngine *engine.Engine
16+
}
17+
18+
func NewEngineFactory(opts promql.EngineOpts, enableThanosEngine bool) *EngineFactory {
19+
prometheusEngine := promql.NewEngine(opts)
20+
21+
var thanosEngine *engine.Engine
22+
if enableThanosEngine {
23+
thanosEngine = engine.New(engine.Opts{
24+
EngineOpts: opts,
25+
LogicalOptimizers: logicalplan.AllOptimizers,
26+
EnableAnalysis: true,
27+
})
28+
}
29+
30+
return &EngineFactory{
31+
prometheusEngine: prometheusEngine,
32+
thanosEngine: thanosEngine,
33+
}
34+
}
35+
36+
func (qf *EngineFactory) NewInstantQuery(ctx context.Context, q storage.Queryable, opts promql.QueryOpts, qs string, ts time.Time) (promql.Query, error) {
37+
if qf.thanosEngine != nil {
38+
res, err := qf.thanosEngine.MakeInstantQuery(ctx, q, fromPromQLOpts(opts), qs, ts)
39+
if err != nil {
40+
if engine.IsUnimplemented(err) {
41+
// fallback to use prometheus engine
42+
goto fallback
43+
}
44+
return nil, err
45+
}
46+
return res, nil
47+
}
48+
49+
fallback:
50+
return qf.prometheusEngine.NewInstantQuery(ctx, q, opts, qs, ts)
51+
}
52+
53+
func (qf *EngineFactory) NewRangeQuery(ctx context.Context, q storage.Queryable, opts promql.QueryOpts, qs string, start, end time.Time, interval time.Duration) (promql.Query, error) {
54+
if qf.thanosEngine != nil {
55+
res, err := qf.thanosEngine.MakeRangeQuery(ctx, q, fromPromQLOpts(opts), qs, start, end, interval)
56+
if err != nil {
57+
if engine.IsUnimplemented(err) {
58+
// fallback to use prometheus engine
59+
goto fallback
60+
}
61+
return nil, err
62+
}
63+
return res, nil
64+
}
65+
66+
fallback:
67+
return qf.prometheusEngine.NewRangeQuery(ctx, q, opts, qs, start, end, interval)
68+
}
69+
70+
func fromPromQLOpts(opts promql.QueryOpts) *engine.QueryOpts {
71+
if opts == nil {
72+
return &engine.QueryOpts{}
73+
}
74+
return &engine.QueryOpts{
75+
LookbackDeltaParam: opts.LookbackDelta(),
76+
EnablePerStepStatsParam: opts.EnablePerStepStats(),
77+
}
78+
}

pkg/querier/querier.go

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ import (
1919
"github.com/prometheus/prometheus/promql/parser"
2020
"github.com/prometheus/prometheus/storage"
2121
"github.com/prometheus/prometheus/util/annotations"
22-
"github.com/thanos-io/promql-engine/engine"
23-
"github.com/thanos-io/promql-engine/logicalplan"
2422
"github.com/thanos-io/thanos/pkg/strutil"
2523
"golang.org/x/sync/errgroup"
2624

@@ -208,7 +206,6 @@ func New(cfg Config, limits *validation.Overrides, distributor Distributor, stor
208206
// The cortex supports holt_winters for users using this function.
209207
EnableExperimentalPromQLFunctions(cfg.EnablePromQLExperimentalFunctions, true)
210208

211-
var queryEngine promql.QueryEngine
212209
opts := promql.EngineOpts{
213210
Logger: util_log.GoKitLogToSlog(logger),
214211
Reg: reg,
@@ -223,15 +220,7 @@ func New(cfg Config, limits *validation.Overrides, distributor Distributor, stor
223220
return cfg.DefaultEvaluationInterval.Milliseconds()
224221
},
225222
}
226-
if cfg.ThanosEngine {
227-
queryEngine = engine.New(engine.Opts{
228-
EngineOpts: opts,
229-
LogicalOptimizers: logicalplan.AllOptimizers,
230-
EnableAnalysis: true,
231-
})
232-
} else {
233-
queryEngine = promql.NewEngine(opts)
234-
}
223+
queryEngine := NewEngineFactory(opts, cfg.ThanosEngine)
235224
return NewSampleAndChunkQueryable(lazyQueryable), exemplarQueryable, queryEngine
236225
}
237226

vendor/github.com/thanos-io/promql-engine/engine/distributed.go

Lines changed: 35 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)