From d70c8c7ec77a016b33645b2acd2fed9bea94b7a0 Mon Sep 17 00:00:00 2001 From: alanprot Date: Wed, 1 May 2024 15:13:47 -0700 Subject: [PATCH 1/2] Returning Prometheus Warnings Signed-off-by: alanprot --- .../tripperware/instantquery/instant_query.go | 10 +- .../instantquery/instant_query_test.go | 9 + .../instantquery/instantquery.pb.go | 153 +++++++++++----- .../instantquery/instantquery.proto | 1 + .../tripperware/queryrange/query_range.go | 6 + .../query_range_middlewares_test.go | 2 + .../queryrange/query_range_test.go | 28 +++ .../tripperware/queryrange/queryrange.pb.go | 167 ++++++++++++------ .../tripperware/queryrange/queryrange.proto | 1 + .../tripperware/queryrange/results_cache.go | 7 +- .../queryrange/results_cache_test.go | 25 ++- 11 files changed, 310 insertions(+), 99 deletions(-) diff --git a/pkg/querier/tripperware/instantquery/instant_query.go b/pkg/querier/tripperware/instantquery/instant_query.go index 252443f5a2..423e17bab0 100644 --- a/pkg/querier/tripperware/instantquery/instant_query.go +++ b/pkg/querier/tripperware/instantquery/instant_query.go @@ -18,6 +18,7 @@ import ( "github.com/prometheus/prometheus/model/labels" "github.com/prometheus/prometheus/model/timestamp" promqlparser "github.com/prometheus/prometheus/promql/parser" + "github.com/thanos-io/thanos/pkg/strutil" "github.com/weaveworks/common/httpgrpc" "google.golang.org/grpc/status" @@ -260,8 +261,12 @@ func (instantQueryCodec) MergeResponse(ctx context.Context, req tripperware.Requ } promResponses := make([]*PrometheusInstantQueryResponse, 0, len(responses)) + warnings := make([][]string, 0, len(responses)) for _, resp := range responses { promResponses = append(promResponses, resp.(*PrometheusInstantQueryResponse)) + if w := resp.(*PrometheusInstantQueryResponse).Warnings; w != nil { + warnings = append(warnings, w) + } } var data PrometheusInstantQueryData @@ -303,8 +308,9 @@ func (instantQueryCodec) MergeResponse(ctx context.Context, req tripperware.Requ } res := &PrometheusInstantQueryResponse{ - Status: queryrange.StatusSuccess, - Data: data, + Status: queryrange.StatusSuccess, + Data: data, + Warnings: strutil.MergeUnsortedSlices(warnings...), } return res, nil } diff --git a/pkg/querier/tripperware/instantquery/instant_query_test.go b/pkg/querier/tripperware/instantquery/instant_query_test.go index 0b40fc2526..aba71fb099 100644 --- a/pkg/querier/tripperware/instantquery/instant_query_test.go +++ b/pkg/querier/tripperware/instantquery/instant_query_test.go @@ -305,6 +305,15 @@ func TestMergeResponse(t *testing.T) { }, expectedResp: `{"status":"success","data":{"resultType":"vector","result":[{"metric":{"__name__":"up","job":"foo"},"value":[1,"1"]},{"metric":{"__name__":"up","job":"bar"},"value":[1,"2"]}]}}`, }, + { + name: "merge with warnings.", + req: &PrometheusRequest{Query: "topk(10, up) by(job)"}, + resps: []string{ + `{"status":"success","warnings":["warning1","warning2"],"data":{"resultType":"vector","result":[{"metric":{"__name__":"up","job":"foo"},"value":[1,"1"]}]}}`, + `{"status":"success","warnings":["warning1","warning3"],"data":{"resultType":"vector","result":[{"metric":{"__name__":"up","job":"bar"},"value":[1,"2"]}]}}`, + }, + expectedResp: `{"status":"success","data":{"resultType":"vector","result":[{"metric":{"__name__":"up","job":"foo"},"value":[1,"1"]},{"metric":{"__name__":"up","job":"bar"},"value":[1,"2"]}]},"warnings":["warning1","warning2","warning3"]}`, + }, { name: "merge two responses with stats", req: defaultReq, diff --git a/pkg/querier/tripperware/instantquery/instantquery.pb.go b/pkg/querier/tripperware/instantquery/instantquery.pb.go index cdf0b3ec2c..a401a19840 100644 --- a/pkg/querier/tripperware/instantquery/instantquery.pb.go +++ b/pkg/querier/tripperware/instantquery/instantquery.pb.go @@ -35,6 +35,7 @@ type PrometheusInstantQueryResponse struct { 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 []*tripperware.PrometheusResponseHeader `protobuf:"bytes,5,rep,name=Headers,proto3" json:"-"` + Warnings []string `protobuf:"bytes,6,rep,name=Warnings,proto3" json:"warnings,omitempty"` } func (m *PrometheusInstantQueryResponse) Reset() { *m = PrometheusInstantQueryResponse{} } @@ -104,6 +105,13 @@ func (m *PrometheusInstantQueryResponse) GetHeaders() []*tripperware.PrometheusR return nil } +func (m *PrometheusInstantQueryResponse) GetWarnings() []string { + if m != nil { + return m.Warnings + } + return nil +} + type PrometheusInstantQueryData struct { ResultType string `protobuf:"bytes,1,opt,name=ResultType,proto3" json:"resultType"` Result PrometheusInstantQueryResult `protobuf:"bytes,2,opt,name=Result,proto3" json:"result"` @@ -403,48 +411,50 @@ func init() { func init() { proto.RegisterFile("instantquery.proto", fileDescriptor_d2ce36475a368033) } var fileDescriptor_d2ce36475a368033 = []byte{ - // 652 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x54, 0xcf, 0x4f, 0xd4, 0x40, - 0x14, 0xee, 0x00, 0x5b, 0xe0, 0x2d, 0xa0, 0x19, 0x88, 0xae, 0x84, 0x4c, 0x49, 0xa3, 0xc9, 0x6a, - 0xb4, 0x9b, 0xac, 0x31, 0xea, 0xd1, 0x2a, 0x06, 0xa3, 0x06, 0x9c, 0x25, 0x1e, 0xbc, 0xcd, 0x2e, - 0x93, 0xa5, 0xba, 0xa5, 0x75, 0x3a, 0x0b, 0xec, 0xcd, 0x3f, 0xc1, 0xbf, 0xc2, 0xf8, 0x3f, 0x78, - 0xf5, 0xc0, 0x91, 0x23, 0xf1, 0xd0, 0x48, 0xb9, 0x98, 0x3d, 0xe1, 0x7f, 0x60, 0x3a, 0x33, 0x85, - 0xae, 0x3f, 0xf1, 0xd6, 0x7e, 0xef, 0xfb, 0xbe, 0xf7, 0xde, 0x37, 0xd3, 0x02, 0x0e, 0xb6, 0x13, - 0xc9, 0xb6, 0xe5, 0xdb, 0x3e, 0x17, 0x03, 0x2f, 0x16, 0x91, 0x8c, 0xf0, 0x4c, 0x19, 0x5b, 0x5c, - 0xe8, 0x46, 0xdd, 0x48, 0x15, 0x1a, 0xf9, 0x93, 0xe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b9, 0x9f, 0x10, 0xd8, 0x1a, 0xc3, 0x7b, 0x60, 0xf7, 0x58, 0x9b, - 0xf7, 0x0a, 0xe5, 0xbc, 0x57, 0x7c, 0x95, 0xde, 0xb3, 0x1c, 0x5f, 0x67, 0x81, 0xf0, 0x9f, 0xe6, - 0xd9, 0x7f, 0x49, 0x9d, 0xff, 0xfa, 0xaa, 0xb5, 0xfe, 0xc1, 0x26, 0x8b, 0x25, 0x17, 0xf9, 0xc1, - 0x85, 0x5c, 0x8a, 0xa0, 0x43, 0x4d, 0x3f, 0x7c, 0x17, 0x6c, 0x3d, 0x8f, 0xb9, 0x0c, 0x17, 0xcf, - 0x3a, 0xeb, 0xd9, 0xfc, 0x59, 0x73, 0xe4, 0x95, 0x1d, 0xd6, 0xeb, 0x73, 0x6a, 0xe8, 0xee, 0x1a, - 0xd8, 0x3a, 0x15, 0xbc, 0x02, 0xb3, 0x1a, 0x6b, 0x49, 0xc1, 0x59, 0x58, 0xec, 0x70, 0x65, 0xe4, - 0x0e, 0xb4, 0x4a, 0x0c, 0x7f, 0x22, 0xb7, 0xa4, 0xa3, 0x2a, 0xdf, 0x3f, 0x38, 0x22, 0xd6, 0xe1, - 0x11, 0xb1, 0x4e, 0x8e, 0x08, 0x7a, 0x97, 0x11, 0xf4, 0x31, 0x23, 0x68, 0x3f, 0x23, 0xe8, 0x20, - 0x23, 0xe8, 0x6b, 0x46, 0xd0, 0xb7, 0x8c, 0x58, 0x27, 0x19, 0x41, 0xef, 0x8f, 0x89, 0x75, 0x70, - 0x4c, 0xac, 0xc3, 0x63, 0x62, 0xbd, 0x1a, 0xf9, 0x0d, 0xb6, 0x6d, 0xf5, 0xdf, 0xb9, 0xfd, 0x23, - 0x00, 0x00, 0xff, 0xff, 0xa2, 0x2a, 0x9a, 0xd2, 0x31, 0x05, 0x00, 0x00, + // 679 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x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, 0x4c, 0x70, 0xbf, 0x4b, 0x4c, + 0x3d, 0x74, 0x07, 0xda, 0xba, 0x1f, 0x73, 0x19, 0x2e, 0x9e, 0x55, 0xd6, 0xbd, 0x79, 0x73, 0x66, + 0xe5, 0xe5, 0x1d, 0xda, 0x1f, 0x32, 0x62, 0xe8, 0xf5, 0x75, 0x68, 0x6b, 0x57, 0xd0, 0x2a, 0x9c, + 0xd3, 0x58, 0x5b, 0x70, 0x46, 0x83, 0x7c, 0x86, 0xcb, 0x63, 0x77, 0xa0, 0x5d, 0x60, 0x78, 0x93, + 0x32, 0x25, 0x19, 0x57, 0x79, 0xde, 0xc1, 0x11, 0xb6, 0x0e, 0x8f, 0xb0, 0x75, 0x72, 0x84, 0xc1, + 0xbb, 0x14, 0x83, 0x8f, 0x29, 0x06, 0xfb, 0x29, 0x06, 0x07, 0x29, 0x06, 0x5f, 0x52, 0x0c, 0xbe, + 0xa6, 0xd8, 0x3a, 0x49, 0x31, 0x78, 0x7f, 0x8c, 0xad, 0x83, 0x63, 0x6c, 0x1d, 0x1e, 0x63, 0xeb, + 0xd5, 0xd8, 0xd3, 0xd9, 0xb1, 0xd5, 0x5b, 0x75, 0xeb, 0x47, 0x00, 0x00, 0x00, 0xff, 0xff, 0x18, + 0x40, 0x53, 0x5d, 0x65, 0x05, 0x00, 0x00, } func (this *PrometheusInstantQueryResponse) Equal(that interface{}) bool { @@ -486,6 +496,14 @@ func (this *PrometheusInstantQueryResponse) Equal(that interface{}) bool { return false } } + if len(this.Warnings) != len(that1.Warnings) { + return false + } + for i := range this.Warnings { + if this.Warnings[i] != that1.Warnings[i] { + return false + } + } return true } func (this *PrometheusInstantQueryData) Equal(that interface{}) bool { @@ -714,7 +732,7 @@ func (this *PrometheusInstantQueryResponse) GoString() string { if this == nil { return "nil" } - s := make([]string, 0, 9) + s := make([]string, 0, 10) s = append(s, "&instantquery.PrometheusInstantQueryResponse{") s = append(s, "Status: "+fmt.Sprintf("%#v", this.Status)+",\n") s = append(s, "Data: "+strings.Replace(this.Data.GoString(), `&`, ``, 1)+",\n") @@ -723,6 +741,7 @@ func (this *PrometheusInstantQueryResponse) GoString() string { if this.Headers != nil { s = append(s, "Headers: "+fmt.Sprintf("%#v", this.Headers)+",\n") } + s = append(s, "Warnings: "+fmt.Sprintf("%#v", this.Warnings)+",\n") s = append(s, "}") return strings.Join(s, "") } @@ -843,6 +862,15 @@ func (m *PrometheusInstantQueryResponse) MarshalToSizedBuffer(dAtA []byte) (int, _ = i var l int _ = l + if len(m.Warnings) > 0 { + for iNdEx := len(m.Warnings) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.Warnings[iNdEx]) + copy(dAtA[i:], m.Warnings[iNdEx]) + i = encodeVarintInstantquery(dAtA, i, uint64(len(m.Warnings[iNdEx]))) + i-- + dAtA[i] = 0x32 + } + } if len(m.Headers) > 0 { for iNdEx := len(m.Headers) - 1; iNdEx >= 0; iNdEx-- { { @@ -1188,6 +1216,12 @@ func (m *PrometheusInstantQueryResponse) Size() (n int) { n += 1 + l + sovInstantquery(uint64(l)) } } + if len(m.Warnings) > 0 { + for _, s := range m.Warnings { + l = len(s) + n += 1 + l + sovInstantquery(uint64(l)) + } + } return n } @@ -1326,6 +1360,7 @@ func (this *PrometheusInstantQueryResponse) String() string { `ErrorType:` + fmt.Sprintf("%v", this.ErrorType) + `,`, `Error:` + fmt.Sprintf("%v", this.Error) + `,`, `Headers:` + repeatedStringForHeaders + `,`, + `Warnings:` + fmt.Sprintf("%v", this.Warnings) + `,`, `}`, }, "") return s @@ -1623,6 +1658,38 @@ func (m *PrometheusInstantQueryResponse) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Warnings", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowInstantquery + } + 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 ErrInvalidLengthInstantquery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthInstantquery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Warnings = append(m.Warnings, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipInstantquery(dAtA[iNdEx:]) diff --git a/pkg/querier/tripperware/instantquery/instantquery.proto b/pkg/querier/tripperware/instantquery/instantquery.proto index 8a45015dd1..8240e2b78d 100644 --- a/pkg/querier/tripperware/instantquery/instantquery.proto +++ b/pkg/querier/tripperware/instantquery/instantquery.proto @@ -18,6 +18,7 @@ message PrometheusInstantQueryResponse { string ErrorType = 3 [(gogoproto.jsontag) = "errorType,omitempty"]; string Error = 4 [(gogoproto.jsontag) = "error,omitempty"]; repeated tripperware.PrometheusResponseHeader Headers = 5 [(gogoproto.jsontag) = "-"]; + repeated string Warnings = 6 [(gogoproto.jsontag) = "warnings,omitempty"]; } message PrometheusInstantQueryData { diff --git a/pkg/querier/tripperware/queryrange/query_range.go b/pkg/querier/tripperware/queryrange/query_range.go index 8ca3364401..00e7ea2928 100644 --- a/pkg/querier/tripperware/queryrange/query_range.go +++ b/pkg/querier/tripperware/queryrange/query_range.go @@ -19,6 +19,7 @@ import ( otlog "github.com/opentracing/opentracing-go/log" "github.com/prometheus/common/model" "github.com/prometheus/prometheus/model/timestamp" + "github.com/thanos-io/thanos/pkg/strutil" "github.com/weaveworks/common/httpgrpc" "github.com/cortexproject/cortex/pkg/querier/tripperware" @@ -135,8 +136,12 @@ func (c prometheusCodec) MergeResponse(ctx context.Context, _ tripperware.Reques } promResponses := make([]*PrometheusResponse, 0, len(responses)) + warnings := make([][]string, 0, len(responses)) for _, res := range responses { promResponses = append(promResponses, res.(*PrometheusResponse)) + if w := res.(*PrometheusResponse).Warnings; w != nil { + warnings = append(warnings, w) + } } // Merge the responses. @@ -153,6 +158,7 @@ func (c prometheusCodec) MergeResponse(ctx context.Context, _ tripperware.Reques Result: sampleStreams, Stats: statsMerge(c.sharded, promResponses), }, + Warnings: strutil.MergeUnsortedSlices(warnings...), } return &response, nil diff --git a/pkg/querier/tripperware/queryrange/query_range_middlewares_test.go b/pkg/querier/tripperware/queryrange/query_range_middlewares_test.go index 619a65c210..526295ac9a 100644 --- a/pkg/querier/tripperware/queryrange/query_range_middlewares_test.go +++ b/pkg/querier/tripperware/queryrange/query_range_middlewares_test.go @@ -32,6 +32,8 @@ func TestRoundTrip(t *testing.T) { var err error if r.RequestURI == query { _, err = w.Write([]byte(responseBody)) + } else if r.RequestURI == queryWithWarnings { + _, err = w.Write([]byte(responseBodyWithWarnings)) } else { _, err = w.Write([]byte("bar")) } diff --git a/pkg/querier/tripperware/queryrange/query_range_test.go b/pkg/querier/tripperware/queryrange/query_range_test.go index 596338d587..0da8489188 100644 --- a/pkg/querier/tripperware/queryrange/query_range_test.go +++ b/pkg/querier/tripperware/queryrange/query_range_test.go @@ -91,7 +91,9 @@ func TestRequest(t *testing.T) { func TestResponse(t *testing.T) { t.Parallel() r := *parsedResponse + rWithWarnings := *parsedResponseWithWarnings r.Headers = respHeaders + rWithWarnings.Headers = respHeaders for i, tc := range []struct { body string expected *PrometheusResponse @@ -102,6 +104,10 @@ func TestResponse(t *testing.T) { body: responseBody, expected: &r, }, + { + body: responseBodyWithWarnings, + expected: &rWithWarnings, + }, { body: responseBody, cancelCtxBeforeDecode: true, @@ -390,6 +396,28 @@ func TestMergeAPIResponses(t *testing.T) { }, }, }, + { + name: "Merge response with warnings.", + input: []tripperware.Response{ + mustParse(t, `{"status":"success","warnings":["warning1","warning2"],"data":{"resultType":"matrix","result":[{"metric":{"a":"b","c":"d"},"values":[[1,"1"]]}]}}`), + mustParse(t, `{"status":"success","warnings":["warning1","warning3"],"data":{"resultType":"matrix","result":[{"metric":{"a":"b","c":"d"},"values":[[1,"1"]]}]}}`), + }, + expected: &PrometheusResponse{ + Status: StatusSuccess, + Warnings: []string{"warning1", "warning2", "warning3"}, + Data: PrometheusData{ + ResultType: matrix, + Result: []tripperware.SampleStream{ + { + Labels: []cortexpb.LabelAdapter{{Name: "a", Value: "b"}, {Name: "c", Value: "d"}}, + Samples: []cortexpb.Sample{ + {Value: 1, TimestampMs: 1000}, + }, + }, + }, + }, + }, + }, { name: "Merging of samples where there is complete overlap.", input: []tripperware.Response{ diff --git a/pkg/querier/tripperware/queryrange/queryrange.pb.go b/pkg/querier/tripperware/queryrange/queryrange.pb.go index 2a179187fa..edf1f6cbe8 100644 --- a/pkg/querier/tripperware/queryrange/queryrange.pb.go +++ b/pkg/querier/tripperware/queryrange/queryrange.pb.go @@ -144,6 +144,7 @@ type PrometheusResponse struct { 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 []*tripperware.PrometheusResponseHeader `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{} } @@ -213,6 +214,13 @@ func (m *PrometheusResponse) GetHeaders() []*tripperware.PrometheusResponseHeade return nil } +func (m *PrometheusResponse) GetWarnings() []string { + if m != nil { + return m.Warnings + } + return nil +} + type PrometheusData struct { ResultType string `protobuf:"bytes,1,opt,name=ResultType,proto3" json:"resultType"` Result []tripperware.SampleStream `protobuf:"bytes,2,rep,name=Result,proto3" json:"result"` @@ -446,55 +454,57 @@ func init() { func init() { proto.RegisterFile("queryrange.proto", fileDescriptor_79b02382e213d0b2) } var fileDescriptor_79b02382e213d0b2 = []byte{ - // 763 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x54, 0xbd, 0x6e, 0xdb, 0x48, - 0x10, 0x16, 0x45, 0xfd, 0xae, 0x0f, 0xb2, 0x6f, 0x6d, 0xdc, 0x51, 0x2a, 0x48, 0x41, 0xf0, 0x01, - 0x3a, 0xc0, 0x47, 0x01, 0x3e, 0x5c, 0x79, 0x41, 0x4c, 0xff, 0xc0, 0x49, 0xe3, 0x80, 0x4e, 0x95, - 0x26, 0x58, 0x89, 0x13, 0x8a, 0xb6, 0x44, 0xd2, 0xcb, 0x25, 0x62, 0x75, 0x79, 0x84, 0x94, 0x79, - 0x84, 0x20, 0xc8, 0x83, 0xb8, 0x74, 0x91, 0xc2, 0x15, 0x1d, 0xcb, 0x4d, 0xc0, 0xca, 0x8f, 0x10, - 0x70, 0x77, 0x29, 0xd1, 0x76, 0x82, 0x34, 0xc6, 0xcc, 0xec, 0x37, 0xa3, 0xef, 0xfb, 0x86, 0x63, - 0xb4, 0x76, 0x16, 0x03, 0x9d, 0x51, 0xe2, 0xbb, 0x60, 0x86, 0x34, 0x60, 0x01, 0x46, 0xcb, 0x4a, - 0x67, 0xc3, 0x0d, 0xdc, 0x80, 0x97, 0x07, 0x59, 0x24, 0x10, 0x1d, 0xdd, 0x0d, 0x02, 0x77, 0x02, - 0x03, 0x9e, 0x0d, 0xe3, 0x37, 0x03, 0x27, 0xa6, 0x84, 0x79, 0x81, 0x2f, 0xdf, 0xdb, 0x0f, 0xdf, - 0x89, 0x3f, 0x93, 0x4f, 0xbb, 0xae, 0xc7, 0xc6, 0xf1, 0xd0, 0x1c, 0x05, 0xd3, 0xc1, 0x28, 0xa0, - 0x0c, 0xce, 0x43, 0x1a, 0x9c, 0xc0, 0x88, 0xc9, 0x6c, 0x10, 0x9e, 0xba, 0x83, 0x8c, 0x80, 0x07, - 0x74, 0xc0, 0xa8, 0x17, 0x86, 0x40, 0xdf, 0x12, 0x0a, 0xbc, 0x26, 0x87, 0xf4, 0xae, 0xcb, 0xe8, - 0xf7, 0x17, 0x34, 0x98, 0x02, 0x1b, 0x43, 0x1c, 0xd9, 0x70, 0x16, 0x43,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e, 0x00, - 0x00, 0xff, 0xff, 0xe0, 0x63, 0x3d, 0x6f, 0xad, 0x05, 0x00, 0x00, + // 792 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x54, 0xcd, 0x4e, 0xe3, 0x48, + 0x10, 0x8e, 0xe3, 0xc4, 0x71, 0x9a, 0x55, 0x60, 0x1b, 0xc4, 0x3a, 0x39, 0xd8, 0x51, 0xc4, 0x4a, + 0x59, 0x89, 0x75, 0x24, 0x56, 0x7b, 0xdc, 0xd5, 0x62, 0x7e, 0xc4, 0xee, 0x85, 0x95, 0x19, 0x69, + 0xa4, 0xb9, 0x8c, 0x3a, 0x71, 0x8f, 0x63, 0x48, 0x6c, 0xd3, 0xdd, 0x16, 0xe4, 0x36, 0x8f, 0x30, + 0xc7, 0x79, 0x84, 0x39, 0xcc, 0x83, 0x70, 0xe4, 0x30, 0x07, 0x4e, 0x66, 0x08, 0x97, 0x91, 0x4f, + 0x3c, 0xc2, 0xc8, 0xdd, 0xed, 0xc4, 0x80, 0xd0, 0x5c, 0xac, 0xaa, 0xea, 0xaf, 0xca, 0xf5, 0x7d, + 0xd5, 0xd5, 0x60, 0xed, 0x3c, 0xc1, 0x64, 0x46, 0x50, 0xe8, 0x63, 0x3b, 0x26, 0x11, 0x8b, 0x20, + 0x58, 0x46, 0x3a, 0x1b, 0x7e, 0xe4, 0x47, 0x3c, 0x3c, 0xc8, 0x2d, 0x81, 0xe8, 0x98, 0x7e, 0x14, + 0xf9, 0x13, 0x3c, 0xe0, 0xde, 0x30, 0x79, 0x37, 0xf0, 0x12, 0x82, 0x58, 0x10, 0x85, 0xf2, 0xbc, + 0xfd, 0xf4, 0x1c, 0x85, 0x33, 0x79, 0xb4, 0xe7, 0x07, 0x6c, 0x9c, 0x0c, 0xed, 0x51, 0x34, 0x1d, + 0x8c, 0x22, 0xc2, 0xf0, 0x65, 0x4c, 0xa2, 0x53, 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, 0xf6, 0x78, 0xe3, 0xba, 0xbb, + 0xf0, 0x9d, 0x7f, 0xae, 0xef, 0xcc, 0xca, 0xcd, 0x9d, 0x59, 0x79, 0xb8, 0x33, 0x95, 0xf7, 0x73, + 0x53, 0xf9, 0x34, 0x37, 0x95, 0xab, 0xb9, 0xa9, 0x5c, 0xcf, 0x4d, 0xe5, 0xeb, 0xdc, 0x54, 0xbe, + 0xcd, 0xcd, 0xca, 0xc3, 0xdc, 0x54, 0x3e, 0xdc, 0x9b, 0x95, 0xeb, 0x7b, 0xb3, 0x72, 0x73, 0x6f, + 0x56, 0xde, 0x94, 0x9e, 0xee, 0xa1, 0xc6, 0x7b, 0xfb, 0xe3, 0x7b, 0x00, 0x00, 0x00, 0xff, 0xff, + 0x72, 0xed, 0xdd, 0xa8, 0xe1, 0x05, 0x00, 0x00, } func (this *PrometheusRequest) Equal(that interface{}) bool { @@ -589,6 +599,14 @@ func (this *PrometheusResponse) Equal(that interface{}) bool { return false } } + if len(this.Warnings) != len(that1.Warnings) { + return false + } + for i := range this.Warnings { + if this.Warnings[i] != that1.Warnings[i] { + return false + } + } return true } func (this *PrometheusData) Equal(that interface{}) bool { @@ -739,7 +757,7 @@ func (this *PrometheusResponse) GoString() string { if this == nil { return "nil" } - s := make([]string, 0, 9) + s := make([]string, 0, 10) s = append(s, "&queryrange.PrometheusResponse{") s = append(s, "Status: "+fmt.Sprintf("%#v", this.Status)+",\n") s = append(s, "Data: "+strings.Replace(this.Data.GoString(), `&`, ``, 1)+",\n") @@ -748,6 +766,7 @@ func (this *PrometheusResponse) GoString() string { if this.Headers != nil { s = append(s, "Headers: "+fmt.Sprintf("%#v", this.Headers)+",\n") } + s = append(s, "Warnings: "+fmt.Sprintf("%#v", this.Warnings)+",\n") s = append(s, "}") return strings.Join(s, "") } @@ -932,6 +951,15 @@ func (m *PrometheusResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.Warnings) > 0 { + for iNdEx := len(m.Warnings) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.Warnings[iNdEx]) + copy(dAtA[i:], m.Warnings[iNdEx]) + i = encodeVarintQueryrange(dAtA, i, uint64(len(m.Warnings[iNdEx]))) + i-- + dAtA[i] = 0x32 + } + } if len(m.Headers) > 0 { for iNdEx := len(m.Headers) - 1; iNdEx >= 0; iNdEx-- { { @@ -1242,6 +1270,12 @@ func (m *PrometheusResponse) Size() (n int) { n += 1 + l + sovQueryrange(uint64(l)) } } + if len(m.Warnings) > 0 { + for _, s := range m.Warnings { + l = len(s) + n += 1 + l + sovQueryrange(uint64(l)) + } + } return n } @@ -1366,6 +1400,7 @@ func (this *PrometheusResponse) String() string { `ErrorType:` + fmt.Sprintf("%v", this.ErrorType) + `,`, `Error:` + fmt.Sprintf("%v", this.Error) + `,`, `Headers:` + repeatedStringForHeaders + `,`, + `Warnings:` + fmt.Sprintf("%v", this.Warnings) + `,`, `}`, }, "") return s @@ -1932,6 +1967,38 @@ func (m *PrometheusResponse) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Warnings", 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.Warnings = append(m.Warnings, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipQueryrange(dAtA[iNdEx:]) diff --git a/pkg/querier/tripperware/queryrange/queryrange.proto b/pkg/querier/tripperware/queryrange/queryrange.proto index f09279693c..3642409504 100644 --- a/pkg/querier/tripperware/queryrange/queryrange.proto +++ b/pkg/querier/tripperware/queryrange/queryrange.proto @@ -30,6 +30,7 @@ message PrometheusResponse { string ErrorType = 3 [(gogoproto.jsontag) = "errorType,omitempty"]; string Error = 4 [(gogoproto.jsontag) = "error,omitempty"]; repeated tripperware.PrometheusResponseHeader Headers = 5 [(gogoproto.jsontag) = "-"]; + repeated string Warnings = 6 [(gogoproto.jsontag) = "warnings,omitempty"]; } message PrometheusData { diff --git a/pkg/querier/tripperware/queryrange/results_cache.go b/pkg/querier/tripperware/queryrange/results_cache.go index 413bc09abf..5d5f073ed7 100644 --- a/pkg/querier/tripperware/queryrange/results_cache.go +++ b/pkg/querier/tripperware/queryrange/results_cache.go @@ -93,7 +93,8 @@ func (PrometheusResponseExtractor) Extract(start, end int64, from tripperware.Re Result: extractMatrix(start, end, promRes.Data.Result), Stats: extractStats(start, end, promRes.Data.Stats), }, - Headers: promRes.Headers, + Headers: promRes.Headers, + Warnings: promRes.Warnings, } } @@ -108,6 +109,7 @@ func (PrometheusResponseExtractor) ResponseWithoutHeaders(resp tripperware.Respo Result: promRes.Data.Result, Stats: promRes.Data.Stats, }, + Warnings: promRes.Warnings, } } @@ -120,7 +122,8 @@ func (PrometheusResponseExtractor) ResponseWithoutStats(resp tripperware.Respons ResultType: promRes.Data.ResultType, Result: promRes.Data.Result, }, - Headers: promRes.Headers, + Headers: promRes.Headers, + Warnings: promRes.Warnings, } } diff --git a/pkg/querier/tripperware/queryrange/results_cache_test.go b/pkg/querier/tripperware/queryrange/results_cache_test.go index fcc6796d6a..abc216c4bd 100644 --- a/pkg/querier/tripperware/queryrange/results_cache_test.go +++ b/pkg/querier/tripperware/queryrange/results_cache_test.go @@ -21,8 +21,10 @@ import ( ) const ( - query = "/api/v1/query_range?end=1536716898&query=sum%28container_memory_rss%29+by+%28namespace%29&start=1536673680&stats=all&step=120" - responseBody = `{"status":"success","data":{"resultType":"matrix","result":[{"metric":{"foo":"bar"},"values":[[1536673680,"137"],[1536673780,"137"]]}]}}` + query = "/api/v1/query_range?end=1536716898&query=sum%28container_memory_rss%29+by+%28namespace%29&start=1536673680&stats=all&step=120" + queryWithWarnings = "/api/v1/query_range?end=1536716898&query=sumsum%28warnings%29&start=1536673680&stats=all&step=120&warnings=true" + responseBody = `{"status":"success","data":{"resultType":"matrix","result":[{"metric":{"foo":"bar"},"values":[[1536673680,"137"],[1536673780,"137"]]}]}}` + responseBodyWithWarnings = `{"status":"success","data":{"resultType":"matrix","result":[{"metric":{"foo":"bar"},"values":[[1536673680,"137"],[1536673780,"137"]]}]},"warnings":["test-warn"]}` ) var ( @@ -80,6 +82,25 @@ var ( }, }, } + + parsedResponseWithWarnings = &PrometheusResponse{ + Status: "success", + Warnings: []string{"test-warn"}, + Data: PrometheusData{ + ResultType: model.ValMatrix.String(), + Result: []tripperware.SampleStream{ + { + Labels: []cortexpb.LabelAdapter{ + {Name: "foo", Value: "bar"}, + }, + Samples: []cortexpb.Sample{ + {Value: 137, TimestampMs: 1536673680000}, + {Value: 137, TimestampMs: 1536673780000}, + }, + }, + }, + }, + } ) func mkAPIResponse(start, end, step int64) *PrometheusResponse { From 985e70c13b3db919fce497b2e60d4c7aaecfb1e4 Mon Sep 17 00:00:00 2001 From: alanprot Date: Wed, 1 May 2024 15:27:57 -0700 Subject: [PATCH 2/2] changelog Signed-off-by: alanprot --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f6fcd51543..63a940928a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * [CHANGE] Ruler: Remove `experimental.ruler.api-enable-rules-backup` flag and use `ruler.ring.replication-factor` to check if rules backup is enabled * [ENHANCEMENT] Query Frontend/Querier: Added store gateway postings touched count and touched size in Querier stats and log in Query Frontend. #5892 +* [ENHANCEMENT] Query Frontend/Querier: Returns `warnings` on prometheus query responses. #5916 * [CHANGE] Upgrade Dockerfile Node version from 14x to 18x. #5906 ## 1.17.0 in progress