From 022c6d5466fbb88c07083035a83aa23bed43acc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel=20Ortu=C3=B1o?= Date: Wed, 12 Jun 2024 11:39:25 +0200 Subject: [PATCH] added `GetHeaders` method to `MetricsQueryRequest` interface. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Miguel Ángel Ortuño --- pkg/frontend/querymiddleware/codec.go | 22 +- .../querymiddleware/codec_json_test.go | 2 +- .../querymiddleware/codec_protobuf_test.go | 2 +- pkg/frontend/querymiddleware/codec_test.go | 8 + pkg/frontend/querymiddleware/model.pb.go | 210 +++++++++--------- pkg/frontend/querymiddleware/model.proto | 4 +- pkg/frontend/querymiddleware/model_extra.go | 26 ++- .../querymiddleware/results_cache_test.go | 10 +- .../querymiddleware/sharded_queryable.go | 10 +- .../querymiddleware/sharded_queryable_test.go | 8 +- 10 files changed, 169 insertions(+), 133 deletions(-) diff --git a/pkg/frontend/querymiddleware/codec.go b/pkg/frontend/querymiddleware/codec.go index 837e4fb2c15..f8a0c11da51 100644 --- a/pkg/frontend/querymiddleware/codec.go +++ b/pkg/frontend/querymiddleware/codec.go @@ -95,6 +95,8 @@ type MetricsQueryRequest interface { GetID() int64 // GetPath returns the URL Path of the request GetPath() string + // GetHeaders returns the HTTP headers in the request. + GetHeaders() []*PrometheusHeader // GetStart returns the start timestamp of the request in milliseconds. GetStart() int64 // GetEnd returns the end timestamp of the request in milliseconds. @@ -163,7 +165,7 @@ type LabelsQueryRequest interface { type Response interface { proto.Message // GetHeaders returns the HTTP headers in the response. - GetHeaders() []*PrometheusResponseHeader + GetHeaders() []*PrometheusHeader } type prometheusCodecMetrics struct { @@ -284,6 +286,12 @@ func (c prometheusCodec) decodeRangeQueryRequest(r *http.Request) (MetricsQueryR return nil, apierror.New(apierror.TypeBadData, err.Error()) } + headers := make([]*PrometheusHeader, 0, len(r.Header)) + for h, hv := range r.Header { + headers = append(headers, &PrometheusHeader{Name: h, Values: slices.Clone(hv)}) + } + sort.Slice(headers, func(i, j int) bool { return headers[i].Name < headers[j].Name }) + start, end, step, err := DecodeRangeQueryTimeParams(&reqValues) if err != nil { return nil, err @@ -299,7 +307,7 @@ func (c prometheusCodec) decodeRangeQueryRequest(r *http.Request) (MetricsQueryR decodeOptions(r, &options) req := NewPrometheusRangeQueryRequest( - r.URL.Path, start, end, step, c.lookbackDelta, queryExpr, options, nil, + r.URL.Path, headers, start, end, step, c.lookbackDelta, queryExpr, options, nil, ) return req, nil } @@ -310,6 +318,12 @@ func (c prometheusCodec) decodeInstantQueryRequest(r *http.Request) (MetricsQuer return nil, apierror.New(apierror.TypeBadData, err.Error()) } + headers := make([]*PrometheusHeader, 0, len(r.Header)) + for h, hv := range r.Header { + headers = append(headers, &PrometheusHeader{Name: h, Values: slices.Clone(hv)}) + } + sort.Slice(headers, func(i, j int) bool { return headers[i].Name < headers[j].Name }) + time, err := DecodeInstantQueryTimeParams(&reqValues, time.Now) if err != nil { return nil, decorateWithParamName(err, "time") @@ -325,7 +339,7 @@ func (c prometheusCodec) decodeInstantQueryRequest(r *http.Request) (MetricsQuer decodeOptions(r, &options) req := NewPrometheusInstantQueryRequest( - r.URL.Path, time, c.lookbackDelta, queryExpr, options, nil, + r.URL.Path, headers, time, c.lookbackDelta, queryExpr, options, nil, ) return req, nil } @@ -699,7 +713,7 @@ func (c prometheusCodec) DecodeResponse(ctx context.Context, r *http.Response, _ } for h, hv := range r.Header { - resp.Headers = append(resp.Headers, &PrometheusResponseHeader{Name: h, Values: hv}) + resp.Headers = append(resp.Headers, &PrometheusHeader{Name: h, Values: hv}) } return resp, nil } diff --git a/pkg/frontend/querymiddleware/codec_json_test.go b/pkg/frontend/querymiddleware/codec_json_test.go index 4ca24eb8274..1c681b87c09 100644 --- a/pkg/frontend/querymiddleware/codec_json_test.go +++ b/pkg/frontend/querymiddleware/codec_json_test.go @@ -27,7 +27,7 @@ import ( func TestPrometheusCodec_JSONResponse(t *testing.T) { headers := http.Header{"Content-Type": []string{"application/json"}} - expectedRespHeaders := []*PrometheusResponseHeader{ + expectedRespHeaders := []*PrometheusHeader{ { Name: "Content-Type", Values: []string{"application/json"}, diff --git a/pkg/frontend/querymiddleware/codec_protobuf_test.go b/pkg/frontend/querymiddleware/codec_protobuf_test.go index 9a32766e44c..f064a79a1b9 100644 --- a/pkg/frontend/querymiddleware/codec_protobuf_test.go +++ b/pkg/frontend/querymiddleware/codec_protobuf_test.go @@ -21,7 +21,7 @@ import ( "github.com/grafana/mimir/pkg/mimirpb" ) -var expectedProtobufResponseHeaders = []*PrometheusResponseHeader{ +var expectedProtobufResponseHeaders = []*PrometheusHeader{ { Name: "Content-Type", Values: []string{mimirpb.QueryResponseMimeType}, diff --git a/pkg/frontend/querymiddleware/codec_test.go b/pkg/frontend/querymiddleware/codec_test.go index c64f3b6c70d..71aa001483d 100644 --- a/pkg/frontend/querymiddleware/codec_test.go +++ b/pkg/frontend/querymiddleware/codec_test.go @@ -79,6 +79,7 @@ func TestMetricsQueryRequest(t *testing.T) { url: "/api/v1/query_range?end=1536716880&query=sum+by+%28namespace%29+%28container_memory_rss%29&start=1536673680&step=120", expected: NewPrometheusRangeQueryRequest( "/api/v1/query_range", + nil, 1536673680*1e3, 1536716880*1e3, (2 * time.Minute).Milliseconds(), @@ -92,6 +93,7 @@ func TestMetricsQueryRequest(t *testing.T) { url: "/api/v1/query?query=sum+by+%28namespace%29+%28container_memory_rss%29&time=1536716880", expected: NewPrometheusInstantQueryRequest( "/api/v1/query", + nil, 1536716880*1e3, 0*time.Minute, parseQuery(t, "sum(container_memory_rss) by (namespace)"), @@ -171,6 +173,7 @@ func TestMetricsQuery_MinMaxTime(t *testing.T) { rangeRequest := NewPrometheusRangeQueryRequest( "/api/v1/query_range", + nil, startTime.UnixMilli(), endTime.UnixMilli(), stepDuration.Milliseconds(), @@ -181,6 +184,7 @@ func TestMetricsQuery_MinMaxTime(t *testing.T) { ) instantRequest := NewPrometheusInstantQueryRequest( "/api/v1/query", + nil, endTime.UnixMilli(), lookbackDuration, parseQuery(t, "go_goroutines{}"), @@ -297,6 +301,7 @@ func TestMetricsQuery_WithStartEnd_TransformConsistency(t *testing.T) { rangeRequest := NewPrometheusRangeQueryRequest( "/api/v1/query_range", + nil, startTime.UnixMilli(), endTime.UnixMilli(), stepDuration.Milliseconds(), @@ -307,6 +312,7 @@ func TestMetricsQuery_WithStartEnd_TransformConsistency(t *testing.T) { ) instantRequest := NewPrometheusInstantQueryRequest( "/api/v1/query", + nil, endTime.UnixMilli(), time.Duration(0), parseQuery(t, "go_goroutines{}"), @@ -375,6 +381,7 @@ func TestMetricsQuery_WithQuery_WithExpr_TransformConsistency(t *testing.T) { rangeRequest := NewPrometheusRangeQueryRequest( "/api/v1/query_range", + nil, startTime.UnixMilli(), endTime.UnixMilli(), stepDuration.Milliseconds(), @@ -385,6 +392,7 @@ func TestMetricsQuery_WithQuery_WithExpr_TransformConsistency(t *testing.T) { ) instantRequest := NewPrometheusInstantQueryRequest( "/api/v1/query", + nil, endTime.UnixMilli(), time.Duration(0), parseQuery(t, "go_goroutines{}"), diff --git a/pkg/frontend/querymiddleware/model.pb.go b/pkg/frontend/querymiddleware/model.pb.go index d620efbaff0..8cc12cb6d12 100644 --- a/pkg/frontend/querymiddleware/model.pb.go +++ b/pkg/frontend/querymiddleware/model.pb.go @@ -31,22 +31,22 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package -type PrometheusResponseHeader struct { +type PrometheusHeader struct { Name string `protobuf:"bytes,1,opt,name=Name,proto3" json:"-"` Values []string `protobuf:"bytes,2,rep,name=Values,proto3" json:"-"` } -func (m *PrometheusResponseHeader) Reset() { *m = PrometheusResponseHeader{} } -func (*PrometheusResponseHeader) ProtoMessage() {} -func (*PrometheusResponseHeader) Descriptor() ([]byte, []int) { +func (m *PrometheusHeader) Reset() { *m = PrometheusHeader{} } +func (*PrometheusHeader) ProtoMessage() {} +func (*PrometheusHeader) Descriptor() ([]byte, []int) { return fileDescriptor_4c16552f9fdb66d8, []int{0} } -func (m *PrometheusResponseHeader) XXX_Unmarshal(b []byte) error { +func (m *PrometheusHeader) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *PrometheusResponseHeader) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *PrometheusHeader) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_PrometheusResponseHeader.Marshal(b, m, deterministic) + return xxx_messageInfo_PrometheusHeader.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -56,26 +56,26 @@ func (m *PrometheusResponseHeader) XXX_Marshal(b []byte, deterministic bool) ([] return b[:n], nil } } -func (m *PrometheusResponseHeader) XXX_Merge(src proto.Message) { - xxx_messageInfo_PrometheusResponseHeader.Merge(m, src) +func (m *PrometheusHeader) XXX_Merge(src proto.Message) { + xxx_messageInfo_PrometheusHeader.Merge(m, src) } -func (m *PrometheusResponseHeader) XXX_Size() int { +func (m *PrometheusHeader) XXX_Size() int { return m.Size() } -func (m *PrometheusResponseHeader) XXX_DiscardUnknown() { - xxx_messageInfo_PrometheusResponseHeader.DiscardUnknown(m) +func (m *PrometheusHeader) XXX_DiscardUnknown() { + xxx_messageInfo_PrometheusHeader.DiscardUnknown(m) } -var xxx_messageInfo_PrometheusResponseHeader proto.InternalMessageInfo +var xxx_messageInfo_PrometheusHeader proto.InternalMessageInfo -func (m *PrometheusResponseHeader) GetName() string { +func (m *PrometheusHeader) GetName() string { if m != nil { return m.Name } return "" } -func (m *PrometheusResponseHeader) GetValues() []string { +func (m *PrometheusHeader) GetValues() []string { if m != nil { return m.Values } @@ -83,12 +83,12 @@ func (m *PrometheusResponseHeader) GetValues() []string { } type PrometheusResponse struct { - Status string `protobuf:"bytes,1,opt,name=Status,proto3" json:"status"` - Data *PrometheusData `protobuf:"bytes,2,opt,name=Data,proto3" json:"data,omitempty"` - ErrorType string `protobuf:"bytes,3,opt,name=ErrorType,proto3" json:"errorType,omitempty"` - Error string `protobuf:"bytes,4,opt,name=Error,proto3" json:"error,omitempty"` - Headers []*PrometheusResponseHeader `protobuf:"bytes,5,rep,name=Headers,proto3" json:"-"` - Warnings []string `protobuf:"bytes,6,rep,name=Warnings,proto3" json:"warnings,omitempty"` + Status string `protobuf:"bytes,1,opt,name=Status,proto3" json:"status"` + Data *PrometheusData `protobuf:"bytes,2,opt,name=Data,proto3" json:"data,omitempty"` + ErrorType string `protobuf:"bytes,3,opt,name=ErrorType,proto3" json:"errorType,omitempty"` + Error string `protobuf:"bytes,4,opt,name=Error,proto3" json:"error,omitempty"` + Headers []*PrometheusHeader `protobuf:"bytes,5,rep,name=Headers,proto3" json:"-"` + Warnings []string `protobuf:"bytes,6,rep,name=Warnings,proto3" json:"warnings,omitempty"` } func (m *PrometheusResponse) Reset() { *m = PrometheusResponse{} } @@ -151,7 +151,7 @@ func (m *PrometheusResponse) GetError() string { return "" } -func (m *PrometheusResponse) GetHeaders() []*PrometheusResponseHeader { +func (m *PrometheusResponse) GetHeaders() []*PrometheusHeader { if m != nil { return m.Headers } @@ -643,7 +643,7 @@ func (m *CachedHTTPHeader) GetValue() string { } func init() { - proto.RegisterType((*PrometheusResponseHeader)(nil), "queryrange.PrometheusResponseHeader") + proto.RegisterType((*PrometheusHeader)(nil), "queryrange.PrometheusHeader") proto.RegisterType((*PrometheusResponse)(nil), "queryrange.PrometheusResponse") proto.RegisterType((*PrometheusData)(nil), "queryrange.PrometheusData") proto.RegisterType((*SampleStream)(nil), "queryrange.SampleStream") @@ -659,79 +659,79 @@ func init() { proto.RegisterFile("model.proto", fileDescriptor_4c16552f9fdb66d8) var fileDescriptor_4c16552f9fdb66d8 = []byte{ // 998 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x55, 0xcd, 0x6e, 0x23, 0x45, - 0x10, 0xf6, 0xc4, 0xbf, 0x29, 0x87, 0x24, 0xea, 0x44, 0xe0, 0x04, 0x98, 0xb1, 0x46, 0x7b, 0x08, - 0x68, 0xd7, 0x81, 0x20, 0x38, 0x20, 0x40, 0xac, 0xb3, 0x46, 0x09, 0xbf, 0xa1, 0x6d, 0x81, 0xc4, - 0x25, 0x6a, 0x7b, 0x7a, 0xed, 0x61, 0x67, 0xa6, 0x87, 0xee, 0xf6, 0xee, 0xfa, 0x86, 0x78, 0x00, - 0xc4, 0x13, 0x70, 0xe6, 0x51, 0xf6, 0x98, 0xe3, 0xb2, 0x87, 0x11, 0x71, 0x84, 0x84, 0x7c, 0xda, - 0x47, 0x40, 0x53, 0x3d, 0x63, 0x4f, 0x76, 0x73, 0xd8, 0x8b, 0xa7, 0xfb, 0xab, 0xef, 0xab, 0xaa, - 0xae, 0xae, 0x2e, 0x43, 0x33, 0x14, 0x1e, 0x0f, 0x3a, 0xb1, 0x14, 0x5a, 0x10, 0xf8, 0x65, 0xca, - 0xe5, 0x4c, 0xb2, 0x68, 0xcc, 0xf7, 0xef, 0x8c, 0x7d, 0x3d, 0x99, 0x0e, 0x3b, 0x23, 0x11, 0x1e, - 0x8e, 0xc5, 0x58, 0x1c, 0x22, 0x65, 0x38, 0xbd, 0x8f, 0x3b, 0xdc, 0xe0, 0xca, 0x48, 0xf7, 0xdf, - 0x2b, 0xd2, 0x25, 0xbb, 0xcf, 0x22, 0x76, 0x18, 0xfa, 0xa1, 0x2f, 0x0f, 0xe3, 0x07, 0x63, 0xb3, - 0x8a, 0x87, 0xe6, 0x9b, 0x29, 0xf6, 0xc6, 0x42, 0x8c, 0x03, 0xbe, 0xf2, 0xcb, 0xa2, 0x99, 0x31, - 0xb9, 0x03, 0x68, 0x9d, 0x49, 0x11, 0x72, 0x3d, 0xe1, 0x53, 0x45, 0xb9, 0x8a, 0x45, 0xa4, 0xf8, - 0x09, 0x67, 0x1e, 0x97, 0x64, 0x0f, 0x2a,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da, 0xa5, - 0xe7, 0x97, 0xb6, 0xf5, 0xeb, 0xdc, 0xb6, 0xfe, 0x9a, 0xdb, 0xd6, 0x93, 0xb9, 0x6d, 0x5d, 0xcc, - 0x6d, 0xeb, 0x9f, 0xb9, 0x6d, 0xfd, 0x37, 0xb7, 0x4b, 0xcf, 0xe7, 0xb6, 0xf5, 0xc7, 0x95, 0x5d, - 0xba, 0xb8, 0xb2, 0x4b, 0x4f, 0xaf, 0xec, 0xd2, 0x4f, 0x5b, 0x98, 0x6d, 0xe8, 0x7b, 0x5e, 0xc0, - 0x1f, 0x31, 0xc9, 0x87, 0x35, 0x6c, 0xd7, 0x0f, 0xfe, 0x0f, 0x00, 0x00, 0xff, 0xff, 0xec, 0x96, - 0x75, 0x18, 0x83, 0x07, 0x00, 0x00, -} - -func (this *PrometheusResponseHeader) Equal(that interface{}) bool { + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x55, 0x41, 0x6f, 0x1b, 0xc5, + 0x17, 0xf7, 0x66, 0x6d, 0xc7, 0x79, 0xee, 0x3f, 0xb1, 0xa6, 0xd1, 0x1f, 0x27, 0xc0, 0xae, 0xb5, + 0xe2, 0x10, 0x50, 0xeb, 0x40, 0x10, 0x1c, 0x10, 0x20, 0xea, 0x34, 0x28, 0x81, 0x02, 0x61, 0x1c, + 0x81, 0xc4, 0x25, 0x1a, 0x7b, 0xa7, 0xf6, 0xd2, 0xdd, 0x9d, 0x65, 0x66, 0xdc, 0xd6, 0x37, 0xc4, + 0x07, 0x40, 0x7c, 0x02, 0xce, 0x7c, 0x94, 0x1e, 0xc3, 0xad, 0xea, 0x61, 0x45, 0x1c, 0x21, 0x21, + 0x9f, 0xfa, 0x11, 0xd0, 0xbe, 0xd9, 0x5d, 0x6f, 0xdb, 0x1c, 0xb8, 0x78, 0x67, 0x7e, 0xef, 0xf7, + 0x7b, 0xef, 0xcd, 0x9b, 0x37, 0xcf, 0xd0, 0x8e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69, 0xbc, 0xe3, + 0xb3, 0xb3, 0xd3, 0xb2, 0xf9, 0x5e, 0x87, 0x8d, 0x71, 0x86, 0x9e, 0x97, 0x2d, 0x48, 0x5b, 0x08, + 0x7c, 0xc9, 0xe7, 0xc4, 0x85, 0xb6, 0x19, 0xb6, 0xe7, 0x63, 0xe1, 0x73, 0xac, 0x55, 0x83, 0x82, + 0x81, 0x0e, 0x85, 0xcf, 0xc9, 0x87, 0xb0, 0x3e, 0xcd, 0xa7, 0x9a, 0xfd, 0xea, 0x54, 0x5b, 0x85, + 0x33, 0x63, 0x8c, 0x16, 0x64, 0x42, 0xa0, 0x3e, 0x12, 0xfe, 0x1c, 0x6b, 0x75, 0x83, 0xe2, 0xda, + 0xfb, 0x18, 0x3a, 0x2f, 0x0b, 0x32, 0x5e, 0x5c, 0xfe, 0xa1, 0x50, 0x5c, 0x93, 0x6d, 0x68, 0xe0, + 0x2b, 0xc5, 0x74, 0x36, 0xa8, 0xd9, 0x0c, 0x8e, 0x2e, 0x2e, 0x9d, 0xda, 0xd3, 0x4b, 0xa7, 0xf6, + 0xfc, 0xd2, 0xb1, 0x7e, 0x5e, 0x38, 0xd6, 0x1f, 0x0b, 0xc7, 0x7a, 0xb2, 0x70, 0xac, 0x8b, 0x85, + 0x63, 0xfd, 0xb5, 0x70, 0xac, 0x7f, 0x16, 0x4e, 0xed, 0xf9, 0xc2, 0xb1, 0x7e, 0xbb, 0x72, 0x6a, + 0x17, 0x57, 0x4e, 0xed, 0xe9, 0x95, 0x53, 0xfb, 0x61, 0x0b, 0xb3, 0x8d, 0x02, 0xdf, 0x0f, 0xf9, + 0x23, 0x26, 0xf9, 0xa8, 0x89, 0xed, 0xfa, 0xfe, 0xbf, 0x01, 0x00, 0x00, 0xff, 0xff, 0x00, 0xcd, + 0x0d, 0xa4, 0x73, 0x07, 0x00, 0x00, +} + +func (this *PrometheusHeader) Equal(that interface{}) bool { if that == nil { return this == nil } - that1, ok := that.(*PrometheusResponseHeader) + that1, ok := that.(*PrometheusHeader) if !ok { - that2, ok := that.(PrometheusResponseHeader) + that2, ok := that.(PrometheusHeader) if ok { that1 = &that2 } else { @@ -1075,12 +1075,12 @@ func (this *CachedHTTPHeader) Equal(that interface{}) bool { } return true } -func (this *PrometheusResponseHeader) GoString() string { +func (this *PrometheusHeader) GoString() string { if this == nil { return "nil" } s := make([]string, 0, 6) - s = append(s, "&querymiddleware.PrometheusResponseHeader{") + s = append(s, "&querymiddleware.PrometheusHeader{") s = append(s, "Name: "+fmt.Sprintf("%#v", this.Name)+",\n") s = append(s, "Values: "+fmt.Sprintf("%#v", this.Values)+",\n") s = append(s, "}") @@ -1237,7 +1237,7 @@ func valueToGoStringModel(v interface{}, typ string) string { pv := reflect.Indirect(rv).Interface() return fmt.Sprintf("func(v %v) *%v { return &v } ( %#v )", typ, typ, pv) } -func (m *PrometheusResponseHeader) Marshal() (dAtA []byte, err error) { +func (m *PrometheusHeader) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -1247,12 +1247,12 @@ func (m *PrometheusResponseHeader) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *PrometheusResponseHeader) MarshalTo(dAtA []byte) (int, error) { +func (m *PrometheusHeader) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *PrometheusResponseHeader) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *PrometheusHeader) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -1760,7 +1760,7 @@ func encodeVarintModel(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) return base } -func (m *PrometheusResponseHeader) Size() (n int) { +func (m *PrometheusHeader) Size() (n int) { if m == nil { return 0 } @@ -1992,11 +1992,11 @@ func sovModel(x uint64) (n int) { func sozModel(x uint64) (n int) { return sovModel(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } -func (this *PrometheusResponseHeader) String() string { +func (this *PrometheusHeader) String() string { if this == nil { return "nil" } - s := strings.Join([]string{`&PrometheusResponseHeader{`, + s := strings.Join([]string{`&PrometheusHeader{`, `Name:` + fmt.Sprintf("%v", this.Name) + `,`, `Values:` + fmt.Sprintf("%v", this.Values) + `,`, `}`, @@ -2007,9 +2007,9 @@ func (this *PrometheusResponse) String() string { if this == nil { return "nil" } - repeatedStringForHeaders := "[]*PrometheusResponseHeader{" + repeatedStringForHeaders := "[]*PrometheusHeader{" for _, f := range this.Headers { - repeatedStringForHeaders += strings.Replace(f.String(), "PrometheusResponseHeader", "PrometheusResponseHeader", 1) + "," + repeatedStringForHeaders += strings.Replace(f.String(), "PrometheusHeader", "PrometheusHeader", 1) + "," } repeatedStringForHeaders += "}" s := strings.Join([]string{`&PrometheusResponse{`, @@ -2152,7 +2152,7 @@ func valueToStringModel(v interface{}) string { pv := reflect.Indirect(rv).Interface() return fmt.Sprintf("*%v", pv) } -func (m *PrometheusResponseHeader) Unmarshal(dAtA []byte) error { +func (m *PrometheusHeader) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -2175,10 +2175,10 @@ func (m *PrometheusResponseHeader) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: PrometheusResponseHeader: wiretype end group for non-group") + return fmt.Errorf("proto: PrometheusHeader: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: PrometheusResponseHeader: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: PrometheusHeader: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: @@ -2459,7 +2459,7 @@ func (m *PrometheusResponse) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Headers = append(m.Headers, &PrometheusResponseHeader{}) + m.Headers = append(m.Headers, &PrometheusHeader{}) if err := m.Headers[len(m.Headers)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } diff --git a/pkg/frontend/querymiddleware/model.proto b/pkg/frontend/querymiddleware/model.proto index 26f33ec0b0c..c68abf0ca77 100644 --- a/pkg/frontend/querymiddleware/model.proto +++ b/pkg/frontend/querymiddleware/model.proto @@ -17,7 +17,7 @@ import "google/protobuf/any.proto"; option (gogoproto.marshaler_all) = true; option (gogoproto.unmarshaler_all) = true; -message PrometheusResponseHeader { +message PrometheusHeader { string Name = 1 [(gogoproto.jsontag) = "-"]; repeated string Values = 2 [(gogoproto.jsontag) = "-"]; } @@ -27,7 +27,7 @@ message PrometheusResponse { PrometheusData Data = 2 [(gogoproto.jsontag) = "data,omitempty"]; string ErrorType = 3 [(gogoproto.jsontag) = "errorType,omitempty"]; string Error = 4 [(gogoproto.jsontag) = "error,omitempty"]; - repeated PrometheusResponseHeader Headers = 5 [(gogoproto.jsontag) = "-"]; + repeated PrometheusHeader Headers = 5 [(gogoproto.jsontag) = "-"]; repeated string Warnings = 6 [(gogoproto.jsontag) = "warnings,omitempty"]; } diff --git a/pkg/frontend/querymiddleware/model_extra.go b/pkg/frontend/querymiddleware/model_extra.go index 7e860151574..663879f9dce 100644 --- a/pkg/frontend/querymiddleware/model_extra.go +++ b/pkg/frontend/querymiddleware/model_extra.go @@ -45,10 +45,11 @@ func newEmptyPrometheusResponse() *PrometheusResponse { } type PrometheusRangeQueryRequest struct { - path string - start int64 - end int64 - step int64 + path string + headers []*PrometheusHeader + start int64 + end int64 + step int64 // lookback is set at query engine level rather than per request, but required to know minT and maxT lookbackDelta time.Duration queryExpr parser.Expr @@ -65,6 +66,7 @@ type PrometheusRangeQueryRequest struct { func NewPrometheusRangeQueryRequest( urlPath string, + headers []*PrometheusHeader, start, end, step int64, lookbackDelta time.Duration, queryExpr parser.Expr, @@ -81,6 +83,7 @@ func NewPrometheusRangeQueryRequest( return &PrometheusRangeQueryRequest{ path: urlPath, + headers: headers, start: start, end: end, step: step, @@ -101,6 +104,10 @@ func (r *PrometheusRangeQueryRequest) GetPath() string { return r.path } +func (r *PrometheusRangeQueryRequest) GetHeaders() []*PrometheusHeader { + return r.headers +} + func (r *PrometheusRangeQueryRequest) GetStart() int64 { return r.start } @@ -227,8 +234,9 @@ func (r *PrometheusRangeQueryRequest) AddSpanTags(sp opentracing.Span) { } type PrometheusInstantQueryRequest struct { - path string - time int64 + path string + headers []*PrometheusHeader + time int64 // lookback is set at query engine level rather than per request, but required to know minT and maxT lookbackDelta time.Duration queryExpr parser.Expr @@ -245,6 +253,7 @@ type PrometheusInstantQueryRequest struct { func NewPrometheusInstantQueryRequest( urlPath string, + headers []*PrometheusHeader, time int64, lookbackDelta time.Duration, queryExpr parser.Expr, @@ -260,6 +269,7 @@ func NewPrometheusInstantQueryRequest( } return &PrometheusInstantQueryRequest{ path: urlPath, + headers: headers, time: time, lookbackDelta: lookbackDelta, queryExpr: queryExpr, @@ -278,6 +288,10 @@ func (r *PrometheusInstantQueryRequest) GetPath() string { return r.path } +func (r *PrometheusInstantQueryRequest) GetHeaders() []*PrometheusHeader { + return r.headers +} + func (r *PrometheusInstantQueryRequest) GetTime() int64 { return r.time } diff --git a/pkg/frontend/querymiddleware/results_cache_test.go b/pkg/frontend/querymiddleware/results_cache_test.go index 9ff724faf0e..13c69574094 100644 --- a/pkg/frontend/querymiddleware/results_cache_test.go +++ b/pkg/frontend/querymiddleware/results_cache_test.go @@ -308,7 +308,7 @@ func TestIsResponseCachable(t *testing.T) { { name: "does not contain the cacheControl header", response: Response(&PrometheusResponse{ - Headers: []*PrometheusResponseHeader{ + Headers: []*PrometheusHeader{ { Name: "meaninglessheader", Values: []string{}, @@ -320,7 +320,7 @@ func TestIsResponseCachable(t *testing.T) { { name: "does contain the cacheControl header which has the value", response: Response(&PrometheusResponse{ - Headers: []*PrometheusResponseHeader{ + Headers: []*PrometheusHeader{ { Name: cacheControlHeader, Values: []string{noStoreValue}, @@ -332,7 +332,7 @@ func TestIsResponseCachable(t *testing.T) { { name: "cacheControl header contains extra values but still good", response: Response(&PrometheusResponse{ - Headers: []*PrometheusResponseHeader{ + Headers: []*PrometheusHeader{ { Name: cacheControlHeader, Values: []string{"foo", noStoreValue}, @@ -349,14 +349,14 @@ func TestIsResponseCachable(t *testing.T) { { name: "nil headers", response: Response(&PrometheusResponse{ - Headers: []*PrometheusResponseHeader{nil}, + Headers: []*PrometheusHeader{nil}, }), expected: true, }, { name: "had cacheControl header but no values", response: Response(&PrometheusResponse{ - Headers: []*PrometheusResponseHeader{{Name: cacheControlHeader}}, + Headers: []*PrometheusHeader{{Name: cacheControlHeader}}, }), expected: true, }, diff --git a/pkg/frontend/querymiddleware/sharded_queryable.go b/pkg/frontend/querymiddleware/sharded_queryable.go index 59f4fac08a4..c68d039bc1e 100644 --- a/pkg/frontend/querymiddleware/sharded_queryable.go +++ b/pkg/frontend/querymiddleware/sharded_queryable.go @@ -57,7 +57,7 @@ func (q *shardedQueryable) Querier(_, _ int64) (storage.Querier, error) { // getResponseHeaders returns the merged response headers received by the downstream // when running the embedded queries. -func (q *shardedQueryable) getResponseHeaders() []*PrometheusResponseHeader { +func (q *shardedQueryable) getResponseHeaders() []*PrometheusHeader { return q.responseHeaders.getHeaders() } @@ -162,7 +162,7 @@ func newResponseHeadersTracker() *responseHeadersTracker { } } -func (t *responseHeadersTracker) mergeHeaders(headers []*PrometheusResponseHeader) { +func (t *responseHeadersTracker) mergeHeaders(headers []*PrometheusHeader) { t.headersMx.Lock() defer t.headersMx.Unlock() @@ -176,14 +176,14 @@ func (t *responseHeadersTracker) mergeHeaders(headers []*PrometheusResponseHeade } } -func (t *responseHeadersTracker) getHeaders() []*PrometheusResponseHeader { +func (t *responseHeadersTracker) getHeaders() []*PrometheusHeader { t.headersMx.Lock() defer t.headersMx.Unlock() // Convert the response headers into the right data type. - out := make([]*PrometheusResponseHeader, 0, len(t.headers)) + out := make([]*PrometheusHeader, 0, len(t.headers)) for name, values := range t.headers { - out = append(out, &PrometheusResponseHeader{Name: name, Values: values}) + out = append(out, &PrometheusHeader{Name: name, Values: values}) } return out diff --git a/pkg/frontend/querymiddleware/sharded_queryable_test.go b/pkg/frontend/querymiddleware/sharded_queryable_test.go index e72a60b7932..da5f223c576 100644 --- a/pkg/frontend/querymiddleware/sharded_queryable_test.go +++ b/pkg/frontend/querymiddleware/sharded_queryable_test.go @@ -264,11 +264,11 @@ func TestShardedQueryable_GetResponseHeaders(t *testing.T) { querier, err := queryable.Querier(math.MinInt64, math.MaxInt64) require.NoError(t, err) - querier.(*shardedQuerier).responseHeaders.mergeHeaders([]*PrometheusResponseHeader{ + querier.(*shardedQuerier).responseHeaders.mergeHeaders([]*PrometheusHeader{ {Name: "content-type", Values: []string{"application/json"}}, {Name: "cache-control", Values: []string{"no-cache"}}, }) - assert.ElementsMatch(t, []*PrometheusResponseHeader{ + assert.ElementsMatch(t, []*PrometheusHeader{ {Name: "content-type", Values: []string{"application/json"}}, {Name: "cache-control", Values: []string{"no-cache"}}, }, queryable.getResponseHeaders()) @@ -277,11 +277,11 @@ func TestShardedQueryable_GetResponseHeaders(t *testing.T) { querier, err = queryable.Querier(math.MinInt64, math.MaxInt64) require.NoError(t, err) - querier.(*shardedQuerier).responseHeaders.mergeHeaders([]*PrometheusResponseHeader{ + querier.(*shardedQuerier).responseHeaders.mergeHeaders([]*PrometheusHeader{ {Name: "content-type", Values: []string{"application/json"}}, {Name: "cache-control", Values: []string{"no-store"}}, }) - assert.ElementsMatch(t, []*PrometheusResponseHeader{ + assert.ElementsMatch(t, []*PrometheusHeader{ {Name: "content-type", Values: []string{"application/json"}}, {Name: "cache-control", Values: []string{"no-cache", "no-store"}}, }, queryable.getResponseHeaders())