Skip to content

Commit

Permalink
QueryRange use protobuf internally instead of json to reduce latency (#…
Browse files Browse the repository at this point in the history
…3745)

* Update query_range to use protobuf between frontend->querier instead of json for improved performance

* changelog
  • Loading branch information
mdisibio authored and mapno committed Jun 6, 2024
1 parent 3a4f309 commit 9cefa83
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* [FEATURE] TraceQL support for event scope and event:name intrinsic [#3708](https://github.com/grafana/tempo/pull/3708) (@stoewer)
* [FEATURE] Flush and query RF1 blocks for TraceQL metric queries [#3628](https://github.com/grafana/tempo/pull/3628) [#3691](https://github.com/grafana/tempo/pull/3691) [#3723](https://github.com/grafana/tempo/pull/3723) (@mapno)
* [ENHANCEMENT] Tag value lookup use protobuf internally for improved latency [#3731](https://github.com/grafana/tempo/pull/3731) (@mdisibio)
* [ENHANCEMENT] TraceQL metrics queries use protobuf internally for improved latency [#3745](https://github.com/grafana/tempo/pull/3745) (@mdisibio)
* [ENHANCEMENT] Improve use of OTEL semantic conventions on the service graph [#3711](https://github.com/grafana/tempo/pull/3711) (@zalegrala)
* [ENHANCEMENT] Performance improvement for `rate() by ()` queries [#3719](https://github.com/grafana/tempo/pull/3719) (@mapno)
* [BUGFIX] Fix metrics queries when grouping by attributes that may not exist [#3734](https://github.com/grafana/tempo/pull/3734) (@mdisibio)
Expand Down
6 changes: 5 additions & 1 deletion modules/frontend/metrics_query_range_sharder.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ func (s *queryRangeSharder) buildBackendRequests(ctx context.Context, tenantID s
queryRangeReq.End += queryRangeReq.Step

subR = api.BuildQueryRangeRequest(subR, queryRangeReq)
subR.Header.Set(api.HeaderAccept, api.HeaderAcceptProtobuf)

prepareRequestForQueriers(subR, tenantID, subR.URL.Path, subR.URL.Query())
// TODO: Handle sampling rate
Expand Down Expand Up @@ -438,7 +439,10 @@ func (s *queryRangeSharder) generatorRequest(searchReq tempopb.QueryRangeRequest

searchReq.QueryMode = querier.QueryModeRecent

return s.toUpstreamRequest(parent.Context(), searchReq, parent, tenantID)
req := s.toUpstreamRequest(parent.Context(), searchReq, parent, tenantID)
req.Header.Set(api.HeaderAccept, api.HeaderAcceptProtobuf)

return req
}

func (s *queryRangeSharder) toUpstreamRequest(ctx context.Context, req tempopb.QueryRangeRequest, parent *http.Request, tenantID string) *http.Request {
Expand Down
17 changes: 1 addition & 16 deletions modules/querier/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,22 +409,7 @@ func (q *Querier) QueryRangeHandler(w http.ResponseWriter, r *http.Request) {
return
}

m := jsonpb.Marshaler{}
jsBytes, funcErr := m.MarshalToString(resp)
if funcErr != nil {
errHandler(ctx, span, funcErr)
http.Error(w, funcErr.Error(), http.StatusInternalServerError)
return
}

_, funcErr = w.Write([]byte(jsBytes))
if funcErr != nil {
errHandler(ctx, span, funcErr)
http.Error(w, funcErr.Error(), http.StatusInternalServerError)
return
}

w.Header().Set(api.HeaderContentType, api.HeaderAcceptJSON)
writeFormattedContentForRequest(w, r, resp)
}()

req, err := api.ParseQueryRangeRequest(r)
Expand Down

0 comments on commit 9cefa83

Please sign in to comment.