From 0f848d880e5ec96631d03ff82b64821b88aff909 Mon Sep 17 00:00:00 2001 From: SungJin1212 Date: Thu, 19 Sep 2024 13:31:43 +0900 Subject: [PATCH] Add info field to query response (#6207) --- CHANGELOG.md | 1 + .../instantquery/instant_query_test.go | 9 + pkg/querier/tripperware/merge.go | 5 + pkg/querier/tripperware/query.pb.go | 218 ++++++++++++------ pkg/querier/tripperware/query.proto | 1 + .../query_range_middlewares_test.go | 2 + .../queryrange/query_range_test.go | 34 +++ .../tripperware/queryrange/queryrange.pb.go | 130 ++++++++--- .../tripperware/queryrange/queryrange.proto | 1 + .../tripperware/queryrange/results_cache.go | 5 + .../queryrange/results_cache_test.go | 26 +++ pkg/ruler/frontend_decoder.go | 17 +- pkg/util/api/response.go | 1 + 13 files changed, 334 insertions(+), 116 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b748b3d5db..61f8f3703f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * [FEATURE] Ruler: Experimental: Add `ruler.frontend-address` to allow query to query frontends instead of ingesters. #6151 * [FEATURE] Ruler: Minimize chances of missed rule group evaluations that can occur due to OOM kills, bad underlying nodes, or due to an unhealthy ruler that appears in the ring as healthy. This feature is enabled via `-ruler.enable-ha-evaluation` flag. #6129 +* [ENHANCEMENT] Query Frontend: Add info field to query response. #6207 * [ENHANCEMENT] Query Frontend: Add peakSample in query stats response. #6188 * [ENHANCEMENT] Ruler: Add new ruler metric `cortex_ruler_rule_groups_in_store` that is the total rule groups per tenant in store, which can be used to compare with `cortex_prometheus_rule_group_rules` to count the number of rule groups that are not loaded by a ruler. #5869 * [ENHANCEMENT] Ingester/Ring: New `READONLY` status on ring to be used by Ingester. New ingester API to change mode of ingester #6163 diff --git a/pkg/querier/tripperware/instantquery/instant_query_test.go b/pkg/querier/tripperware/instantquery/instant_query_test.go index 19219c67b1..6e2acbfc3c 100644 --- a/pkg/querier/tripperware/instantquery/instant_query_test.go +++ b/pkg/querier/tripperware/instantquery/instant_query_test.go @@ -362,6 +362,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"]}]},"warnings":["warning1","warning2","warning3"]}`, }, + { + name: "merge with infos.", + req: &tripperware.PrometheusRequest{Query: "topk(10, up) by(job)"}, + resps: []string{ + `{"status":"success","infos":["info1","info2"],"data":{"resultType":"vector","result":[{"metric":{"__name__":"up","job":"foo"},"value":[1,"1"]}]}}`, + `{"status":"success","infos":["info1","info3"],"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"]}]},"infos":["info1","info2","info3"]}`, + }, { name: "merge two responses with stats", req: defaultReq, diff --git a/pkg/querier/tripperware/merge.go b/pkg/querier/tripperware/merge.go index 44c4dcbd75..5eb37387c5 100644 --- a/pkg/querier/tripperware/merge.go +++ b/pkg/querier/tripperware/merge.go @@ -42,11 +42,15 @@ func MergeResponse(ctx context.Context, sumStats bool, req Request, responses .. } promResponses := make([]*PrometheusResponse, 0, len(responses)) warnings := make([][]string, 0, len(responses)) + infos := make([][]string, 0, len(responses)) for _, resp := range responses { promResponses = append(promResponses, resp.(*PrometheusResponse)) if w := resp.(*PrometheusResponse).Warnings; w != nil { warnings = append(warnings, w) } + if i := resp.(*PrometheusResponse).Infos; i != nil { + infos = append(infos, i) + } } // Check if it is a range query. Range query passed req as nil since @@ -96,6 +100,7 @@ func MergeResponse(ctx context.Context, sumStats bool, req Request, responses .. Status: StatusSuccess, Data: data, Warnings: strutil.MergeUnsortedSlices(warnings...), + Infos: strutil.MergeUnsortedSlices(infos...), } return res, nil } diff --git a/pkg/querier/tripperware/query.pb.go b/pkg/querier/tripperware/query.pb.go index d21f9732df..ed3fb15084 100644 --- a/pkg/querier/tripperware/query.pb.go +++ b/pkg/querier/tripperware/query.pb.go @@ -38,6 +38,7 @@ type PrometheusResponse struct { 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"` + Infos []string `protobuf:"bytes,7,rep,name=Infos,proto3" json:"infos,omitempty"` } func (m *PrometheusResponse) Reset() { *m = PrometheusResponse{} } @@ -114,6 +115,13 @@ func (m *PrometheusResponse) GetWarnings() []string { return nil } +func (m *PrometheusResponse) GetInfos() []string { + if m != nil { + return m.Infos + } + return nil +} + type PrometheusData struct { ResultType string `protobuf:"bytes,1,opt,name=ResultType,proto3" json:"resultType"` Result PrometheusQueryResult `protobuf:"bytes,2,opt,name=Result,proto3" json:"result"` @@ -986,82 +994,83 @@ func init() { func init() { proto.RegisterFile("query.proto", fileDescriptor_5c6ac9b241082464) } var fileDescriptor_5c6ac9b241082464 = []byte{ - // 1189 bytes of a gzipped FileDescriptorProto + // 1207 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xc4, 0x56, 0x4b, 0x6f, 0x1b, 0xd5, - 0x17, 0xf7, 0xf8, 0x31, 0x71, 0x8e, 0xd3, 0xa4, 0xff, 0x9b, 0x3e, 0x9c, 0xfe, 0xcb, 0x8c, 0x19, - 0x81, 0x14, 0x04, 0x71, 0x44, 0x10, 0x54, 0x80, 0x54, 0x91, 0x81, 0x40, 0x28, 0x94, 0xa4, 0x37, - 0x51, 0x91, 0xd8, 0x54, 0xd7, 0xf6, 0xc5, 0x19, 0xe2, 0xf1, 0x4c, 0xef, 0xdc, 0x69, 0x62, 0x56, - 0x7c, 0x02, 0xc4, 0x1a, 0x89, 0x05, 0x3b, 0x16, 0x7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 0xff, - 0x8f, 0xdd, 0x32, 0xe5, 0x95, 0x7e, 0xe7, 0xdf, 0x00, 0x00, 0x00, 0xff, 0xff, 0x64, 0x1e, 0xe3, - 0x30, 0x86, 0x0b, 0x00, 0x00, + 0x17, 0xf7, 0xf8, 0x31, 0x76, 0x8e, 0xd3, 0xa4, 0xff, 0x9b, 0x3e, 0x9c, 0xfe, 0xcb, 0x8c, 0x19, + 0x81, 0x14, 0x04, 0x75, 0x44, 0x10, 0x54, 0x80, 0x54, 0xd1, 0x81, 0x42, 0x5a, 0x28, 0x6d, 0x6f, + 0xaa, 0x22, 0xb1, 0xa9, 0xae, 0xed, 0x5b, 0x67, 0x88, 0xe7, 0xd1, 0x3b, 0x77, 0x9a, 0x98, 0x15, + 0x6b, 0x16, 0x88, 0x35, 0x12, 0x0b, 0x76, 0x2c, 0xf8, 0x20, 0x59, 0x76, 0x59, 0x21, 0x31, 0x22, + 0xce, 0x06, 0xcd, 0xaa, 0x1f, 0x01, 0xdd, 0xc7, 0xd8, 0xe3, 0xc4, 0x49, 0xd4, 0x15, 0x1b, 0x67, + 0xce, 0x39, 0xbf, 0xf3, 0xbc, 0xe7, 0x11, 0x68, 0x3e, 0x4d, 0x28, 0x1b, 0x75, 0x22, 0x16, 0xf2, + 0x10, 0x35, 0x39, 0xf3, 0xa2, 0x88, 0xb2, 0x5d, 0xc2, 0xe8, 0x95, 0x0b, 0x83, 0x70, 0x10, 0x4a, + 0xfe, 0xba, 0xf8, 0x52, 0x90, 0x2b, 0xd6, 0x20, 0x0c, 0x07, 0x43, 0xba, 0x2e, 0xa9, 0x6e, 0xf2, + 0x64, 0xbd, 0x9f, 0x30, 0xc2, 0xbd, 0x30, 0xd0, 0xf2, 0xd5, 0xa3, 0x72, 0x12, 0x68, 0xeb, 0x57, + 0x3e, 0x1c, 0x78, 0x7c, 0x3b, 0xe9, 0x76, 0x7a, 0xa1, 0xbf, 0xde, 0x0b, 0x19, 0xa7, 0x7b, 0x11, + 0x0b, 0xb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0x51, 0x94, 0x7d, 0x80, 0x35, 0x1c, 0x3d, 0x28, 0xee, 0x4e, 0x55, 0xb2, 0xb3, 0x57, + 0xf9, 0xff, 0xb4, 0xad, 0xa9, 0x6a, 0x71, 0x99, 0xde, 0x03, 0x53, 0xd5, 0x19, 0xdd, 0x82, 0x73, + 0x71, 0xe1, 0xdc, 0xe5, 0x65, 0x59, 0x9d, 0xe3, 0x40, 0x21, 0xf4, 0x66, 0x9e, 0xd5, 0x72, 0x6f, + 0x3e, 0x3f, 0xb0, 0x4a, 0x2f, 0x0e, 0xac, 0xd2, 0xcb, 0x03, 0xcb, 0xf8, 0x61, 0x6c, 0x19, 0xbf, + 0x8f, 0x2d, 0x63, 0x7f, 0x6c, 0x19, 0xcf, 0xc7, 0x96, 0xf1, 0xf7, 0xd8, 0x32, 0xfe, 0x19, 0x5b, + 0xa5, 0x97, 0x63, 0xcb, 0xf8, 0xf9, 0xd0, 0x2a, 0x3d, 0x3f, 0xb4, 0x4a, 0x2f, 0x0e, 0xad, 0xd2, + 0xb7, 0xc5, 0x7f, 0xc7, 0xbb, 0xa6, 0xbc, 0xd2, 0xef, 0xfd, 0x1b, 0x00, 0x00, 0xff, 0xff, 0x31, + 0xdc, 0x8d, 0x85, 0xb1, 0x0b, 0x00, 0x00, } func (this *PrometheusResponse) Equal(that interface{}) bool { @@ -1111,6 +1120,14 @@ func (this *PrometheusResponse) Equal(that interface{}) bool { return false } } + if len(this.Infos) != len(that1.Infos) { + return false + } + for i := range this.Infos { + if this.Infos[i] != that1.Infos[i] { + return false + } + } return true } func (this *PrometheusData) Equal(that interface{}) bool { @@ -1665,7 +1682,7 @@ func (this *PrometheusResponse) GoString() string { if this == nil { return "nil" } - s := make([]string, 0, 10) + s := make([]string, 0, 11) s = append(s, "&tripperware.PrometheusResponse{") s = append(s, "Status: "+fmt.Sprintf("%#v", this.Status)+",\n") s = append(s, "Data: "+strings.Replace(this.Data.GoString(), `&`, ``, 1)+",\n") @@ -1675,6 +1692,7 @@ func (this *PrometheusResponse) GoString() string { s = append(s, "Headers: "+fmt.Sprintf("%#v", this.Headers)+",\n") } s = append(s, "Warnings: "+fmt.Sprintf("%#v", this.Warnings)+",\n") + s = append(s, "Infos: "+fmt.Sprintf("%#v", this.Infos)+",\n") s = append(s, "}") return strings.Join(s, "") } @@ -1942,6 +1960,15 @@ func (m *PrometheusResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.Infos) > 0 { + for iNdEx := len(m.Infos) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.Infos[iNdEx]) + copy(dAtA[i:], m.Infos[iNdEx]) + i = encodeVarintQuery(dAtA, i, uint64(len(m.Infos[iNdEx]))) + i-- + dAtA[i] = 0x3a + } + } if len(m.Warnings) > 0 { for iNdEx := len(m.Warnings) - 1; iNdEx >= 0; iNdEx-- { i -= len(m.Warnings[iNdEx]) @@ -2764,6 +2791,12 @@ func (m *PrometheusResponse) Size() (n int) { n += 1 + l + sovQuery(uint64(l)) } } + if len(m.Infos) > 0 { + for _, s := range m.Infos { + l = len(s) + n += 1 + l + sovQuery(uint64(l)) + } + } return n } @@ -3102,6 +3135,7 @@ func (this *PrometheusResponse) String() string { `Error:` + fmt.Sprintf("%v", this.Error) + `,`, `Headers:` + repeatedStringForHeaders + `,`, `Warnings:` + fmt.Sprintf("%v", this.Warnings) + `,`, + `Infos:` + fmt.Sprintf("%v", this.Infos) + `,`, `}`, }, "") return s @@ -3573,6 +3607,38 @@ func (m *PrometheusResponse) Unmarshal(dAtA []byte) error { } m.Warnings = append(m.Warnings, string(dAtA[iNdEx:postIndex])) iNdEx = postIndex + case 7: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Infos", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + 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 ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Infos = append(m.Infos, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipQuery(dAtA[iNdEx:]) diff --git a/pkg/querier/tripperware/query.proto b/pkg/querier/tripperware/query.proto index 0bac43c6c3..2df1b705a1 100644 --- a/pkg/querier/tripperware/query.proto +++ b/pkg/querier/tripperware/query.proto @@ -19,6 +19,7 @@ message PrometheusResponse { string Error = 4 [(gogoproto.jsontag) = "error,omitempty"]; repeated tripperware.PrometheusResponseHeader Headers = 5 [(gogoproto.jsontag) = "-"]; repeated string Warnings = 6 [(gogoproto.jsontag) = "warnings,omitempty"]; + repeated string Infos = 7 [(gogoproto.jsontag) = "infos,omitempty"]; } message PrometheusData { diff --git a/pkg/querier/tripperware/queryrange/query_range_middlewares_test.go b/pkg/querier/tripperware/queryrange/query_range_middlewares_test.go index 526295ac9a..6981f5d7d4 100644 --- a/pkg/querier/tripperware/queryrange/query_range_middlewares_test.go +++ b/pkg/querier/tripperware/queryrange/query_range_middlewares_test.go @@ -34,6 +34,8 @@ func TestRoundTrip(t *testing.T) { _, err = w.Write([]byte(responseBody)) } else if r.RequestURI == queryWithWarnings { _, err = w.Write([]byte(responseBodyWithWarnings)) + } else if r.RequestURI == queryWithInfos { + _, err = w.Write([]byte(responseBodyWithInfos)) } 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 476b07186b..f603e19494 100644 --- a/pkg/querier/tripperware/queryrange/query_range_test.go +++ b/pkg/querier/tripperware/queryrange/query_range_test.go @@ -92,8 +92,10 @@ func TestResponse(t *testing.T) { t.Parallel() r := *parsedResponse rWithWarnings := *parsedResponseWithWarnings + rWithInfos := *parsedResponseWithInfos r.Headers = respHeaders rWithWarnings.Headers = respHeaders + rWithInfos.Headers = respHeaders for i, tc := range []struct { body string expected *tripperware.PrometheusResponse @@ -108,6 +110,10 @@ func TestResponse(t *testing.T) { body: responseBodyWithWarnings, expected: &rWithWarnings, }, + { + body: responseBodyWithInfos, + expected: &rWithInfos, + }, { body: responseBody, cancelCtxBeforeDecode: true, @@ -484,6 +490,34 @@ func TestMergeAPIResponses(t *testing.T) { }, }, }, + { + name: "Merge response with infos.", + input: []tripperware.Response{ + mustParse(t, `{"status":"success","infos":["info1","info2"],"data":{"resultType":"matrix","result":[{"metric":{"a":"b","c":"d"},"values":[[1,"1"]]}]}}`), + mustParse(t, `{"status":"success","infos":["info1","info3"],"data":{"resultType":"matrix","result":[{"metric":{"a":"b","c":"d"},"values":[[1,"1"]]}]}}`), + }, + expected: &tripperware.PrometheusResponse{ + Status: StatusSuccess, + Infos: []string{"info1", "info2", "info3"}, + Data: tripperware.PrometheusData{ + ResultType: matrix, + Result: tripperware.PrometheusQueryResult{ + Result: &tripperware.PrometheusQueryResult_Matrix{ + Matrix: &tripperware.Matrix{ + SampleStreams: []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 77290ee97a..1edbd8df03 100644 --- a/pkg/querier/tripperware/queryrange/queryrange.pb.go +++ b/pkg/querier/tripperware/queryrange/queryrange.pb.go @@ -33,6 +33,7 @@ type PrometheusResponse struct { 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"` + Infos []string `protobuf:"bytes,7,rep,name=Infos,proto3" json:"infos,omitempty"` } func (m *PrometheusResponse) Reset() { *m = PrometheusResponse{} } @@ -109,6 +110,13 @@ func (m *PrometheusResponse) GetWarnings() []string { return nil } +func (m *PrometheusResponse) GetInfos() []string { + if m != nil { + return m.Infos + } + 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"` @@ -176,37 +184,38 @@ func init() { func init() { proto.RegisterFile("queryrange.proto", fileDescriptor_79b02382e213d0b2) } var fileDescriptor_79b02382e213d0b2 = []byte{ - // 470 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x92, 0x41, 0x6f, 0xd3, 0x30, - 0x14, 0xc7, 0xe3, 0x76, 0x0d, 0xd4, 0x95, 0x0a, 0xf2, 0xd0, 0x08, 0x3d, 0x38, 0x55, 0x05, 0x52, - 0x91, 0x20, 0x91, 0x8a, 0xb8, 0x43, 0x80, 0x89, 0x1b, 0x28, 0x45, 0x42, 0xe2, 0xe6, 0x75, 0x4f, - 0x59, 0x60, 0xa9, 0x8d, 0xed, 0x68, 0xf4, 0xc6, 0x47, 0xe0, 0x63, 0xf0, 0x51, 0x76, 0xec, 0x81, - 0xc3, 0x4e, 0x16, 0x4d, 0x2f, 0x28, 0xa7, 0x7d, 0x04, 0x14, 0x27, 0x5b, 0x33, 0x71, 0xe0, 0x96, - 0xf7, 0xcf, 0xef, 0xff, 0xec, 0xf7, 0xf7, 0xc3, 0x77, 0xbf, 0xe6, 0x20, 0x57, 0x92, 0x2d, 0x13, - 0x08, 0x84, 0xe4, 0x9a, 0x13, 0xbc, 0x53, 0x46, 0xf7, 0x12, 0x9e, 0x70, 0x2b, 0x87, 0xd5, 0x57, - 0x4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 0xea, 0x95, 0xc6, 0x47, 0x4f, 0xe3, 0x2b, 0x33, 0x99, 0xe1, - 0xdb, 0x1f, 0x99, 0x5c, 0xa6, 0xcb, 0x44, 0x79, 0xee, 0xb8, 0x3b, 0xed, 0x47, 0x07, 0xa5, 0xf1, - 0xc9, 0x59, 0xa3, 0xb5, 0x0e, 0xbe, 0xe6, 0x26, 0xbf, 0x10, 0x1e, 0xde, 0x8c, 0x83, 0x04, 0x18, - 0xc7, 0xa0, 0xf2, 0x53, 0x6d, 0x27, 0xae, 0x03, 0x1e, 0x96, 0xc6, 0xc7, 0xf2, 0x5a, 0x8d, 0x5b, - 0x04, 0x79, 0x89, 0xdd, 0xba, 0xf2, 0x3a, 0xf6, 0xf6, 0x0f, 0x6e, 0xdc, 0x7e, 0xce, 0x32, 0x71, - 0x0a, 0x73, 0x2d, 0x81, 0x65, 0xd1, 0xb0, 0x49, 0xda, 0xad, 0x5b, 0xc5, 0x8d, 0x91, 0xbc, 0xc3, - 0xbd, 0xea, 0xf5, 0x94, 0xcd, 0x77, 0x30, 0x7b, 0xf8, 0x9f, 0xf9, 0xab, 0x17, 0x56, 0x75, 0xa4, - 0xd6, 0xd6, 0x8e, 0xd4, 0x0a, 0xd1, 0x8b, 0xf5, 0x86, 0x3a, 0x17, 0x1b, 0xea, 0x5c, 0x6e, 0x28, - 0xfa, 0x5e, 0x50, 0xf4, 0xb3, 0xa0, 0xe8, 0xbc, 0xa0, 0x68, 0x5d, 0x50, 0xf4, 0xbb, 0xa0, 0xe8, - 0x4f, 0x41, 0x9d, 0xcb, 0x82, 0xa2, 0x1f, 0x5b, 0xea, 0xac, 0xb7, 0xd4, 0xb9, 0xd8, 0x52, 0xe7, - 0x53, 0x6b, 0xa9, 0x8f, 0x5c, 0xbb, 0x80, 0xcf, 0xfe, 0x06, 0x00, 0x00, 0xff, 0xff, 0xc5, 0x7b, - 0x72, 0x81, 0xfb, 0x02, 0x00, 0x00, + // 488 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x52, 0x31, 0x6f, 0xd3, 0x40, + 0x14, 0xf6, 0x35, 0x8d, 0x4b, 0x2e, 0x52, 0x40, 0x57, 0x54, 0x4c, 0x86, 0x73, 0x14, 0x81, 0x14, + 0x24, 0xb0, 0xa5, 0x20, 0x76, 0x30, 0x50, 0xc1, 0x04, 0x72, 0x90, 0x90, 0xd8, 0xae, 0xe9, 0xc3, + 0x35, 0xd4, 0x3e, 0x73, 0x77, 0x56, 0xc9, 0xc6, 0xca, 0xc6, 0xcf, 0xe0, 0xa7, 0x74, 0xcc, 0xc0, + 0xd0, 0xc9, 0x22, 0xce, 0x82, 0x3c, 0xf5, 0x27, 0x20, 0x9f, 0xdd, 0xe6, 0x22, 0x06, 0x36, 0xbf, + 0xcf, 0xdf, 0xf7, 0xee, 0x7d, 0xef, 0x7b, 0xf8, 0xd6, 0x97, 0x1c, 0xc4, 0x42, 0xb0, 0x34, 0x02, + 0x2f, 0x13, 0x5c, 0x71, 0x82, 0x37, 0xc8, 0xf0, 0x76, 0xc4, 0x23, 0xae, 0x61, 0xbf, 0xfe, 0x6a, + 0x18, 0xc3, 0xe7, 0x51, 0xac, 0x4e, 0xf2, 0x23, 0x6f, 0xce, 0x13, 0x7f, 0xce, 0x85, 0x82, 0xaf, + 0x99, 0xe0, 0x9f, 0x60, 0xae, 0xda, 0xca, 0xcf, 0x3e, 0x47, 0x7e, 0xdd, 0x25, 0x06, 0xe1, 0x2b, + 0x11, 0x67, 0x19, 0x88, 0x33, 0x26, 0x40, 0x63, 0x8b, 0xa6, 0xc9, 0xf8, 0x7b, 0x07, 0x93, 0xb7, + 0x82, 0x27, 0xa0, 0x4e, 0x20, 0x97, 0x21, 0xc8, 0x8c, 0xa7, 0x12, 0xc8, 0x18, 0xdb, 0x33, 0xc5, + 0x54, 0x2e, 0x1d, 0x34, 0x42, 0x93, 0x5e, 0x80, 0xab, 0xc2, 0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xe2, + 0x1a, 0x0d, 0x0d, 0x06, 0x79, 0x86, 0xed, 0xa6, 0x72, 0x76, 0xb4, 0xd1, 0xbb, 0x5b, 0x46, 0x67, + 0x2c, 0xc9, 0x4e, 0x61, 0xa6, 0x04, 0xb0, 0x24, 0x18, 0xb4, 0xa1, 0xd8, 0x4d, 0xab, 0xb0, 0x15, + 0x92, 0x37, 0xb8, 0x5b, 0x07, 0x2d, 0x75, 0x14, 0xfd, 0xe9, 0xbd, 0xff, 0xac, 0xaa, 0x3e, 0x06, + 0xd9, 0xd8, 0xd2, 0x32, 0xd3, 0x96, 0x06, 0x82, 0xa7, 0xcb, 0x15, 0xb5, 0x2e, 0x56, 0xd4, 0xba, + 0x5c, 0x51, 0xf4, 0xad, 0xa4, 0xe8, 0x67, 0x49, 0xd1, 0x79, 0x49, 0xd1, 0xb2, 0xa4, 0xe8, 0x77, + 0x49, 0xd1, 0x9f, 0x92, 0x5a, 0x97, 0x25, 0x45, 0x3f, 0xd6, 0xd4, 0x5a, 0xae, 0xa9, 0x75, 0xb1, + 0xa6, 0xd6, 0x07, 0xe3, 0xfe, 0x8f, 0x6c, 0x7d, 0xab, 0x8f, 0xff, 0x06, 0x00, 0x00, 0xff, 0xff, + 0x7b, 0xf7, 0x21, 0xc5, 0x26, 0x03, 0x00, 0x00, } func (this *PrometheusResponse) Equal(that interface{}) bool { @@ -256,6 +265,14 @@ func (this *PrometheusResponse) Equal(that interface{}) bool { return false } } + if len(this.Infos) != len(that1.Infos) { + return false + } + for i := range this.Infos { + if this.Infos[i] != that1.Infos[i] { + return false + } + } return true } func (this *PrometheusData) Equal(that interface{}) bool { @@ -297,7 +314,7 @@ func (this *PrometheusResponse) GoString() string { if this == nil { return "nil" } - s := make([]string, 0, 10) + s := make([]string, 0, 11) 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") @@ -307,6 +324,7 @@ func (this *PrometheusResponse) GoString() string { s = append(s, "Headers: "+fmt.Sprintf("%#v", this.Headers)+",\n") } s = append(s, "Warnings: "+fmt.Sprintf("%#v", this.Warnings)+",\n") + s = append(s, "Infos: "+fmt.Sprintf("%#v", this.Infos)+",\n") s = append(s, "}") return strings.Join(s, "") } @@ -358,6 +376,15 @@ func (m *PrometheusResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.Infos) > 0 { + for iNdEx := len(m.Infos) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.Infos[iNdEx]) + copy(dAtA[i:], m.Infos[iNdEx]) + i = encodeVarintQueryrange(dAtA, i, uint64(len(m.Infos[iNdEx]))) + i-- + dAtA[i] = 0x3a + } + } if len(m.Warnings) > 0 { for iNdEx := len(m.Warnings) - 1; iNdEx >= 0; iNdEx-- { i -= len(m.Warnings[iNdEx]) @@ -514,6 +541,12 @@ func (m *PrometheusResponse) Size() (n int) { n += 1 + l + sovQueryrange(uint64(l)) } } + if len(m.Infos) > 0 { + for _, s := range m.Infos { + l = len(s) + n += 1 + l + sovQueryrange(uint64(l)) + } + } return n } @@ -562,6 +595,7 @@ func (this *PrometheusResponse) String() string { `Error:` + fmt.Sprintf("%v", this.Error) + `,`, `Headers:` + repeatedStringForHeaders + `,`, `Warnings:` + fmt.Sprintf("%v", this.Warnings) + `,`, + `Infos:` + fmt.Sprintf("%v", this.Infos) + `,`, `}`, }, "") return s @@ -815,6 +849,38 @@ func (m *PrometheusResponse) Unmarshal(dAtA []byte) error { } m.Warnings = append(m.Warnings, string(dAtA[iNdEx:postIndex])) iNdEx = postIndex + case 7: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Infos", 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.Infos = append(m.Infos, 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 8d2e024d13..1bdbc238b3 100644 --- a/pkg/querier/tripperware/queryrange/queryrange.proto +++ b/pkg/querier/tripperware/queryrange/queryrange.proto @@ -17,6 +17,7 @@ message PrometheusResponse { string Error = 4 [(gogoproto.jsontag) = "error,omitempty"]; repeated tripperware.PrometheusResponseHeader Headers = 5 [(gogoproto.jsontag) = "-"]; repeated string Warnings = 6 [(gogoproto.jsontag) = "warnings,omitempty"]; + repeated string Infos = 7 [(gogoproto.jsontag) = "infos,omitempty"]; } message PrometheusData { diff --git a/pkg/querier/tripperware/queryrange/results_cache.go b/pkg/querier/tripperware/queryrange/results_cache.go index 76757e72bb..b3a474ba8e 100644 --- a/pkg/querier/tripperware/queryrange/results_cache.go +++ b/pkg/querier/tripperware/queryrange/results_cache.go @@ -101,6 +101,7 @@ func (PrometheusResponseExtractor) Extract(start, end int64, from tripperware.Re }, Headers: promRes.Headers, Warnings: promRes.Warnings, + Infos: promRes.Infos, } } @@ -116,6 +117,7 @@ func (PrometheusResponseExtractor) ResponseWithoutHeaders(resp tripperware.Respo Stats: promRes.Data.Stats, }, Warnings: promRes.Warnings, + Infos: promRes.Infos, } } @@ -130,6 +132,7 @@ func (PrometheusResponseExtractor) ResponseWithoutStats(resp tripperware.Respons }, Headers: promRes.Headers, Warnings: promRes.Warnings, + Infos: promRes.Infos, } } @@ -600,6 +603,7 @@ func convertToTripperwarePrometheusResponse(resp tripperware.Response) tripperwa Error: r.Error, Headers: r.Headers, Warnings: r.Warnings, + Infos: r.Infos, } } @@ -621,6 +625,7 @@ func convertFromTripperwarePrometheusResponse(resp tripperware.Response) tripper Error: r.Error, Headers: r.Headers, Warnings: r.Warnings, + Infos: r.Infos, } } diff --git a/pkg/querier/tripperware/queryrange/results_cache_test.go b/pkg/querier/tripperware/queryrange/results_cache_test.go index 1a3d70e1cd..3d1e9f9574 100644 --- a/pkg/querier/tripperware/queryrange/results_cache_test.go +++ b/pkg/querier/tripperware/queryrange/results_cache_test.go @@ -26,8 +26,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" queryWithWarnings = "/api/v1/query_range?end=1536716898&query=sumsum%28warnings%29&start=1536673680&stats=all&step=120&warnings=true" + queryWithInfos = "/api/v1/query_range?end=1536716898&query=rate%28go_gc_gogc_percent%5B5m%5D%29&start=1536673680&stats=all&step=120" 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"]}` + responseBodyWithInfos = `{"status":"success","data":{"resultType":"matrix","result":[{"metric":{"foo":"bar"},"values":[[1536673680,"137"],[1536673780,"137"]]}]},"infos":["PromQL info: metric might not be a counter, name does not end in _total/_sum/_count/_bucket: \"go_gc_gogc_percent\" (1:6)"]}` ) var ( @@ -112,6 +114,30 @@ var ( }, }, } + parsedResponseWithInfos = &tripperware.PrometheusResponse{ + Status: "success", + Infos: []string{"PromQL info: metric might not be a counter, name does not end in _total/_sum/_count/_bucket: \"go_gc_gogc_percent\" (1:6)"}, + Data: tripperware.PrometheusData{ + ResultType: model.ValMatrix.String(), + Result: tripperware.PrometheusQueryResult{ + Result: &tripperware.PrometheusQueryResult_Matrix{ + Matrix: &tripperware.Matrix{ + SampleStreams: []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) tripperware.Response { diff --git a/pkg/ruler/frontend_decoder.go b/pkg/ruler/frontend_decoder.go index 832a511a4d..c8e653a05f 100644 --- a/pkg/ruler/frontend_decoder.go +++ b/pkg/ruler/frontend_decoder.go @@ -9,6 +9,8 @@ import ( "github.com/prometheus/common/model" "github.com/prometheus/prometheus/model/labels" "github.com/prometheus/prometheus/promql" + + "github.com/cortexproject/cortex/pkg/util/api" ) const ( @@ -19,13 +21,8 @@ type JsonDecoder struct{} type Warning []string func (j JsonDecoder) Decode(body []byte) (promql.Vector, Warning, error) { - var response struct { - Status string `json:"status"` - Data json.RawMessage `json:"data"` - ErrorType string `json:"errorType"` - Warnings Warning `json:"warnings"` - Error string `json:"error"` - } + var response api.Response + if err := json.NewDecoder(bytes.NewReader(body)).Decode(&response); err != nil { return nil, nil, err } @@ -37,8 +34,12 @@ func (j JsonDecoder) Decode(body []byte) (promql.Vector, Warning, error) { Result json.RawMessage `json:"result"` }{} - if err := json.Unmarshal(response.Data, &data); err != nil { + if responseDataBytes, err := json.Marshal(response.Data); err != nil { return nil, response.Warnings, err + } else { + if err = json.Unmarshal(responseDataBytes, &data); err != nil { + return nil, response.Warnings, err + } } switch data.Type { diff --git a/pkg/util/api/response.go b/pkg/util/api/response.go index 7e7c7713a2..c58baf60b9 100644 --- a/pkg/util/api/response.go +++ b/pkg/util/api/response.go @@ -23,6 +23,7 @@ type Response struct { ErrorType v1.ErrorType `json:"errorType,omitempty"` Error string `json:"error,omitempty"` Warnings []string `json:"warnings,omitempty"` + Infos []string `json:"infos,omitempty"` } // RespondFromGRPCError writes gRPC error in Prometheus response format.