Skip to content

Commit

Permalink
Update thanos-io/promql-engine (#7215)
Browse files Browse the repository at this point in the history
* Update thanos-io/promql-engine

This commit updates the promql-engine module to latest main and modifies
to remote engine based on the breaking change.

Signed-off-by: Filip Petkovski <filip.petkovsky@gmail.com>

* Fix lint

Signed-off-by: Filip Petkovski <filip.petkovsky@gmail.com>

---------

Signed-off-by: Filip Petkovski <filip.petkovsky@gmail.com>
  • Loading branch information
fpetkovski committed Mar 21, 2024
1 parent 6df670f commit 4a2a455
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 14 deletions.
7 changes: 6 additions & 1 deletion cmd/thanos/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,12 @@ func queryFuncCreator(
queryAPIClients := grpcEndpointSet.GetQueryAPIClients()
for _, i := range rand.Perm(len(queryAPIClients)) {
e := query.NewRemoteEngine(logger, queryAPIClients[i], query.Opts{})
q, err := e.NewInstantQuery(ctx, nil, qs, t)
expr, err := parser.ParseExpr(qs)
if err != nil {
level.Error(logger).Log("err", err, "query", qs)
continue
}
q, err := e.NewInstantQuery(ctx, nil, expr, t)
if err != nil {
level.Error(logger).Log("err", err, "query", qs)
continue
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ require (
github.com/sony/gobreaker v0.5.0
github.com/stretchr/testify v1.8.4
github.com/thanos-io/objstore v0.0.0-20231112185854-37752ee64d98
github.com/thanos-io/promql-engine v0.0.0-20240125175542-4a8e9731acba
github.com/thanos-io/promql-engine v0.0.0-20240318110350-23714ea2522d
github.com/uber/jaeger-client-go v2.30.0+incompatible
github.com/uber/jaeger-lib v2.4.1+incompatible // indirect
github.com/vimeo/galaxycache v0.0.0-20210323154928-b7e5d71c067a
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1536,8 +1536,8 @@ github.com/thanos-community/galaxycache v0.0.0-20211122094458-3a32041a1f1e h1:f1
github.com/thanos-community/galaxycache v0.0.0-20211122094458-3a32041a1f1e/go.mod h1:jXcofnrSln/cLI6/dhlBxPQZEEQHVPCcFaH75M+nSzM=
github.com/thanos-io/objstore v0.0.0-20231112185854-37752ee64d98 h1:gx2MTto1UQRumGoJzY3aFPQ31Ov3nOV7NaD7j6q288k=
github.com/thanos-io/objstore v0.0.0-20231112185854-37752ee64d98/go.mod h1:JauBAcJ61tRSv9widgISVmA6akQXDeUMXBrVmWW4xog=
github.com/thanos-io/promql-engine v0.0.0-20240125175542-4a8e9731acba h1:BFohBPqCWBpbqNO3F3lC2uZ0egSfPGQoSDloTRraPHU=
github.com/thanos-io/promql-engine v0.0.0-20240125175542-4a8e9731acba/go.mod h1:YGk7VqhYDfhUyZjWK7ZU1JmBQKSvr5mT5Txut8oK1MA=
github.com/thanos-io/promql-engine v0.0.0-20240318110350-23714ea2522d h1:/6Gy8ul/6iKHaAg3OhaoPmph2TRAlansv4z+VAbTOKk=
github.com/thanos-io/promql-engine v0.0.0-20240318110350-23714ea2522d/go.mod h1:YGk7VqhYDfhUyZjWK7ZU1JmBQKSvr5mT5Txut8oK1MA=
github.com/themihai/gomemcache v0.0.0-20180902122335-24332e2d58ab h1:7ZR3hmisBWw77ZpO1/o86g+JV3VKlk3d48jopJxzTjU=
github.com/themihai/gomemcache v0.0.0-20180902122335-24332e2d58ab/go.mod h1:eheTFp954zcWZXCU8d0AT76ftsQOTo4DTqkN/h3k1MY=
github.com/tklauser/go-sysconf v0.3.4/go.mod h1:Cl2c8ZRWfHD5IrfHo9VN+FX9kCFjIOyVklgXycLB6ek=
Expand Down
18 changes: 9 additions & 9 deletions pkg/query/remote_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,26 +181,26 @@ func (r *remoteEngine) infosWithoutReplicaLabels() infopb.TSDBInfos {
return infos
}

func (r *remoteEngine) NewRangeQuery(_ context.Context, opts promql.QueryOpts, qs string, start, end time.Time, interval time.Duration) (promql.Query, error) {
func (r *remoteEngine) NewRangeQuery(_ context.Context, _ promql.QueryOpts, plan parser.Expr, start, end time.Time, interval time.Duration) (promql.Query, error) {
return &remoteQuery{
logger: r.logger,
client: r.client,
opts: r.opts,

qs: qs,
plan: plan,
start: start,
end: end,
interval: interval,
}, nil
}

func (r *remoteEngine) NewInstantQuery(_ context.Context, _ promql.QueryOpts, qs string, ts time.Time) (promql.Query, error) {
func (r *remoteEngine) NewInstantQuery(_ context.Context, _ promql.QueryOpts, plan parser.Expr, ts time.Time) (promql.Query, error) {
return &remoteQuery{
logger: r.logger,
client: r.client,
opts: r.opts,

qs: qs,
plan: plan,
start: ts,
end: ts,
interval: 0,
Expand All @@ -212,7 +212,7 @@ type remoteQuery struct {
client Client
opts Opts

qs string
plan parser.Expr
start time.Time
end time.Time
interval time.Duration
Expand All @@ -235,7 +235,7 @@ func (r *remoteQuery) Exec(ctx context.Context) *promql.Result {
// Instant query.
if r.start == r.end {
request := &querypb.QueryRequest{
Query: r.qs,
Query: r.plan.String(),
TimeSeconds: r.start.Unix(),
TimeoutSeconds: int64(r.opts.Timeout.Seconds()),
EnablePartialResponse: r.opts.EnablePartialResponse,
Expand Down Expand Up @@ -286,7 +286,7 @@ func (r *remoteQuery) Exec(ctx context.Context) *promql.Result {
}

request := &querypb.QueryRangeRequest{
Query: r.qs,
Query: r.plan.String(),
StartTimeSeconds: r.start.Unix(),
EndTimeSeconds: r.end.Unix(),
IntervalSeconds: int64(r.interval.Seconds()),
Expand Down Expand Up @@ -349,7 +349,7 @@ func (r *remoteQuery) Exec(ctx context.Context) *promql.Result {
}
result = append(result, series)
}
level.Debug(r.logger).Log("msg", "Executed query", "query", r.qs, "time", time.Since(start))
level.Debug(r.logger).Log("msg", "Executed query", "query", r.plan, "time", time.Since(start))

return &promql.Result{Value: result, Warnings: warnings}
}
Expand All @@ -360,7 +360,7 @@ func (r *remoteQuery) Statement() parser.Statement { return nil }

func (r *remoteQuery) Stats() *stats.Statistics { return nil }

func (r *remoteQuery) String() string { return r.qs }
func (r *remoteQuery) String() string { return r.plan.String() }

func (r *remoteQuery) Cancel() {
if r.cancel != nil {
Expand Down
5 changes: 4 additions & 1 deletion pkg/query/remote_engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/go-kit/log"
"github.com/pkg/errors"
"github.com/prometheus/prometheus/model/labels"
"github.com/prometheus/prometheus/promql/parser"
"google.golang.org/grpc"

"github.com/thanos-io/thanos/pkg/api/query/querypb"
Expand All @@ -27,11 +28,13 @@ func TestRemoteEngine_Warnings(t *testing.T) {
Timeout: 1 * time.Second,
})
var (
query = "up"
start = time.Unix(0, 0)
end = time.Unix(120, 0)
step = 30 * time.Second
)
query, err := parser.ParseExpr("up")
testutil.Ok(t, err)

qry, err := engine.NewRangeQuery(context.Background(), nil, query, start, end, step)
testutil.Ok(t, err)
res := qry.Exec(context.Background())
Expand Down

0 comments on commit 4a2a455

Please sign in to comment.