Skip to content

Commit 670658d

Browse files
committed
fix regression of query range result cache unable to parse old cached results
Signed-off-by: Ben Ye <[email protected]>
1 parent 8622767 commit 670658d

File tree

7 files changed

+1433
-51
lines changed

7 files changed

+1433
-51
lines changed

pkg/querier/tripperware/custom.go

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,5 @@
11
package tripperware
22

3-
import (
4-
"fmt"
5-
6-
"github.com/gogo/protobuf/types"
7-
)
8-
9-
func (e *Extent) ToResponse() (Response, error) {
10-
msg, err := types.EmptyAny(e.Response)
11-
if err != nil {
12-
return nil, err
13-
}
14-
15-
if err := types.UnmarshalAny(e.Response, msg); err != nil {
16-
return nil, err
17-
}
18-
19-
resp, ok := msg.(Response)
20-
if !ok {
21-
return nil, fmt.Errorf("bad cached type")
22-
}
23-
return resp, nil
24-
}
25-
263
func (m *Sample) GetTimestampMs() int64 {
274
if m != nil {
285
if m.Sample != nil {

pkg/querier/tripperware/instantquery/instant_query.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func (c instantQueryCodec) DecodeRequest(_ context.Context, r *http.Request, for
6666
}
6767

6868
func (instantQueryCodec) DecodeResponse(ctx context.Context, r *http.Response, _ tripperware.Request) (tripperware.Response, error) {
69-
log, ctx := spanlogger.New(ctx, "tripperware.PrometheusResponse") //nolint:ineffassign,staticcheck
69+
log, ctx := spanlogger.New(ctx, "DecodeQueryInstantResponse") //nolint:ineffassign,staticcheck
7070
defer log.Finish()
7171

7272
if err := ctx.Err(); err != nil {

pkg/querier/tripperware/queryrange/query_range.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,20 @@ var (
4141
cacheControlHeader = "Cache-Control"
4242
)
4343

44+
func (resp *PrometheusResponse) HTTPHeaders() map[string][]string {
45+
if resp != nil && resp.GetHeaders() != nil {
46+
r := map[string][]string{}
47+
for _, header := range resp.GetHeaders() {
48+
if header != nil {
49+
r[header.Name] = header.Values
50+
}
51+
}
52+
53+
return r
54+
}
55+
return nil
56+
}
57+
4458
type prometheusCodec struct {
4559
sharded bool
4660
}
@@ -57,6 +71,11 @@ func (c prometheusCodec) MergeResponse(ctx context.Context, req tripperware.Requ
5771
return tripperware.NewEmptyPrometheusResponse(false), nil
5872
}
5973

74+
// Safety guard in case any response from results cache middleware
75+
// still uses the old queryrange.PrometheusResponse type.
76+
for i, resp := range responses {
77+
responses[i] = convertResponse(resp)
78+
}
6079
return tripperware.MergeResponse(ctx, c.sharded, nil, responses...)
6180
}
6281

0 commit comments

Comments
 (0)