From 09be4fab7be3116ca157dbf3efdd9ec93f90f717 Mon Sep 17 00:00:00 2001 From: SungJin1212 Date: Wed, 4 Sep 2024 10:33:20 +0900 Subject: [PATCH] Support peakSamples in query frontend response Signed-off-by: SungJin1212 --- CHANGELOG.md | 1 + .../tripperware/instantquery/instant_query.go | 4 +- .../instantquery/instant_query_test.go | 33 +++-- pkg/querier/tripperware/query.go | 3 +- pkg/querier/tripperware/query.pb.go | 127 ++++++++++++------ pkg/querier/tripperware/query.proto | 1 + .../tripperware/queryrange/query_range.go | 4 +- .../queryrange/query_range_test.go | 47 ++++++- .../tripperware/test_shard_by_query_utils.go | 42 +++--- 9 files changed, 181 insertions(+), 81 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 334a3c5776e..395c86a66da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## master / unreleased +* [FEATURE] Query Frontend: Add peakSample in query stats response. * [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] Ruler: Add query statistics metrics when --ruler.query-stats-enabled=true. #6173 * [ENHANCEMENT] Distributor: Add new `cortex_reduced_resolution_histogram_samples_total` metric to to track the number of histogram samples which resolution was reduced. #6182 diff --git a/pkg/querier/tripperware/instantquery/instant_query.go b/pkg/querier/tripperware/instantquery/instant_query.go index 135670ec377..3ba3a251e8e 100644 --- a/pkg/querier/tripperware/instantquery/instant_query.go +++ b/pkg/querier/tripperware/instantquery/instant_query.go @@ -514,6 +514,7 @@ func NewEmptyPrometheusInstantQueryResponse() *PrometheusInstantQueryResponse { func statsMerge(resps []*PrometheusInstantQueryResponse) *tripperware.PrometheusResponseStats { output := map[int64]*tripperware.PrometheusResponseQueryableSamplesStatsPerStep{} hasStats := false + var peakSamples int64 for _, resp := range resps { if resp.Data.Stats == nil { continue @@ -531,13 +532,14 @@ func statsMerge(resps []*PrometheusInstantQueryResponse) *tripperware.Prometheus output[s.GetTimestampMs()] = s } } + peakSamples = max(peakSamples, resp.Data.Stats.Samples.PeakSamples) } if !hasStats { return nil } - return tripperware.StatsMerge(output) + return tripperware.StatsMerge(output, peakSamples) } func decorateWithParamName(err error, field string) error { diff --git a/pkg/querier/tripperware/instantquery/instant_query_test.go b/pkg/querier/tripperware/instantquery/instant_query_test.go index 3a19641b975..8f1a76e0dcd 100644 --- a/pkg/querier/tripperware/instantquery/instant_query_test.go +++ b/pkg/querier/tripperware/instantquery/instant_query_test.go @@ -173,10 +173,10 @@ func TestResponse(t *testing.T) { body: `{"status":"success","data":{"resultType":"string","result":[1,"foo"]}}`, }, { - body: `{"status":"success","data":{"resultType":"string","result":[1,"foo"],"stats":{"samples":{"totalQueryableSamples":10,"totalQueryableSamplesPerStep":[[1536673680,5],[1536673780,5]]}}}}`, + body: `{"status":"success","data":{"resultType":"string","result":[1,"foo"],"stats":{"samples":{"totalQueryableSamples":10,"totalQueryableSamplesPerStep":[[1536673680,5],[1536673780,5]],"peakSamples":10}}}}`, }, { - body: `{"status":"success","data":{"resultType":"matrix","result":[{"metric":{"foo":"bar"},"values":[[1,"137"],[2,"137"]]}],"stats":{"samples":{"totalQueryableSamples":10,"totalQueryableSamplesPerStep":[[1536673680,5],[1536673780,5]]}}}}`, + body: `{"status":"success","data":{"resultType":"matrix","result":[{"metric":{"foo":"bar"},"values":[[1,"137"],[2,"137"]]}],"stats":{"samples":{"totalQueryableSamples":10,"totalQueryableSamplesPerStep":[[1536673680,5],[1536673780,5]],"peakSamples":10}}}}`, }, { body: `{"status":"success","data":{"resultType":"matrix","result":[{"metric":{"foo":"bar"},"values":[[1,"137"],[2,"137"]]}]}}`, @@ -241,8 +241,8 @@ func TestMergeResponse(t *testing.T) { { name: "empty response with stats", req: defaultReq, - resps: []string{`{"status":"success","data":{"resultType":"vector","result":[],"stats":{"samples":{"totalQueryableSamples":0,"totalQueryableSamplesPerStep":[]}}}}`}, - expectedResp: `{"status":"success","data":{"resultType":"vector","result":[],"stats":{"samples":{"totalQueryableSamples":0,"totalQueryableSamplesPerStep":[]}}}}`, + resps: []string{`{"status":"success","data":{"resultType":"vector","result":[],"stats":{"samples":{"totalQueryableSamples":0,"totalQueryableSamplesPerStep":[],"peakSamples":0}}}}`}, + expectedResp: `{"status":"success","data":{"resultType":"vector","result":[],"stats":{"samples":{"totalQueryableSamples":0,"totalQueryableSamplesPerStep":[],"peakSamples":0}}}}`, }, { name: "single response", @@ -253,8 +253,8 @@ func TestMergeResponse(t *testing.T) { { name: "single response with stats", req: defaultReq, - resps: []string{`{"status":"success","data":{"resultType":"vector","result":[{"metric":{"__name__":"up"},"value":[1,"1"]}],"stats":{"samples":{"totalQueryableSamples":10,"totalQueryableSamplesPerStep":[[1,10]]}}}}`}, - expectedResp: `{"status":"success","data":{"resultType":"vector","result":[{"metric":{"__name__":"up"},"value":[1,"1"]}],"stats":{"samples":{"totalQueryableSamples":10,"totalQueryableSamplesPerStep":[[1,10]]}}}}`, + resps: []string{`{"status":"success","data":{"resultType":"vector","result":[{"metric":{"__name__":"up"},"value":[1,"1"]}],"stats":{"samples":{"totalQueryableSamples":10,"totalQueryableSamplesPerStep":[[1,10]],"peakSamples":10}}}}`}, + expectedResp: `{"status":"success","data":{"resultType":"vector","result":[{"metric":{"__name__":"up"},"value":[1,"1"]}],"stats":{"samples":{"totalQueryableSamples":10,"totalQueryableSamplesPerStep":[[1,10]],"peakSamples":10}}}}`, }, { name: "duplicated response", @@ -275,10 +275,10 @@ func TestMergeResponse(t *testing.T) { name: "duplicated response with stats", req: defaultReq, resps: []string{ - `{"status":"success","data":{"resultType":"vector","result":[{"metric":{"__name__":"up"},"value":[1,"1"]}],"stats":{"samples":{"totalQueryableSamples":10,"totalQueryableSamplesPerStep":[[1,10]]}}}}`, - `{"status":"success","data":{"resultType":"vector","result":[{"metric":{"__name__":"up"},"value":[1,"1"]}],"stats":{"samples":{"totalQueryableSamples":10,"totalQueryableSamplesPerStep":[[1,10]]}}}}`, + `{"status":"success","data":{"resultType":"vector","result":[{"metric":{"__name__":"up"},"value":[1,"1"]}],"stats":{"samples":{"totalQueryableSamples":10,"totalQueryableSamplesPerStep":[[1,10]],"peakSamples":10}}}}`, + `{"status":"success","data":{"resultType":"vector","result":[{"metric":{"__name__":"up"},"value":[1,"1"]}],"stats":{"samples":{"totalQueryableSamples":10,"totalQueryableSamplesPerStep":[[1,10]],"peakSamples":10}}}}`, }, - expectedResp: `{"status":"success","data":{"resultType":"vector","result":[{"metric":{"__name__":"up"},"value":[1,"1"]}],"stats":{"samples":{"totalQueryableSamples":20,"totalQueryableSamplesPerStep":[[1,20]]}}}}`, + expectedResp: `{"status":"success","data":{"resultType":"vector","result":[{"metric":{"__name__":"up"},"value":[1,"1"]}],"stats":{"samples":{"totalQueryableSamples":20,"totalQueryableSamplesPerStep":[[1,20]],"peakSamples":10}}}}`, }, { name: "merge two responses", @@ -365,10 +365,19 @@ func TestMergeResponse(t *testing.T) { name: "merge two responses with stats", req: defaultReq, resps: []string{ - `{"status":"success","data":{"resultType":"vector","result":[{"metric":{"__name__":"up","job":"foo"},"value":[1,"1"]}],"stats":{"samples":{"totalQueryableSamples":10,"totalQueryableSamplesPerStep":[[1,10]]}}}}`, - `{"status":"success","data":{"resultType":"vector","result":[{"metric":{"__name__":"up","job":"bar"},"value":[2,"2"]}],"stats":{"samples":{"totalQueryableSamples":10,"totalQueryableSamplesPerStep":[[1,10]]}}}}`, + `{"status":"success","data":{"resultType":"vector","result":[{"metric":{"__name__":"up","job":"foo"},"value":[1,"1"]}],"stats":{"samples":{"totalQueryableSamples":10,"totalQueryableSamplesPerStep":[[1,10]],"peakSamples":10}}}}`, + `{"status":"success","data":{"resultType":"vector","result":[{"metric":{"__name__":"up","job":"bar"},"value":[2,"2"]}],"stats":{"samples":{"totalQueryableSamples":10,"totalQueryableSamplesPerStep":[[1,10]],"peakSamples":10}}}}`, }, - expectedResp: `{"status":"success","data":{"resultType":"vector","result":[{"metric":{"__name__":"up","job":"bar"},"value":[2,"2"]},{"metric":{"__name__":"up","job":"foo"},"value":[1,"1"]}],"stats":{"samples":{"totalQueryableSamples":20,"totalQueryableSamplesPerStep":[[1,20]]}}}}`, + expectedResp: `{"status":"success","data":{"resultType":"vector","result":[{"metric":{"__name__":"up","job":"bar"},"value":[2,"2"]},{"metric":{"__name__":"up","job":"foo"},"value":[1,"1"]}],"stats":{"samples":{"totalQueryableSamples":20,"totalQueryableSamplesPerStep":[[1,20]],"peakSamples":10}}}}`, + }, + { + name: "merge two responses with stats, the peak samples should be larger one among the responses", + req: defaultReq, + resps: []string{ + `{"status":"success","data":{"resultType":"vector","result":[{"metric":{"__name__":"up","job":"foo"},"value":[1,"1"]}],"stats":{"samples":{"totalQueryableSamples":10,"totalQueryableSamplesPerStep":[[1,10]],"peakSamples":10}}}}`, + `{"status":"success","data":{"resultType":"vector","result":[{"metric":{"__name__":"up","job":"bar"},"value":[2,"2"]}],"stats":{"samples":{"totalQueryableSamples":10,"totalQueryableSamplesPerStep":[[1,10]],"peakSamples":15}}}}`, + }, + expectedResp: `{"status":"success","data":{"resultType":"vector","result":[{"metric":{"__name__":"up","job":"bar"},"value":[2,"2"]},{"metric":{"__name__":"up","job":"foo"},"value":[1,"1"]}],"stats":{"samples":{"totalQueryableSamples":20,"totalQueryableSamplesPerStep":[[1,20]],"peakSamples":15}}}}`, }, { name: "responses don't contain vector, should return an error", diff --git a/pkg/querier/tripperware/query.go b/pkg/querier/tripperware/query.go index 0e8237c74eb..e8cd772b9f3 100644 --- a/pkg/querier/tripperware/query.go +++ b/pkg/querier/tripperware/query.go @@ -266,7 +266,7 @@ func BodyBufferFromHTTPGRPCResponse(res *httpgrpc.HTTPResponse, logger log.Logge return res.Body, nil } -func StatsMerge(stats map[int64]*PrometheusResponseQueryableSamplesStatsPerStep) *PrometheusResponseStats { +func StatsMerge(stats map[int64]*PrometheusResponseQueryableSamplesStatsPerStep, peakSamples int64) *PrometheusResponseStats { keys := make([]int64, 0, len(stats)) for key := range stats { keys = append(keys, key) @@ -279,6 +279,7 @@ func StatsMerge(stats map[int64]*PrometheusResponseQueryableSamplesStatsPerStep) result.Samples.TotalQueryableSamplesPerStep = append(result.Samples.TotalQueryableSamplesPerStep, stats[key]) result.Samples.TotalQueryableSamples += stats[key].Value } + result.Samples.PeakSamples = peakSamples return result } diff --git a/pkg/querier/tripperware/query.pb.go b/pkg/querier/tripperware/query.pb.go index 5c462144047..e415e160feb 100644 --- a/pkg/querier/tripperware/query.pb.go +++ b/pkg/querier/tripperware/query.pb.go @@ -303,6 +303,7 @@ func (m *PrometheusResponseStats) GetSamples() *PrometheusResponseSamplesStats { type PrometheusResponseSamplesStats struct { TotalQueryableSamples int64 `protobuf:"varint,1,opt,name=totalQueryableSamples,proto3" json:"totalQueryableSamples"` TotalQueryableSamplesPerStep []*PrometheusResponseQueryableSamplesStatsPerStep `protobuf:"bytes,2,rep,name=totalQueryableSamplesPerStep,proto3" json:"totalQueryableSamplesPerStep"` + PeakSamples int64 `protobuf:"varint,3,opt,name=peakSamples,proto3" json:"peakSamples"` } func (m *PrometheusResponseSamplesStats) Reset() { *m = PrometheusResponseSamplesStats{} } @@ -351,6 +352,13 @@ func (m *PrometheusResponseSamplesStats) GetTotalQueryableSamplesPerStep() []*Pr return nil } +func (m *PrometheusResponseSamplesStats) GetPeakSamples() int64 { + if m != nil { + return m.PeakSamples + } + return 0 +} + type PrometheusResponseQueryableSamplesStatsPerStep struct { Value int64 `protobuf:"varint,1,opt,name=value,proto3" json:"value,omitempty"` TimestampMs int64 `protobuf:"varint,2,opt,name=timestamp_ms,json=timestampMs,proto3" json:"timestamp_ms,omitempty"` @@ -521,48 +529,49 @@ func init() { func init() { proto.RegisterFile("query.proto", fileDescriptor_5c6ac9b241082464) } var fileDescriptor_5c6ac9b241082464 = []byte{ - // 646 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 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 0xe8, 0x2e, 0xac, - 0xbd, 0x35, 0x57, 0x6f, 0xc6, 0xd5, 0x77, 0x16, 0xa0, 0xd7, 0xbe, 0xba, 0x47, 0x87, 0x29, 0x93, - 0xea, 0x7f, 0x93, 0xfa, 0x9b, 0xa7, 0xe7, 0xd8, 0x39, 0x3b, 0xc7, 0xce, 0xe5, 0x39, 0x06, 0x5f, - 0x72, 0x0c, 0x7e, 0xe6, 0x18, 0x9c, 0xe4, 0x18, 0x9c, 0xe6, 0x18, 0xfc, 0xce, 0x31, 0xf8, 0x93, - 0x63, 0xe7, 0x32, 0xc7, 0xe0, 0xeb, 0x05, 0x76, 0x4e, 0x2f, 0xb0, 0x73, 0x76, 0x81, 0x9d, 0x77, - 0xc3, 0x7f, 0xec, 0xa0, 0x66, 0xfe, 0xb3, 0x0f, 0xff, 0x06, 0x00, 0x00, 0xff, 0xff, 0x33, 0x14, - 0x72, 0x0f, 0xd4, 0x05, 0x00, 0x00, + // 663 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x54, 0x4f, 0x4f, 0xd4, 0x40, + 0x14, 0xef, 0xec, 0xc2, 0x12, 0xa6, 0x44, 0xc8, 0x80, 0x71, 0x21, 0x38, 0x5d, 0x7b, 0x22, 0x31, + 0x2e, 0x11, 0x13, 0x13, 0xf5, 0x22, 0x3d, 0x91, 0xf8, 0x0f, 0x67, 0x89, 0x07, 0x2f, 0x66, 0xba, + 0x4c, 0x96, 0x4a, 0xcb, 0x94, 0x99, 0xa9, 0xa0, 0x27, 0x3f, 0x82, 0x67, 0x6f, 0xde, 0xfc, 0x28, + 0x1c, 0x39, 0x12, 0x0f, 0x8d, 0x94, 0x8b, 0xd9, 0x13, 0x1f, 0xc1, 0x74, 0xa6, 0xdd, 0x2d, 0xec, + 0x66, 0x0d, 0xf1, 0x36, 0xef, 0xf7, 0xde, 0xef, 0xfd, 0xde, 0x7b, 0x7d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f2, 0x76, 0xbf, 0xc0, 0xc5, 0x31, 0x34, 0x74, 0x0f, 0xce, 0xa9, 0x20, 0x62, 0x52, 0xd1, 0x28, + 0xfe, 0x10, 0xe5, 0x83, 0x02, 0x6b, 0x75, 0x62, 0x0f, 0xb0, 0x57, 0x12, 0x3d, 0x87, 0xb3, 0x83, + 0x3c, 0xcd, 0x5a, 0x0b, 0xac, 0xd9, 0x1b, 0xab, 0x93, 0xca, 0xf1, 0xa6, 0xf2, 0x52, 0xc8, 0x90, + 0xe4, 0x1e, 0xc2, 0xf9, 0x6b, 0x31, 0x68, 0x09, 0x4e, 0x77, 0x79, 0x72, 0xa0, 0xb4, 0x20, 0x20, + 0xc6, 0x40, 0x0b, 0xb0, 0x2e, 0x13, 0x23, 0x02, 0x48, 0xfe, 0x44, 0x8f, 0xe1, 0x8c, 0x9f, 0x74, + 0xf7, 0x99, 0x2a, 0x27, 0x71, 0x55, 0x7a, 0x28, 0xaa, 0x83, 0x48, 0x19, 0xec, 0x4a, 0x38, 0x7f, + 0xcd, 0x87, 0x30, 0x84, 0x3e, 0x4f, 0x0e, 0x76, 0xa9, 0x08, 0x98, 0x69, 0x74, 0x9a, 0x54, 0x90, + 0xbc, 0xa4, 0x90, 0x1f, 0x31, 0x51, 0xc8, 0x1b, 0x23, 0x47, 0x93, 0x5c, 0xae, 0x59, 0x37, 0xa8, + 0x36, 0x86, 0xe5, 0x4f, 0x55, 0xca, 0x77, 0x23, 0x78, 0x67, 0x5b, 0xf0, 0x88, 0xa9, 0x3d, 0x96, + 0x48, 0xc2, 0x64, 0xcc, 0x0f, 0x24, 0xeb, 0x28, 0xaa, 0x24, 0x22, 0xc3, 0x85, 0x00, 0x7a, 0x84, + 0xf7, 0xaf, 0xf4, 0x31, 0x86, 0x66, 0xa2, 0x35, 0xdb, 0xb3, 0xfb, 0xa9, 0x53, 0xf2, 0x07, 0x8b, + 0xe2, 0x9e, 0xd4, 0x20, 0x9e, 0x4c, 0x44, 0x6f, 0xe0, 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+ 0xef, 0xab, 0x3f, 0x79, 0xbf, 0xa1, 0x7f, 0xcd, 0x8f, 0xfe, 0x06, 0x00, 0x00, 0xff, 0xff, 0xf4, + 0xf1, 0x08, 0xb2, 0x07, 0x06, 0x00, 0x00, } func (this *SampleStream) Equal(that interface{}) bool { @@ -759,6 +768,9 @@ func (this *PrometheusResponseSamplesStats) Equal(that interface{}) bool { return false } } + if this.PeakSamples != that1.PeakSamples { + return false + } return true } func (this *PrometheusResponseQueryableSamplesStatsPerStep) Equal(that interface{}) bool { @@ -930,12 +942,13 @@ func (this *PrometheusResponseSamplesStats) GoString() string { if this == nil { return "nil" } - s := make([]string, 0, 6) + s := make([]string, 0, 7) s = append(s, "&tripperware.PrometheusResponseSamplesStats{") s = append(s, "TotalQueryableSamples: "+fmt.Sprintf("%#v", this.TotalQueryableSamples)+",\n") if this.TotalQueryableSamplesPerStep != nil { s = append(s, "TotalQueryableSamplesPerStep: "+fmt.Sprintf("%#v", this.TotalQueryableSamplesPerStep)+",\n") } + s = append(s, "PeakSamples: "+fmt.Sprintf("%#v", this.PeakSamples)+",\n") s = append(s, "}") return strings.Join(s, "") } @@ -1233,6 +1246,11 @@ func (m *PrometheusResponseSamplesStats) MarshalToSizedBuffer(dAtA []byte) (int, _ = i var l int _ = l + if m.PeakSamples != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.PeakSamples)) + i-- + dAtA[i] = 0x18 + } if len(m.TotalQueryableSamplesPerStep) > 0 { for iNdEx := len(m.TotalQueryableSamplesPerStep) - 1; iNdEx >= 0; iNdEx-- { { @@ -1488,6 +1506,9 @@ func (m *PrometheusResponseSamplesStats) Size() (n int) { n += 1 + l + sovQuery(uint64(l)) } } + if m.PeakSamples != 0 { + n += 1 + sovQuery(uint64(m.PeakSamples)) + } return n } @@ -1635,6 +1656,7 @@ func (this *PrometheusResponseSamplesStats) String() string { s := strings.Join([]string{`&PrometheusResponseSamplesStats{`, `TotalQueryableSamples:` + fmt.Sprintf("%v", this.TotalQueryableSamples) + `,`, `TotalQueryableSamplesPerStep:` + repeatedStringForTotalQueryableSamplesPerStep + `,`, + `PeakSamples:` + fmt.Sprintf("%v", this.PeakSamples) + `,`, `}`, }, "") return s @@ -2325,6 +2347,25 @@ func (m *PrometheusResponseSamplesStats) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field PeakSamples", wireType) + } + m.PeakSamples = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.PeakSamples |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipQuery(dAtA[iNdEx:]) diff --git a/pkg/querier/tripperware/query.proto b/pkg/querier/tripperware/query.proto index 9664fcf5289..1715cd884c1 100644 --- a/pkg/querier/tripperware/query.proto +++ b/pkg/querier/tripperware/query.proto @@ -41,6 +41,7 @@ message PrometheusResponseStats { message PrometheusResponseSamplesStats { int64 totalQueryableSamples = 1 [(gogoproto.jsontag) = "totalQueryableSamples"]; repeated PrometheusResponseQueryableSamplesStatsPerStep totalQueryableSamplesPerStep = 2 [(gogoproto.jsontag) = "totalQueryableSamplesPerStep"]; + int64 peakSamples = 3 [(gogoproto.jsontag) = "peakSamples"]; } message PrometheusResponseQueryableSamplesStatsPerStep { diff --git a/pkg/querier/tripperware/queryrange/query_range.go b/pkg/querier/tripperware/queryrange/query_range.go index 82eb0c12fc6..95d6c778009 100644 --- a/pkg/querier/tripperware/queryrange/query_range.go +++ b/pkg/querier/tripperware/queryrange/query_range.go @@ -320,6 +320,7 @@ func (prometheusCodec) EncodeResponse(ctx context.Context, res tripperware.Respo func statsMerge(shouldSumStats bool, resps []*PrometheusResponse) *tripperware.PrometheusResponseStats { output := map[int64]*tripperware.PrometheusResponseQueryableSamplesStatsPerStep{} hasStats := false + var peakSamples int64 for _, resp := range resps { if resp.Data.Stats == nil { continue @@ -341,12 +342,13 @@ func statsMerge(shouldSumStats bool, resps []*PrometheusResponse) *tripperware.P output[s.GetTimestampMs()] = s } } + peakSamples = max(peakSamples, resp.Data.Stats.Samples.PeakSamples) } if !hasStats { return nil } - return tripperware.StatsMerge(output) + return tripperware.StatsMerge(output, peakSamples) } func matrixMerge(ctx context.Context, resps []*PrometheusResponse) ([]tripperware.SampleStream, error) { diff --git a/pkg/querier/tripperware/queryrange/query_range_test.go b/pkg/querier/tripperware/queryrange/query_range_test.go index 0da8489188e..f1d156b149d 100644 --- a/pkg/querier/tripperware/queryrange/query_range_test.go +++ b/pkg/querier/tripperware/queryrange/query_range_test.go @@ -156,7 +156,7 @@ func TestResponseWithStats(t *testing.T) { expected *PrometheusResponse }{ { - body: `{"status":"success","data":{"resultType":"matrix","result":[{"metric":{"foo":"bar"},"values":[[1536673680,"137"],[1536673780,"137"]]}],"stats":{"samples":{"totalQueryableSamples":10,"totalQueryableSamplesPerStep":[[1536673680,5],[1536673780,5]]}}}}`, + body: `{"status":"success","data":{"resultType":"matrix","result":[{"metric":{"foo":"bar"},"values":[[1536673680,"137"],[1536673780,"137"]]}],"stats":{"samples":{"totalQueryableSamples":10,"totalQueryableSamplesPerStep":[[1536673680,5],[1536673780,5]],"peakSamples":16}}}}`, expected: &PrometheusResponse{ Status: "success", Data: PrometheusData{ @@ -179,6 +179,7 @@ func TestResponseWithStats(t *testing.T) { {Value: 5, TimestampMs: 1536673680000}, {Value: 5, TimestampMs: 1536673780000}, }, + PeakSamples: 16, }, }, }, @@ -735,6 +736,48 @@ func TestMergeAPIResponses(t *testing.T) { }}, }, }, + }, { + name: "[stats] Peak samples should be the largest one among the responses", + input: []tripperware.Response{ + mustParse(t, `{"status":"success","data":{"resultType":"matrix","result":[{"metric":{"a":"b","c":"d"},"values":[[2,"2"],[3,"3"]]}],"stats":{"samples":{"totalQueryableSamples":20,"totalQueryableSamplesPerStep":[[2,2],[3,3]],"peakSamples":20}}}}`), + mustParse(t, `{"status":"success","data":{"resultType":"matrix","result":[{"metric":{"c":"d","a":"b"},"values":[[2,"2"],[3,"3"],[4,"4"],[5,"5"]]}],"stats":{"samples":{"totalQueryableSamples":20,"totalQueryableSamplesPerStep":[[2,2],[3,3],[4,4],[5,5]],"peakSamples":22}}}}`), + mustParse(t, `{"status":"success","data":{"resultType":"matrix","result":[{"metric":{"c":"d","a":"b"},"values":[[6,"6"],[7,"7"],[8,"8"],[9,"9"]]}],"stats":{"samples":{"totalQueryableSamples":20,"totalQueryableSamplesPerStep":[[6,6],[7,7],[8,8],[9,9]],"peakSamples":25}}}}`), + }, + expected: &PrometheusResponse{ + Status: StatusSuccess, + Data: PrometheusData{ + ResultType: matrix, + Result: []tripperware.SampleStream{ + { + Labels: []cortexpb.LabelAdapter{{Name: "a", Value: "b"}, {Name: "c", Value: "d"}}, + Samples: []cortexpb.Sample{ + {Value: 2, TimestampMs: 2000}, + {Value: 3, TimestampMs: 3000}, + {Value: 4, TimestampMs: 4000}, + {Value: 5, TimestampMs: 5000}, + {Value: 6, TimestampMs: 6000}, + {Value: 7, TimestampMs: 7000}, + {Value: 8, TimestampMs: 8000}, + {Value: 9, TimestampMs: 9000}, + }, + }, + }, + Stats: &tripperware.PrometheusResponseStats{Samples: &tripperware.PrometheusResponseSamplesStats{ + TotalQueryableSamples: 44, + TotalQueryableSamplesPerStep: []*tripperware.PrometheusResponseQueryableSamplesStatsPerStep{ + {Value: 2, TimestampMs: 2000}, + {Value: 3, TimestampMs: 3000}, + {Value: 4, TimestampMs: 4000}, + {Value: 5, TimestampMs: 5000}, + {Value: 6, TimestampMs: 6000}, + {Value: 7, TimestampMs: 7000}, + {Value: 8, TimestampMs: 8000}, + {Value: 9, TimestampMs: 9000}, + }, + PeakSamples: 25, + }}, + }, + }, }} { tc := tc t.Run(tc.name, func(t *testing.T) { @@ -763,7 +806,7 @@ func TestGzippedResponse(t *testing.T) { err error }{ { - body: `{"status":"success","data":{"resultType":"matrix","result":[{"metric":{"a":"b","c":"d"},"values":[[2,"2"],[3,"3"]]}],"stats":{"samples":{"totalQueryableSamples":20,"totalQueryableSamplesPerStep":[[2,2],[3,3]]}}}}`, + body: `{"status":"success","data":{"resultType":"matrix","result":[{"metric":{"a":"b","c":"d"},"values":[[2,"2"],[3,"3"]]}],"stats":{"samples":{"totalQueryableSamples":20,"totalQueryableSamplesPerStep":[[2,2],[3,3]],"peakSamples":10}}}}`, status: 200, }, { diff --git a/pkg/querier/tripperware/test_shard_by_query_utils.go b/pkg/querier/tripperware/test_shard_by_query_utils.go index 2fbd2a48c57..1c8c0c1d40a 100644 --- a/pkg/querier/tripperware/test_shard_by_query_utils.go +++ b/pkg/querier/tripperware/test_shard_by_query_utils.go @@ -302,10 +302,10 @@ http_requests_total`, shardingLabels: []string{"pod", "cluster_name"}, shardSize: 2, responses: []string{ - `{"status":"success","data":{"resultType":"matrix","result":[{"metric":{"__name__":"metric","__job__":"a"},"values":[[1,"1"],[2,"2"],[3,"3"]]}],"stats":{"samples":{"totalQueryableSamples":6,"totalQueryableSamplesPerStep":[[1,1],[2,2],[3,3]]}}}}`, - `{"status":"success","data":{"resultType":"matrix","result":[{"metric":{"__name__":"metric","__job__":"b"},"values":[[1,"1"],[2,"2"],[3,"3"]]}],"stats":{"samples":{"totalQueryableSamples":6,"totalQueryableSamplesPerStep":[[1,1],[2,2],[3,3]]}}}}`, + `{"status":"success","data":{"resultType":"matrix","result":[{"metric":{"__name__":"metric","__job__":"a"},"values":[[1,"1"],[2,"2"],[3,"3"]]}],"stats":{"samples":{"totalQueryableSamples":6,"totalQueryableSamplesPerStep":[[1,1],[2,2],[3,3]],"peakSamples":6}}}}`, + `{"status":"success","data":{"resultType":"matrix","result":[{"metric":{"__name__":"metric","__job__":"b"},"values":[[1,"1"],[2,"2"],[3,"3"]]}],"stats":{"samples":{"totalQueryableSamples":6,"totalQueryableSamplesPerStep":[[1,1],[2,2],[3,3]],"peakSamples":7}}}}`, }, - response: `{"status":"success","data":{"resultType":"matrix","result":[{"metric":{"__job__":"a","__name__":"metric"},"values":[[1,"1"],[2,"2"],[3,"3"]]},{"metric":{"__job__":"b","__name__":"metric"},"values":[[1,"1"],[2,"2"],[3,"3"]]}],"stats":{"samples":{"totalQueryableSamples":12,"totalQueryableSamplesPerStep":[[1,2],[2,4],[3,6]]}}}}`, + response: `{"status":"success","data":{"resultType":"matrix","result":[{"metric":{"__job__":"a","__name__":"metric"},"values":[[1,"1"],[2,"2"],[3,"3"]]},{"metric":{"__job__":"b","__name__":"metric"},"values":[[1,"1"],[2,"2"],[3,"3"]]}],"stats":{"samples":{"totalQueryableSamples":12,"totalQueryableSamplesPerStep":[[1,2],[2,4],[3,6]],"peakSamples":7}}}}`, }, { name: "should shard instant query when query is shardable", @@ -315,10 +315,10 @@ http_requests_total`, shardingLabels: []string{"pod", "cluster_name"}, isShardable: true, responses: []string{ - `{"status":"success","data":{"resultType":"vector","result":[{"metric":{"__name__":"up","job":"foo"},"value":[1,"1"]}],"stats":{"samples":{"totalQueryableSamples":10,"totalQueryableSamplesPerStep":[[1,10]]}}}}`, - `{"status":"success","data":{"resultType":"vector","result":[{"metric":{"__name__":"up","job":"bar"},"value":[2,"2"]}],"stats":{"samples":{"totalQueryableSamples":10,"totalQueryableSamplesPerStep":[[1,10]]}}}}`, + `{"status":"success","data":{"resultType":"vector","result":[{"metric":{"__name__":"up","job":"foo"},"value":[1,"1"]}],"stats":{"samples":{"totalQueryableSamples":10,"totalQueryableSamplesPerStep":[[1,10]],"peakSamples":10}}}}`, + `{"status":"success","data":{"resultType":"vector","result":[{"metric":{"__name__":"up","job":"bar"},"value":[2,"2"]}],"stats":{"samples":{"totalQueryableSamples":10,"totalQueryableSamplesPerStep":[[1,10]],"peakSamples":11}}}}`, }, - response: `{"status":"success","data":{"resultType":"vector","result":[{"metric":{"__name__":"up","job":"bar"},"value":[2,"2"]},{"metric":{"__name__":"up","job":"foo"},"value":[1,"1"]}],"stats":{"samples":{"totalQueryableSamples":20,"totalQueryableSamplesPerStep":[[1,20]]}}}}`, + response: `{"status":"success","data":{"resultType":"vector","result":[{"metric":{"__name__":"up","job":"bar"},"value":[2,"2"]},{"metric":{"__name__":"up","job":"foo"},"value":[1,"1"]}],"stats":{"samples":{"totalQueryableSamples":20,"totalQueryableSamplesPerStep":[[1,20]],"peakSamples":11}}}}`, }, { name: "should not shard if shard size is 1", @@ -327,9 +327,9 @@ http_requests_total`, shardSize: 1, isShardable: false, responses: []string{ - `{"status":"success","data":{"resultType":"vector","result":[{"metric":{"__name__":"up","job":"foo"},"value":[1,"1"]}],"stats":{"samples":{"totalQueryableSamples":10,"totalQueryableSamplesPerStep":[[1,10]]}}}}`, + `{"status":"success","data":{"resultType":"vector","result":[{"metric":{"__name__":"up","job":"foo"},"value":[1,"1"]}],"stats":{"samples":{"totalQueryableSamples":10,"totalQueryableSamplesPerStep":[[1,10]],"peakSamples":10}}}}`, }, - response: `{"status":"success","data":{"resultType":"vector","result":[{"metric":{"__name__":"up","job":"foo"},"value":[1,"1"]}],"stats":{"samples":{"totalQueryableSamples":10,"totalQueryableSamplesPerStep":[[1,10]]}}}}`, + response: `{"status":"success","data":{"resultType":"vector","result":[{"metric":{"__name__":"up","job":"foo"},"value":[1,"1"]}],"stats":{"samples":{"totalQueryableSamples":10,"totalQueryableSamplesPerStep":[[1,10]],"peakSamples":10}}}}`, }, } for _, query := range nonShardable { @@ -340,9 +340,9 @@ http_requests_total`, shardSize: 2, isShardable: false, responses: []string{ - `{"status":"success","data":{"resultType":"vector","result":[{"metric":{"__name__":"up","job":"foo"},"value":[1,"1"]}],"stats":{"samples":{"totalQueryableSamples":10,"totalQueryableSamplesPerStep":[[1,10]]}}}}`, + `{"status":"success","data":{"resultType":"vector","result":[{"metric":{"__name__":"up","job":"foo"},"value":[1,"1"]}],"stats":{"samples":{"totalQueryableSamples":10,"totalQueryableSamplesPerStep":[[1,10]],"peakSamples":10}}}}`, }, - response: `{"status":"success","data":{"resultType":"vector","result":[{"metric":{"__name__":"up","job":"foo"},"value":[1,"1"]}],"stats":{"samples":{"totalQueryableSamples":10,"totalQueryableSamplesPerStep":[[1,10]]}}}}`, + response: `{"status":"success","data":{"resultType":"vector","result":[{"metric":{"__name__":"up","job":"foo"},"value":[1,"1"]}],"stats":{"samples":{"totalQueryableSamples":10,"totalQueryableSamplesPerStep":[[1,10]],"peakSamples":10}}}}`, expectedErr: query.expectedErr, }) tests = append(tests, testCase{ @@ -352,9 +352,9 @@ http_requests_total`, shardSize: 2, isShardable: false, responses: []string{ - `{"status":"success","data":{"resultType":"matrix","result":[{"metric":{"__job__":"a","__name__":"metric"},"values":[[1,"1"],[2,"2"],[3,"3"]]}],"stats":{"samples":{"totalQueryableSamples":6,"totalQueryableSamplesPerStep":[[1,1],[2,2],[3,3]]}}}}`, + `{"status":"success","data":{"resultType":"matrix","result":[{"metric":{"__job__":"a","__name__":"metric"},"values":[[1,"1"],[2,"2"],[3,"3"]]}],"stats":{"samples":{"totalQueryableSamples":6,"totalQueryableSamplesPerStep":[[1,1],[2,2],[3,3]],"peakSamples":6}}}}`, }, - response: `{"status":"success","data":{"resultType":"matrix","result":[{"metric":{"__job__":"a","__name__":"metric"},"values":[[1,"1"],[2,"2"],[3,"3"]]}],"stats":{"samples":{"totalQueryableSamples":6,"totalQueryableSamplesPerStep":[[1,1],[2,2],[3,3]]}}}}`, + response: `{"status":"success","data":{"resultType":"matrix","result":[{"metric":{"__job__":"a","__name__":"metric"},"values":[[1,"1"],[2,"2"],[3,"3"]]}],"stats":{"samples":{"totalQueryableSamples":6,"totalQueryableSamplesPerStep":[[1,1],[2,2],[3,3]],"peakSamples":6}}}}`, expectedErr: query.expectedErr, }) } @@ -368,10 +368,10 @@ http_requests_total`, shardSize: 2, shardingLabels: query.shardingLabels, responses: []string{ - `{"status":"success","data":{"resultType":"vector","result":[{"metric":{"__name__":"up","job":"foo"},"value":[1,"1"]}],"stats":{"samples":{"totalQueryableSamples":10,"totalQueryableSamplesPerStep":[[1,10]]}}}}`, - `{"status":"success","data":{"resultType":"vector","result":[{"metric":{"__name__":"up","job":"bar"},"value":[2,"2"]}],"stats":{"samples":{"totalQueryableSamples":10,"totalQueryableSamplesPerStep":[[1,10]]}}}}`, + `{"status":"success","data":{"resultType":"vector","result":[{"metric":{"__name__":"up","job":"foo"},"value":[1,"1"]}],"stats":{"samples":{"totalQueryableSamples":10,"totalQueryableSamplesPerStep":[[1,10]],"peakSamples":10}}}}`, + `{"status":"success","data":{"resultType":"vector","result":[{"metric":{"__name__":"up","job":"bar"},"value":[2,"2"]}],"stats":{"samples":{"totalQueryableSamples":10,"totalQueryableSamplesPerStep":[[1,10]],"peakSamples":10}}}}`, }, - response: `{"status":"success","data":{"resultType":"vector","result":[{"metric":{"__name__":"up","job":"bar"},"value":[2,"2"]},{"metric":{"__name__":"up","job":"foo"},"value":[1,"1"]}],"stats":{"samples":{"totalQueryableSamples":20,"totalQueryableSamplesPerStep":[[1,20]]}}}}`, + response: `{"status":"success","data":{"resultType":"vector","result":[{"metric":{"__name__":"up","job":"bar"},"value":[2,"2"]},{"metric":{"__name__":"up","job":"foo"},"value":[1,"1"]}],"stats":{"samples":{"totalQueryableSamples":20,"totalQueryableSamplesPerStep":[[1,20]],"peakSamples":10}}}}`, expectedErr: query.expectedErr, }) tests = append(tests, testCase{ @@ -382,10 +382,10 @@ http_requests_total`, shardSize: 2, shardingLabels: query.shardingLabels, responses: []string{ - `{"status":"success","data":{"resultType":"matrix","result":[{"metric":{"__name__":"metric","__job__":"a"},"values":[[1,"1"],[2,"2"],[3,"3"]]}],"stats":{"samples":{"totalQueryableSamples":6,"totalQueryableSamplesPerStep":[[1,1],[2,2],[3,3]]}}}}`, - `{"status":"success","data":{"resultType":"matrix","result":[{"metric":{"__name__":"metric","__job__":"b"},"values":[[1,"1"],[2,"2"],[3,"3"]]}],"stats":{"samples":{"totalQueryableSamples":6,"totalQueryableSamplesPerStep":[[1,1],[2,2],[3,3]]}}}}`, + `{"status":"success","data":{"resultType":"matrix","result":[{"metric":{"__name__":"metric","__job__":"a"},"values":[[1,"1"],[2,"2"],[3,"3"]]}],"stats":{"samples":{"totalQueryableSamples":6,"totalQueryableSamplesPerStep":[[1,1],[2,2],[3,3]],"peakSamples":6}}}}`, + `{"status":"success","data":{"resultType":"matrix","result":[{"metric":{"__name__":"metric","__job__":"b"},"values":[[1,"1"],[2,"2"],[3,"3"]]}],"stats":{"samples":{"totalQueryableSamples":6,"totalQueryableSamplesPerStep":[[1,1],[2,2],[3,3]],"peakSamples":7}}}}`, }, - response: `{"status":"success","data":{"resultType":"matrix","result":[{"metric":{"__job__":"a","__name__":"metric"},"values":[[1,"1"],[2,"2"],[3,"3"]]},{"metric":{"__job__":"b","__name__":"metric"},"values":[[1,"1"],[2,"2"],[3,"3"]]}],"stats":{"samples":{"totalQueryableSamples":12,"totalQueryableSamplesPerStep":[[1,2],[2,4],[3,6]]}}}}`, + response: `{"status":"success","data":{"resultType":"matrix","result":[{"metric":{"__job__":"a","__name__":"metric"},"values":[[1,"1"],[2,"2"],[3,"3"]]},{"metric":{"__job__":"b","__name__":"metric"},"values":[[1,"1"],[2,"2"],[3,"3"]]}],"stats":{"samples":{"totalQueryableSamples":12,"totalQueryableSamplesPerStep":[[1,2],[2,4],[3,6]],"peakSamples":7}}}}`, expectedErr: query.expectedErr, }) } @@ -399,10 +399,10 @@ http_requests_total`, shardSize: 2, shardingLabels: query.shardingLabels, responses: []string{ - `{"status":"success","data":{"resultType":"matrix","result":[{"metric":{"__name__":"up","job":"foo"},"values":[[1,"1"]]}],"stats":{"samples":{"totalQueryableSamples":10,"totalQueryableSamplesPerStep":[[1,10]]}}}}`, - `{"status":"success","data":{"resultType":"matrix","result":[{"metric":{"__name__":"up","job":"bar"},"values":[[2,"2"]]}],"stats":{"samples":{"totalQueryableSamples":10,"totalQueryableSamplesPerStep":[[1,10]]}}}}`, + `{"status":"success","data":{"resultType":"matrix","result":[{"metric":{"__name__":"up","job":"foo"},"values":[[1,"1"]]}],"stats":{"samples":{"totalQueryableSamples":10,"totalQueryableSamplesPerStep":[[1,10]],"peakSamples":10}}}}`, + `{"status":"success","data":{"resultType":"matrix","result":[{"metric":{"__name__":"up","job":"bar"},"values":[[2,"2"]]}],"stats":{"samples":{"totalQueryableSamples":10,"totalQueryableSamplesPerStep":[[1,10]],"peakSamples":11}}}}`, }, - response: `{"status":"success","data":{"resultType":"matrix","result":[{"metric":{"__name__":"up","job":"bar"},"values":[[2,"2"]]},{"metric":{"__name__":"up","job":"foo"},"values":[[1,"1"]]}],"stats":{"samples":{"totalQueryableSamples":20,"totalQueryableSamplesPerStep":[[1,20]]}}}}`, + response: `{"status":"success","data":{"resultType":"matrix","result":[{"metric":{"__name__":"up","job":"bar"},"values":[[2,"2"]]},{"metric":{"__name__":"up","job":"foo"},"values":[[1,"1"]]}],"stats":{"samples":{"totalQueryableSamples":20,"totalQueryableSamplesPerStep":[[1,20]],"peakSamples":11}}}}`, }) }