diff --git a/CHANGELOG.md b/CHANGELOG.md index 76578bbe973..c8739aea4ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ * [FEATURE] Query Frontend: Add `cortex_query_fetched_series_total` and `cortex_query_fetched_chunks_bytes_total` per-user counters to expose the number of series and bytes fetched as part of queries. These metrics can be enabled with the `-frontend.query-stats-enabled` flag (or its respective YAML config option `query_stats_enabled`). #4343 * [FEATURE] AlertManager: Add support for SNS Receiver. #4382 * [FEATURE] Distributor: Add label `status` to metric `cortex_distributor_ingester_append_failures_total` #4442 +* [ENHANCEMENT] Query Frontend: Add setting `-frontend.forward-headers-list` in frontend to configure the set of headers from the requests to be forwarded to downstream requests. #4486 * [FEATURE] Queries: Added `present_over_time` PromQL function, also some TSDB optimisations. #4505 * [ENHANCEMENT] Add timeout for waiting on compactor to become ACTIVE in the ring. #4262 * [ENHANCEMENT] Reduce memory used by streaming queries, particularly in ruler. #4341 diff --git a/docs/configuration/arguments.md b/docs/configuration/arguments.md index 643d4865cbe..c9cfab126f9 100644 --- a/docs/configuration/arguments.md +++ b/docs/configuration/arguments.md @@ -116,6 +116,10 @@ The ingester query API was improved over time, but defaults to the old behaviour If set to true, will cause the querier to cache query results. The cache will be used to answer future, overlapping queries. The query frontend calculates extra queries required to fill gaps in the cache. +- `-frontend.forward-headers-list` + + Request headers forwarded by query frontend to downstream queriers. Multiple headers may be specified. Defaults to empty. + - `-frontend.max-cache-freshness` When caching query results, it is desirable to prevent the caching of very recent results that might still be in flux. Use this parameter to configure the age of results that should be excluded. diff --git a/docs/configuration/config-file-reference.md b/docs/configuration/config-file-reference.md index 7d2db4cb6a8..e87c2d4357a 100644 --- a/docs/configuration/config-file-reference.md +++ b/docs/configuration/config-file-reference.md @@ -1166,6 +1166,10 @@ results_cache: # query ASTs. This feature is supported only by the chunks storage engine. # CLI flag: -querier.parallelise-shardable-queries [parallelise_shardable_queries: | default = false] + +# List of headers forwarded by the query Frontend to downstream querier. +# CLI flag: -frontend.forward-headers-list +[forward_headers_list: | default = []] ``` ### `ruler_config` diff --git a/docs/configuration/prometheus-frontend.md b/docs/configuration/prometheus-frontend.md index c8cbda01b83..acf110611d5 100644 --- a/docs/configuration/prometheus-frontend.md +++ b/docs/configuration/prometheus-frontend.md @@ -28,6 +28,10 @@ query_range: align_queries_with_step: true cache_results: true + # list of request headers forwarded by query frontend to downstream queriers. + forward_headers_list: + - Authorization + results_cache: cache: diff --git a/pkg/querier/queryrange/query_range.go b/pkg/querier/queryrange/query_range.go index 32962db9080..4c61d97232c 100644 --- a/pkg/querier/queryrange/query_range.go +++ b/pkg/querier/queryrange/query_range.go @@ -52,7 +52,7 @@ var ( type Codec interface { Merger // DecodeRequest decodes a Request from an http request. - DecodeRequest(context.Context, *http.Request) (Request, error) + DecodeRequest(_ context.Context, request *http.Request, forwardHeaders []string) (Request, error) // DecodeResponse decodes a Response from an http response. // The original request is also passed as a parameter this is useful for implementation that needs the request // to merge result or build the result correctly. @@ -187,7 +187,7 @@ func (prometheusCodec) MergeResponse(responses ...Response) (Response, error) { return &response, nil } -func (prometheusCodec) DecodeRequest(_ context.Context, r *http.Request) (Request, error) { +func (prometheusCodec) DecodeRequest(_ context.Context, r *http.Request, forwardHeaders []string) (Request, error) { var result PrometheusRequest var err error result.Start, err = util.ParseTime(r.FormValue("start")) @@ -222,6 +222,16 @@ func (prometheusCodec) DecodeRequest(_ context.Context, r *http.Request) (Reques result.Query = r.FormValue("query") result.Path = r.URL.Path + // Include the specified headers from http request in prometheusRequest. + for _, header := range forwardHeaders { + for h, hv := range r.Header { + if strings.EqualFold(h, header) { + result.Headers = append(result.Headers, &PrometheusRequestHeader{Name: h, Values: hv}) + break + } + } + } + for _, value := range r.Header.Values(cacheControlHeader) { if strings.Contains(value, noStoreValue) { result.CachingOptions.Disabled = true @@ -247,12 +257,20 @@ func (prometheusCodec) EncodeRequest(ctx context.Context, r Request) (*http.Requ Path: promReq.Path, RawQuery: params.Encode(), } + var h = http.Header{} + + for _, hv := range promReq.Headers { + for _, v := range hv.Values { + h.Add(hv.Name, v) + } + } + req := &http.Request{ Method: "GET", RequestURI: u.String(), // This is what the httpgrpc code looks at. URL: u, Body: http.NoBody, - Header: http.Header{}, + Header: h, } return req.WithContext(ctx), nil diff --git a/pkg/querier/queryrange/query_range_test.go b/pkg/querier/queryrange/query_range_test.go index 70b660c9ca0..65c8b0e8e73 100644 --- a/pkg/querier/queryrange/query_range_test.go +++ b/pkg/querier/queryrange/query_range_test.go @@ -18,6 +18,10 @@ import ( ) func TestRequest(t *testing.T) { + // Create a Copy parsedRequest to assign the expected headers to the request without affecting other tests using the global. + // The test below adds a Test-Header header to the request and expects it back once the encode/decode of request is done via PrometheusCodec + parsedRequestWithHeaders := *parsedRequest + parsedRequestWithHeaders.Headers = reqHeaders for i, tc := range []struct { url string expected Request @@ -25,7 +29,7 @@ func TestRequest(t *testing.T) { }{ { url: query, - expected: parsedRequest, + expected: &parsedRequestWithHeaders, }, { url: "api/v1/query_range?start=foo", @@ -55,11 +59,14 @@ func TestRequest(t *testing.T) { t.Run(strconv.Itoa(i), func(t *testing.T) { r, err := http.NewRequest("GET", tc.url, nil) require.NoError(t, err) + r.Header.Add("Test-Header", "test") ctx := user.InjectOrgID(context.Background(), "1") - r = r.WithContext(ctx) - req, err := PrometheusCodec.DecodeRequest(ctx, r) + // Get a deep copy of the request with Context changed to ctx + r = r.Clone(ctx) + + req, err := PrometheusCodec.DecodeRequest(ctx, r, []string{"Test-Header"}) if err != nil { require.EqualValues(t, tc.expectedErr, err) return diff --git a/pkg/querier/queryrange/queryrange.pb.go b/pkg/querier/queryrange/queryrange.pb.go index 22533001ced..ea8157140a4 100644 --- a/pkg/querier/queryrange/queryrange.pb.go +++ b/pkg/querier/queryrange/queryrange.pb.go @@ -32,20 +32,72 @@ var _ = time.Kitchen // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package +type PrometheusRequestHeader struct { + Name string `protobuf:"bytes,1,opt,name=Name,proto3" json:"-"` + Values []string `protobuf:"bytes,2,rep,name=Values,proto3" json:"-"` +} + +func (m *PrometheusRequestHeader) Reset() { *m = PrometheusRequestHeader{} } +func (*PrometheusRequestHeader) ProtoMessage() {} +func (*PrometheusRequestHeader) Descriptor() ([]byte, []int) { + return fileDescriptor_79b02382e213d0b2, []int{0} +} +func (m *PrometheusRequestHeader) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *PrometheusRequestHeader) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_PrometheusRequestHeader.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *PrometheusRequestHeader) XXX_Merge(src proto.Message) { + xxx_messageInfo_PrometheusRequestHeader.Merge(m, src) +} +func (m *PrometheusRequestHeader) XXX_Size() int { + return m.Size() +} +func (m *PrometheusRequestHeader) XXX_DiscardUnknown() { + xxx_messageInfo_PrometheusRequestHeader.DiscardUnknown(m) +} + +var xxx_messageInfo_PrometheusRequestHeader proto.InternalMessageInfo + +func (m *PrometheusRequestHeader) GetName() string { + if m != nil { + return m.Name + } + return "" +} + +func (m *PrometheusRequestHeader) GetValues() []string { + if m != nil { + return m.Values + } + return nil +} + type PrometheusRequest struct { - Path string `protobuf:"bytes,1,opt,name=path,proto3" json:"path,omitempty"` - Start int64 `protobuf:"varint,2,opt,name=start,proto3" json:"start,omitempty"` - End int64 `protobuf:"varint,3,opt,name=end,proto3" json:"end,omitempty"` - Step int64 `protobuf:"varint,4,opt,name=step,proto3" json:"step,omitempty"` - Timeout time.Duration `protobuf:"bytes,5,opt,name=timeout,proto3,stdduration" json:"timeout"` - Query string `protobuf:"bytes,6,opt,name=query,proto3" json:"query,omitempty"` - CachingOptions CachingOptions `protobuf:"bytes,7,opt,name=cachingOptions,proto3" json:"cachingOptions"` + Path string `protobuf:"bytes,1,opt,name=path,proto3" json:"path,omitempty"` + Start int64 `protobuf:"varint,2,opt,name=start,proto3" json:"start,omitempty"` + End int64 `protobuf:"varint,3,opt,name=end,proto3" json:"end,omitempty"` + Step int64 `protobuf:"varint,4,opt,name=step,proto3" json:"step,omitempty"` + Timeout time.Duration `protobuf:"bytes,5,opt,name=timeout,proto3,stdduration" json:"timeout"` + Query string `protobuf:"bytes,6,opt,name=query,proto3" json:"query,omitempty"` + CachingOptions CachingOptions `protobuf:"bytes,7,opt,name=cachingOptions,proto3" json:"cachingOptions"` + Headers []*PrometheusRequestHeader `protobuf:"bytes,8,rep,name=Headers,proto3" json:"-"` } func (m *PrometheusRequest) Reset() { *m = PrometheusRequest{} } func (*PrometheusRequest) ProtoMessage() {} func (*PrometheusRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_79b02382e213d0b2, []int{0} + return fileDescriptor_79b02382e213d0b2, []int{1} } func (m *PrometheusRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -123,6 +175,13 @@ func (m *PrometheusRequest) GetCachingOptions() CachingOptions { return CachingOptions{} } +func (m *PrometheusRequest) GetHeaders() []*PrometheusRequestHeader { + if m != nil { + return m.Headers + } + return nil +} + type PrometheusResponseHeader struct { Name string `protobuf:"bytes,1,opt,name=Name,proto3" json:"-"` Values []string `protobuf:"bytes,2,rep,name=Values,proto3" json:"-"` @@ -131,7 +190,7 @@ type PrometheusResponseHeader struct { func (m *PrometheusResponseHeader) Reset() { *m = PrometheusResponseHeader{} } func (*PrometheusResponseHeader) ProtoMessage() {} func (*PrometheusResponseHeader) Descriptor() ([]byte, []int) { - return fileDescriptor_79b02382e213d0b2, []int{1} + return fileDescriptor_79b02382e213d0b2, []int{2} } func (m *PrometheusResponseHeader) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -185,7 +244,7 @@ type PrometheusResponse struct { func (m *PrometheusResponse) Reset() { *m = PrometheusResponse{} } func (*PrometheusResponse) ProtoMessage() {} func (*PrometheusResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_79b02382e213d0b2, []int{2} + return fileDescriptor_79b02382e213d0b2, []int{3} } func (m *PrometheusResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -257,7 +316,7 @@ type PrometheusData struct { func (m *PrometheusData) Reset() { *m = PrometheusData{} } func (*PrometheusData) ProtoMessage() {} func (*PrometheusData) Descriptor() ([]byte, []int) { - return fileDescriptor_79b02382e213d0b2, []int{3} + return fileDescriptor_79b02382e213d0b2, []int{4} } func (m *PrometheusData) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -308,7 +367,7 @@ type SampleStream struct { func (m *SampleStream) Reset() { *m = SampleStream{} } func (*SampleStream) ProtoMessage() {} func (*SampleStream) Descriptor() ([]byte, []int) { - return fileDescriptor_79b02382e213d0b2, []int{4} + return fileDescriptor_79b02382e213d0b2, []int{5} } func (m *SampleStream) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -353,7 +412,7 @@ type CachedResponse struct { func (m *CachedResponse) Reset() { *m = CachedResponse{} } func (*CachedResponse) ProtoMessage() {} func (*CachedResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_79b02382e213d0b2, []int{5} + return fileDescriptor_79b02382e213d0b2, []int{6} } func (m *CachedResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -406,7 +465,7 @@ type Extent struct { func (m *Extent) Reset() { *m = Extent{} } func (*Extent) ProtoMessage() {} func (*Extent) Descriptor() ([]byte, []int) { - return fileDescriptor_79b02382e213d0b2, []int{6} + return fileDescriptor_79b02382e213d0b2, []int{7} } func (m *Extent) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -470,7 +529,7 @@ type CachingOptions struct { func (m *CachingOptions) Reset() { *m = CachingOptions{} } func (*CachingOptions) ProtoMessage() {} func (*CachingOptions) Descriptor() ([]byte, []int) { - return fileDescriptor_79b02382e213d0b2, []int{7} + return fileDescriptor_79b02382e213d0b2, []int{8} } func (m *CachingOptions) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -507,6 +566,7 @@ func (m *CachingOptions) GetDisabled() bool { } func init() { + proto.RegisterType((*PrometheusRequestHeader)(nil), "queryrange.PrometheusRequestHeader") proto.RegisterType((*PrometheusRequest)(nil), "queryrange.PrometheusRequest") proto.RegisterType((*PrometheusResponseHeader)(nil), "queryrange.PrometheusResponseHeader") proto.RegisterType((*PrometheusResponse)(nil), "queryrange.PrometheusResponse") @@ -520,61 +580,95 @@ func init() { func init() { proto.RegisterFile("queryrange.proto", fileDescriptor_79b02382e213d0b2) } var fileDescriptor_79b02382e213d0b2 = []byte{ - // 827 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x55, 0xcd, 0x8e, 0x1b, 0x45, - 0x10, 0x76, 0xaf, 0xed, 0xb1, 0xdd, 0x1b, 0x39, 0x4b, 0x6f, 0x04, 0xe3, 0x95, 0x98, 0xb1, 0x46, - 0x1c, 0x16, 0x29, 0x99, 0x95, 0x16, 0x71, 0x00, 0x09, 0x94, 0x0c, 0x59, 0x14, 0x7e, 0x04, 0x51, - 0x6f, 0xc4, 0x81, 0x0b, 0x6a, 0x7b, 0x0a, 0x7b, 0x12, 0xcf, 0x4f, 0x7a, 0x7a, 0xd0, 0xfa, 0x86, - 0xf2, 0x04, 0x1c, 0x79, 0x04, 0x90, 0x78, 0x0c, 0x0e, 0x39, 0xee, 0x31, 0xe2, 0x30, 0xb0, 0xde, - 0x0b, 0x9a, 0x53, 0x1e, 0x01, 0xf5, 0xcf, 0x78, 0x66, 0x77, 0xb9, 0xe4, 0x62, 0x55, 0x55, 0xd7, - 0x57, 0xf5, 0xd5, 0xd7, 0x3d, 0x65, 0xbc, 0xf7, 0xbc, 0x00, 0xbe, 0xe6, 0x2c, 0x59, 0x80, 0x9f, - 0xf1, 0x54, 0xa4, 0x04, 0x37, 0x91, 0x83, 0x7b, 0x8b, 0x48, 0x2c, 0x8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d9, 0xa6, 0x1b, - 0x8c, 0xaa, 0xd2, 0xd5, 0x81, 0x7a, 0x55, 0x4c, 0xf4, 0xaa, 0x50, 0xeb, 0x43, 0xb3, 0x80, 0x24, - 0xd4, 0x3b, 0x63, 0x8a, 0x87, 0x82, 0xb3, 0x39, 0xfc, 0x10, 0x85, 0xe6, 0xcd, 0xd5, 0x0f, 0x44, - 0x85, 0xbf, 0x08, 0xc9, 0xa7, 0x78, 0xc8, 0xcd, 0x38, 0x66, 0x85, 0xdc, 0xb9, 0xb1, 0x42, 0x1e, - 0x24, 0xeb, 0xe0, 0x56, 0x55, 0xba, 0xdb, 0x4c, 0xba, 0xb5, 0xbe, 0xec, 0x0d, 0xbb, 0x7b, 0x3d, - 0xef, 0xae, 0x96, 0xa6, 0xf9, 0xf4, 0xc9, 0x01, 0x1e, 0x86, 0x51, 0xce, 0x66, 0x2b, 0x08, 0x15, - 0xf1, 0x21, 0xdd, 0xfa, 0xc1, 0xfd, 0xf3, 0x0b, 0xa7, 0xf3, 0xea, 0xc2, 0xe9, 0xbc, 0xbe, 0x70, - 0xd0, 0xcf, 0x1b, 0x07, 0xfd, 0xb6, 0x71, 0xd0, 0xcb, 0x8d, 0x83, 0xce, 0x37, 0x0e, 0xfa, 0x67, - 0xe3, 0xa0, 0x7f, 0x37, 0x4e, 0xe7, 0xf5, 0xc6, 0x41, 0xbf, 0x5c, 0x3a, 0x9d, 0xf3, 0x4b, 0xa7, - 0xf3, 0xea, 0xd2, 0xe9, 0x7c, 0xdf, 0xfa, 0x0b, 0x98, 0x59, 0x8a, 0xdb, 0x07, 0xff, 0x05, 0x00, - 0x00, 0xff, 0xff, 0x08, 0x83, 0xd3, 0x7d, 0x29, 0x06, 0x00, 0x00, -} + // 849 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x55, 0xcd, 0x6e, 0x1b, 0x55, + 0x14, 0xf6, 0xc4, 0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xba, 0xb6, 0x3e, + 0xef, 0xf4, 0xdb, 0x3b, 0x9d, 0xc9, 0x3d, 0xdd, 0x9a, 0xc6, 0x02, 0xd9, 0x83, 0x7e, 0x18, 0xe5, + 0x6c, 0xba, 0xc0, 0x50, 0x25, 0xde, 0xa7, 0x6b, 0x3f, 0x78, 0x70, 0x71, 0xe9, 0xb6, 0x5e, 0x5c, + 0xba, 0xad, 0x97, 0x97, 0xae, 0xf5, 0xe3, 0xca, 0xb5, 0x7e, 0x5d, 0xb9, 0xd6, 0xf9, 0xca, 0xb5, + 0x2e, 0x56, 0xae, 0xf5, 0xf7, 0xca, 0xb5, 0xfe, 0x59, 0xb9, 0xad, 0x97, 0x2b, 0xd7, 0xfa, 0xf9, + 0xca, 0x6d, 0x5d, 0x5c, 0xb9, 0xad, 0x17, 0x57, 0x6e, 0xeb, 0xdb, 0xc6, 0xbf, 0xd3, 0xd4, 0x56, + 0xb9, 0xbd, 0xf7, 0x6f, 0x00, 0x00, 0x00, 0xff, 0xff, 0xa5, 0x4d, 0x41, 0xea, 0xc4, 0x06, 0x00, + 0x00, +} + +func (this *PrometheusRequestHeader) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + that1, ok := that.(*PrometheusRequestHeader) + if !ok { + that2, ok := that.(PrometheusRequestHeader) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if this.Name != that1.Name { + return false + } + if len(this.Values) != len(that1.Values) { + return false + } + for i := range this.Values { + if this.Values[i] != that1.Values[i] { + return false + } + } + return true +} func (this *PrometheusRequest) Equal(that interface{}) bool { if that == nil { return this == nil @@ -615,6 +709,14 @@ func (this *PrometheusRequest) Equal(that interface{}) bool { if !this.CachingOptions.Equal(&that1.CachingOptions) { return false } + if len(this.Headers) != len(that1.Headers) { + return false + } + for i := range this.Headers { + if !this.Headers[i].Equal(that1.Headers[i]) { + return false + } + } return true } func (this *PrometheusResponseHeader) Equal(that interface{}) bool { @@ -848,11 +950,22 @@ func (this *CachingOptions) Equal(that interface{}) bool { } return true } +func (this *PrometheusRequestHeader) GoString() string { + if this == nil { + return "nil" + } + s := make([]string, 0, 6) + s = append(s, "&queryrange.PrometheusRequestHeader{") + s = append(s, "Name: "+fmt.Sprintf("%#v", this.Name)+",\n") + s = append(s, "Values: "+fmt.Sprintf("%#v", this.Values)+",\n") + s = append(s, "}") + return strings.Join(s, "") +} func (this *PrometheusRequest) GoString() string { if this == nil { return "nil" } - s := make([]string, 0, 11) + s := make([]string, 0, 12) s = append(s, "&queryrange.PrometheusRequest{") s = append(s, "Path: "+fmt.Sprintf("%#v", this.Path)+",\n") s = append(s, "Start: "+fmt.Sprintf("%#v", this.Start)+",\n") @@ -861,6 +974,9 @@ func (this *PrometheusRequest) GoString() string { s = append(s, "Timeout: "+fmt.Sprintf("%#v", this.Timeout)+",\n") s = append(s, "Query: "+fmt.Sprintf("%#v", this.Query)+",\n") s = append(s, "CachingOptions: "+strings.Replace(this.CachingOptions.GoString(), `&`, ``, 1)+",\n") + if this.Headers != nil { + s = append(s, "Headers: "+fmt.Sprintf("%#v", this.Headers)+",\n") + } s = append(s, "}") return strings.Join(s, "") } @@ -975,6 +1091,45 @@ func valueToGoStringQueryrange(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 *PrometheusRequestHeader) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *PrometheusRequestHeader) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *PrometheusRequestHeader) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Values) > 0 { + for iNdEx := len(m.Values) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.Values[iNdEx]) + copy(dAtA[i:], m.Values[iNdEx]) + i = encodeVarintQueryrange(dAtA, i, uint64(len(m.Values[iNdEx]))) + i-- + dAtA[i] = 0x12 + } + } + if len(m.Name) > 0 { + i -= len(m.Name) + copy(dAtA[i:], m.Name) + i = encodeVarintQueryrange(dAtA, i, uint64(len(m.Name))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + func (m *PrometheusRequest) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -995,6 +1150,20 @@ func (m *PrometheusRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.Headers) > 0 { + for iNdEx := len(m.Headers) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Headers[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQueryrange(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x42 + } + } { size, err := m.CachingOptions.MarshalToSizedBuffer(dAtA[:i]) if err != nil { @@ -1387,6 +1556,25 @@ func encodeVarintQueryrange(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) return base } +func (m *PrometheusRequestHeader) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Name) + if l > 0 { + n += 1 + l + sovQueryrange(uint64(l)) + } + if len(m.Values) > 0 { + for _, s := range m.Values { + l = len(s) + n += 1 + l + sovQueryrange(uint64(l)) + } + } + return n +} + func (m *PrometheusRequest) Size() (n int) { if m == nil { return 0 @@ -1414,6 +1602,12 @@ func (m *PrometheusRequest) Size() (n int) { } l = m.CachingOptions.Size() n += 1 + l + sovQueryrange(uint64(l)) + if len(m.Headers) > 0 { + for _, e := range m.Headers { + l = e.Size() + n += 1 + l + sovQueryrange(uint64(l)) + } + } return n } @@ -1565,10 +1759,26 @@ func sovQueryrange(x uint64) (n int) { func sozQueryrange(x uint64) (n int) { return sovQueryrange(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } +func (this *PrometheusRequestHeader) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&PrometheusRequestHeader{`, + `Name:` + fmt.Sprintf("%v", this.Name) + `,`, + `Values:` + fmt.Sprintf("%v", this.Values) + `,`, + `}`, + }, "") + return s +} func (this *PrometheusRequest) String() string { if this == nil { return "nil" } + repeatedStringForHeaders := "[]*PrometheusRequestHeader{" + for _, f := range this.Headers { + repeatedStringForHeaders += strings.Replace(f.String(), "PrometheusRequestHeader", "PrometheusRequestHeader", 1) + "," + } + repeatedStringForHeaders += "}" s := strings.Join([]string{`&PrometheusRequest{`, `Path:` + fmt.Sprintf("%v", this.Path) + `,`, `Start:` + fmt.Sprintf("%v", this.Start) + `,`, @@ -1577,6 +1787,7 @@ func (this *PrometheusRequest) String() string { `Timeout:` + strings.Replace(strings.Replace(fmt.Sprintf("%v", this.Timeout), "Duration", "duration.Duration", 1), `&`, ``, 1) + `,`, `Query:` + fmt.Sprintf("%v", this.Query) + `,`, `CachingOptions:` + strings.Replace(strings.Replace(this.CachingOptions.String(), "CachingOptions", "CachingOptions", 1), `&`, ``, 1) + `,`, + `Headers:` + repeatedStringForHeaders + `,`, `}`, }, "") return s @@ -1690,6 +1901,123 @@ func valueToStringQueryrange(v interface{}) string { pv := reflect.Indirect(rv).Interface() return fmt.Sprintf("*%v", pv) } +func (m *PrometheusRequestHeader) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQueryrange + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: PrometheusRequestHeader: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: PrometheusRequestHeader: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQueryrange + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQueryrange + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQueryrange + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Name = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Values", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQueryrange + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQueryrange + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQueryrange + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Values = append(m.Values, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQueryrange(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthQueryrange + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthQueryrange + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func (m *PrometheusRequest) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -1906,6 +2234,40 @@ func (m *PrometheusRequest) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 8: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Headers", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQueryrange + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQueryrange + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQueryrange + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Headers = append(m.Headers, &PrometheusRequestHeader{}) + if err := m.Headers[len(m.Headers)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipQueryrange(dAtA[iNdEx:]) diff --git a/pkg/querier/queryrange/queryrange.proto b/pkg/querier/queryrange/queryrange.proto index 188c6da328f..1725bdc4ef3 100644 --- a/pkg/querier/queryrange/queryrange.proto +++ b/pkg/querier/queryrange/queryrange.proto @@ -12,6 +12,10 @@ import "google/protobuf/any.proto"; option (gogoproto.marshaler_all) = true; option (gogoproto.unmarshaler_all) = true; +message PrometheusRequestHeader { + string Name = 1 [(gogoproto.jsontag) = "-"]; + repeated string Values = 2 [(gogoproto.jsontag) = "-"]; +} message PrometheusRequest { string path = 1; int64 start = 2; @@ -20,6 +24,7 @@ message PrometheusRequest { google.protobuf.Duration timeout = 5 [(gogoproto.stdduration) = true, (gogoproto.nullable) = false]; string query = 6; CachingOptions cachingOptions = 7 [(gogoproto.nullable) = false]; + repeated PrometheusRequestHeader Headers = 8 [(gogoproto.jsontag) = "-"]; } message PrometheusResponseHeader { diff --git a/pkg/querier/queryrange/results_cache_test.go b/pkg/querier/queryrange/results_cache_test.go index 06a36894353..e76b532ec64 100644 --- a/pkg/querier/queryrange/results_cache_test.go +++ b/pkg/querier/queryrange/results_cache_test.go @@ -32,6 +32,12 @@ var ( Step: 120 * 1e3, Query: "sum(container_memory_rss) by (namespace)", } + reqHeaders = []*PrometheusRequestHeader{ + { + Name: "Test-Header", + Values: []string{"test"}, + }, + } noCacheRequest = &PrometheusRequest{ Path: "/api/v1/query_range", Start: 1536673680 * 1e3, diff --git a/pkg/querier/queryrange/roundtrip.go b/pkg/querier/queryrange/roundtrip.go index 2741afef6ed..4620ff4e458 100644 --- a/pkg/querier/queryrange/roundtrip.go +++ b/pkg/querier/queryrange/roundtrip.go @@ -26,6 +26,7 @@ import ( "github.com/go-kit/log" "github.com/go-kit/log/level" + "github.com/grafana/dskit/flagext" "github.com/opentracing/opentracing-go" "github.com/pkg/errors" "github.com/prometheus/client_golang/prometheus" @@ -59,6 +60,8 @@ type Config struct { CacheResults bool `yaml:"cache_results"` MaxRetries int `yaml:"max_retries"` ShardedQueries bool `yaml:"parallelise_shardable_queries"` + // List of headers which query_range middleware chain would forward to downstream querier. + ForwardHeaders flagext.StringSlice `yaml:"forward_headers_list"` } // RegisterFlags adds the flags required to config this to the given FlagSet. @@ -68,6 +71,7 @@ func (cfg *Config) RegisterFlags(f *flag.FlagSet) { f.BoolVar(&cfg.AlignQueriesWithStep, "querier.align-querier-with-step", false, "Mutate incoming queries to align their start and end with their step.") f.BoolVar(&cfg.CacheResults, "querier.cache-results", false, "Cache query results.") f.BoolVar(&cfg.ShardedQueries, "querier.parallelise-shardable-queries", false, "Perform query parallelisations based on storage sharding configuration and query ASTs. This feature is supported only by the chunks storage engine.") + f.Var(&cfg.ForwardHeaders, "frontend.forward-headers-list", "List of headers forwarded by the query Frontend to downstream querier.") cfg.ResultsCacheConfig.RegisterFlags(f) } @@ -213,7 +217,7 @@ func NewTripperware( return func(next http.RoundTripper) http.RoundTripper { // Finally, if the user selected any query range middleware, stitch it in. if len(queryRangeMiddleware) > 0 { - queryrange := NewRoundTripper(next, codec, queryRangeMiddleware...) + queryrange := NewRoundTripper(next, codec, cfg.ForwardHeaders, queryRangeMiddleware...) return RoundTripFunc(func(r *http.Request) (*http.Response, error) { isQueryRange := strings.HasSuffix(r.URL.Path, "/query_range") op := "query" @@ -244,14 +248,16 @@ type roundTripper struct { next http.RoundTripper handler Handler codec Codec + headers []string } // NewRoundTripper merges a set of middlewares into an handler, then inject it into the `next` roundtripper // using the codec to translate requests and responses. -func NewRoundTripper(next http.RoundTripper, codec Codec, middlewares ...Middleware) http.RoundTripper { +func NewRoundTripper(next http.RoundTripper, codec Codec, headers []string, middlewares ...Middleware) http.RoundTripper { transport := roundTripper{ - next: next, - codec: codec, + next: next, + codec: codec, + headers: headers, } transport.handler = MergeMiddlewares(middlewares...).Wrap(&transport) return transport @@ -259,7 +265,8 @@ func NewRoundTripper(next http.RoundTripper, codec Codec, middlewares ...Middlew func (q roundTripper) RoundTrip(r *http.Request) (*http.Response, error) { - request, err := q.codec.DecodeRequest(r.Context(), r) + // include the headers specified in the roundTripper during decoding the request. + request, err := q.codec.DecodeRequest(r.Context(), r, q.headers) if err != nil { return nil, err } diff --git a/pkg/querier/queryrange/split_by_interval_test.go b/pkg/querier/queryrange/split_by_interval_test.go index 081d049ac7a..c026330c0ce 100644 --- a/pkg/querier/queryrange/split_by_interval_test.go +++ b/pkg/querier/queryrange/split_by_interval_test.go @@ -281,7 +281,7 @@ func TestSplitByDay(t *testing.T) { roundtripper := NewRoundTripper(singleHostRoundTripper{ host: u.Host, next: http.DefaultTransport, - }, PrometheusCodec, NewLimitsMiddleware(mockLimits{}), SplitByIntervalMiddleware(interval, mockLimits{}, PrometheusCodec, nil)) + }, PrometheusCodec, nil, NewLimitsMiddleware(mockLimits{}), SplitByIntervalMiddleware(interval, mockLimits{}, PrometheusCodec, nil)) req, err := http.NewRequest("GET", tc.path, http.NoBody) require.NoError(t, err)