Skip to content

Commit 0366b42

Browse files
committed
add bytes fetched into response header
1 parent fe50c0b commit 0366b42

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

internal/cortex/querier/queryrange/query_range.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,11 @@ func (prometheusCodec) EncodeResponse(ctx context.Context, res Response) (*http.
473473
httpHeader := http.Header{
474474
"Content-Type": []string{"application/json"}}
475475
if queryBytesFetchedHttpHeaderValue := QueryBytesFetchedHttpHeaderValue(res); queryBytesFetchedHttpHeaderValue != nil {
476+
// M3 code path
476477
httpHeader[QueryBytesFetchedHeaderName] = queryBytesFetchedHttpHeaderValue
478+
} else if res.(*PrometheusResponse).Data.SeriesStatsCounter != nil {
479+
// Pantheon code path
480+
httpHeader[QueryBytesFetchedHeaderName] = []string{strconv.FormatInt(res.(*PrometheusResponse).Data.SeriesStatsCounter.Bytes, 10)}
477481
}
478482
resp := http.Response{
479483
Header: httpHeader,

pkg/queryfrontend/queryinstant_codec.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,11 +263,17 @@ func (c queryInstantCodec) EncodeResponse(ctx context.Context, res queryrange.Re
263263

264264
sp.LogFields(otlog.Int("bytes", len(b)))
265265

266+
httpHeader := http.Header{
267+
"Content-Type": []string{"application/json"}}
268+
if queryBytesFetchedHttpHeaderValue := queryrange.QueryBytesFetchedHttpHeaderValue(res); queryBytesFetchedHttpHeaderValue != nil {
269+
// M3 code path
270+
httpHeader[queryrange.QueryBytesFetchedHeaderName] = queryBytesFetchedHttpHeaderValue
271+
} else if res.(*queryrange.PrometheusInstantQueryResponse).Data.SeriesStatsCounter != nil {
272+
// Pantheon code path
273+
httpHeader[queryrange.QueryBytesFetchedHeaderName] = []string{strconv.FormatInt(res.(*queryrange.PrometheusInstantQueryResponse).Data.SeriesStatsCounter.Bytes, 10)}
274+
}
266275
resp := http.Response{
267-
Header: http.Header{
268-
"Content-Type": []string{"application/json"},
269-
queryrange.QueryBytesFetchedHeaderName: queryrange.QueryBytesFetchedHttpHeaderValue(res),
270-
},
276+
Header: httpHeader,
271277
Body: io.NopCloser(bytes.NewBuffer(b)),
272278
StatusCode: http.StatusOK,
273279
ContentLength: int64(len(b)),

0 commit comments

Comments
 (0)