Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update thanos-io/promql-engine #7215

Merged
merged 2 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading