Skip to content

Commit b6a8f5e

Browse files
committed
Pass Request to DecodeResponse in case it is required.
Loki has the concept of log Direction which is essential to know when merging responses. This change allows Loki to inject the direction in the response which can be then used when merging multiple responses. Signed-off-by: Cyril Tovena <[email protected]>
1 parent fcbc186 commit b6a8f5e

File tree

4 files changed

+5
-5
lines changed

4 files changed

+5
-5
lines changed

pkg/querier/queryrange/marshaling_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func BenchmarkMarshalling(b *testing.B) {
1919
apiResp, err := PrometheusCodec.DecodeResponse(context.Background(), &http.Response{
2020
StatusCode: 200,
2121
Body: ioutil.NopCloser(bytes.NewReader(buf)),
22-
})
22+
}, nil)
2323
require.NoError(b, err)
2424

2525
resp, err := PrometheusCodec.EncodeResponse(context.Background(), apiResp)

pkg/querier/queryrange/query_range.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ type Codec interface {
4141
// DecodeRequest decodes a Request from an http request.
4242
DecodeRequest(context.Context, *http.Request) (Request, error)
4343
// DecodeResponse decodes a Response from an http response..
44-
DecodeResponse(context.Context, *http.Response) (Response, error)
44+
DecodeResponse(context.Context, *http.Response, Request) (Response, error)
4545
// EncodeRequest encodes a Request into an http request.
4646
EncodeRequest(context.Context, Request) (*http.Request, error)
4747
// EncodeResponse encodes a Response into an http response.
@@ -198,7 +198,7 @@ func (prometheusCodec) EncodeRequest(ctx context.Context, r Request) (*http.Requ
198198
return req.WithContext(ctx), nil
199199
}
200200

201-
func (prometheusCodec) DecodeResponse(ctx context.Context, r *http.Response) (Response, error) {
201+
func (prometheusCodec) DecodeResponse(ctx context.Context, r *http.Response, _ Request) (Response, error) {
202202
if r.StatusCode/100 != 2 {
203203
body, _ := ioutil.ReadAll(r.Body)
204204
return nil, httpgrpc.Errorf(r.StatusCode, string(body))

pkg/querier/queryrange/query_range_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func TestResponse(t *testing.T) {
8989
Header: http.Header{"Content-Type": []string{"application/json"}},
9090
Body: ioutil.NopCloser(bytes.NewBuffer([]byte(tc.body))),
9191
}
92-
resp, err := PrometheusCodec.DecodeResponse(context.Background(), response)
92+
resp, err := PrometheusCodec.DecodeResponse(context.Background(), response, nil)
9393
require.NoError(t, err)
9494
assert.Equal(t, tc.expected, resp)
9595

pkg/querier/queryrange/roundtrip.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,5 +176,5 @@ func (q roundTripper) Do(ctx context.Context, r Request) (Response, error) {
176176
}
177177
defer func() { _ = response.Body.Close() }()
178178

179-
return q.codec.DecodeResponse(ctx, response)
179+
return q.codec.DecodeResponse(ctx, response, r)
180180
}

0 commit comments

Comments
 (0)