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

Query: adding stats to the remote engine #7361

Merged
merged 14 commits into from
May 24, 2024
Merged
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re

- [#7317](https://github.com/thanos-io/thanos/pull/7317) Tracing: allow specifying resource attributes for the OTLP configuration.
- [#7367](https://github.com/thanos-io/thanos/pull/7367) Store Gateway: log request ID in request logs.
- [#7361](https://github.com/thanos-io/thanos/pull/7361) Query: pass query stats from remote execution from server to client.

### Changed

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ require (
github.com/sony/gobreaker v0.5.0
github.com/stretchr/testify v1.9.0
github.com/thanos-io/objstore v0.0.0-20240309075357-e8336a5fd5f3
github.com/thanos-io/promql-engine v0.0.0-20240405095051-b7d0da367508
github.com/thanos-io/promql-engine v0.0.0-20240515161521-93aa311933cf
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 @@ -1552,8 +1552,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-20240309075357-e8336a5fd5f3 h1:Q0BjHI7FMe5KkKVXBFYto5VNASxiA/+AEhHup/IT7N0=
github.com/thanos-io/objstore v0.0.0-20240309075357-e8336a5fd5f3/go.mod h1:ptMYNPgbyAR7a2Ab2t7zHA2/0be2ePyawVR7lp7fZtg=
github.com/thanos-io/promql-engine v0.0.0-20240405095051-b7d0da367508 h1:4X0ThYb7/wTTKS73wT13ixw0lj5OJ87g45RWIZhPZDA=
github.com/thanos-io/promql-engine v0.0.0-20240405095051-b7d0da367508/go.mod h1:FEPnabuTql1bDA4OUM41mwcZOJ20R436k8vq+xtGEG0=
github.com/thanos-io/promql-engine v0.0.0-20240515161521-93aa311933cf h1:R6of9adrCWXhETBstsFzNqrZou5UqeY3fh3k5yv5POY=
github.com/thanos-io/promql-engine v0.0.0-20240515161521-93aa311933cf/go.mod h1:FEPnabuTql1bDA4OUM41mwcZOJ20R436k8vq+xtGEG0=
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
27 changes: 24 additions & 3 deletions pkg/api/query/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/prometheus/prometheus/promql"
"github.com/prometheus/prometheus/storage"
"github.com/thanos-io/promql-engine/engine"
"github.com/thanos-io/promql-engine/logicalplan"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
Expand Down Expand Up @@ -129,7 +130,9 @@ func (g *GRPCAPI) Query(request *querypb.QueryRequest, server querypb.Query_Quer
return err
}
}
return nil
}
if err := server.Send(querypb.NewQueryStatsResponse(extractQueryStats(qry))); err != nil {
return err
}

return nil
Expand Down Expand Up @@ -245,17 +248,35 @@ func (g *GRPCAPI) QueryRange(request *querypb.QueryRangeRequest, srv querypb.Que
return err
}
}
return nil
case promql.Scalar:
series := &prompb.TimeSeries{
Samples: []prompb.Sample{{Value: value.V, Timestamp: value.T}},
}
return srv.Send(querypb.NewQueryRangeResponse(series))
if err := srv.Send(querypb.NewQueryRangeResponse(series)); err != nil {
return err
}
}
if err := srv.Send(querypb.NewQueryRangeStatsResponse(extractQueryStats(qry))); err != nil {
return err
}

return nil
}

func extractQueryStats(qry promql.Query) *querypb.QueryStats {
stats := &querypb.QueryStats{
SamplesTotal: 0,
PeakSamples: 0,
}
if explQry, ok := qry.(engine.ExplainableQuery); ok {
analyze := explQry.Analyze()
stats.SamplesTotal = analyze.TotalSamples()
stats.PeakSamples = analyze.PeakSamples()
}

return stats
}

func (g *GRPCAPI) getRangeQueryForEngine(
ctx context.Context,
request *querypb.QueryRangeRequest,
Expand Down
8 changes: 6 additions & 2 deletions pkg/api/query/grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ func TestGRPCQueryAPIErrorHandling(t *testing.T) {
if len(test.engine.warns) > 0 {
testutil.Ok(t, err)
for i, resp := range srv.responses {
testutil.Equals(t, test.engine.warns.AsErrors()[i].Error(), resp.GetWarnings())
if resp.GetWarnings() != "" {
testutil.Equals(t, test.engine.warns.AsErrors()[i].Error(), resp.GetWarnings())
}
}
}
})
Expand All @@ -136,7 +138,9 @@ func TestGRPCQueryAPIErrorHandling(t *testing.T) {
if len(test.engine.warns) > 0 {
testutil.Ok(t, err)
for i, resp := range srv.responses {
testutil.Equals(t, test.engine.warns.AsErrors()[i].Error(), resp.GetWarnings())
if resp.GetWarnings() != "" {
testutil.Equals(t, test.engine.warns.AsErrors()[i].Error(), resp.GetWarnings())
}
}
}
})
Expand Down
Loading
Loading