diff --git a/CHANGELOG.md b/CHANGELOG.md index fd24e6b7fef..205aa7ea3d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/modules/frontend/metrics_query_range_sharder.go b/modules/frontend/metrics_query_range_sharder.go index 96a66963b9f..65eae768421 100644 --- a/modules/frontend/metrics_query_range_sharder.go +++ b/modules/frontend/metrics_query_range_sharder.go @@ -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 @@ -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 { diff --git a/modules/querier/http.go b/modules/querier/http.go index 301aae491f1..fb67cdd78f1 100644 --- a/modules/querier/http.go +++ b/modules/querier/http.go @@ -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)