@@ -25,6 +25,8 @@ import (
2525 "github.com/cortexproject/cortex/pkg/querier/tripperware"
2626)
2727
28+ var testInstantQueryCodec = NewInstantQueryCodec (string (tripperware .NonCompression ), string (tripperware .ProtobufCodecType ))
29+
2830const testHistogramResponse = `{"status":"success","data":{"resultType":"vector","result":[{"metric":{"__name__":"prometheus_http_request_duration_seconds","handler":"/metrics","instance":"localhost:9090","job":"prometheus"},"histogram":[1719528871.898,{"count":"6342","sum":"43.31319875499995","buckets":[[0,"0.0013810679320049755","0.0015060652591874421","1"],[0,"0.0015060652591874421","0.001642375811042411","7"],[0,"0.001642375811042411","0.0017910235218841233","5"],[0,"0.0017910235218841233","0.001953125","13"],[0,"0.001953125","0.0021298979153618314","19"],[0,"0.0021298979153618314","0.0023226701464896895","13"],[0,"0.0023226701464896895","0.002532889755177753","13"],[0,"0.002532889755177753","0.002762135864009951","15"],[0,"0.002762135864009951","0.0030121305183748843","12"],[0,"0.0030121305183748843","0.003284751622084822","34"],[0,"0.003284751622084822","0.0035820470437682465","188"],[0,"0.0035820470437682465","0.00390625","372"],[0,"0.00390625","0.004259795830723663","400"],[0,"0.004259795830723663","0.004645340292979379","411"],[0,"0.004645340292979379","0.005065779510355506","425"],[0,"0.005065779510355506","0.005524271728019902","425"],[0,"0.005524271728019902","0.0060242610367497685","521"],[0,"0.0060242610367497685","0.006569503244169644","621"],[0,"0.006569503244169644","0.007164094087536493","593"],[0,"0.007164094087536493","0.0078125","506"],[0,"0.0078125","0.008519591661447326","458"],[0,"0.008519591661447326","0.009290680585958758","346"],[0,"0.009290680585958758","0.010131559020711013","285"],[0,"0.010131559020711013","0.011048543456039804","196"],[0,"0.011048543456039804","0.012048522073499537","129"],[0,"0.012048522073499537","0.013139006488339287","85"],[0,"0.013139006488339287","0.014328188175072986","65"],[0,"0.014328188175072986","0.015625","54"],[0,"0.015625","0.01703918332289465","53"],[0,"0.01703918332289465","0.018581361171917516","20"],[0,"0.018581361171917516","0.020263118041422026","21"],[0,"0.020263118041422026","0.022097086912079608","15"],[0,"0.022097086912079608","0.024097044146999074","11"],[0,"0.024097044146999074","0.026278012976678575","2"],[0,"0.026278012976678575","0.028656376350145972","3"],[0,"0.028656376350145972","0.03125","3"],[0,"0.04052623608284405","0.044194173824159216","2"]]}]}]}}`
2931
3032func sortPrometheusResponseHeader (headers []* tripperware.PrometheusResponseHeader ) {
@@ -35,7 +37,7 @@ func sortPrometheusResponseHeader(headers []*tripperware.PrometheusResponseHeade
3537
3638func TestRequest (t * testing.T ) {
3739 t .Parallel ()
38- codec := InstantQueryCodec
40+ codec := testInstantQueryCodec
3941
4042 for _ , tc := range []struct {
4143 url string
@@ -182,7 +184,7 @@ func TestCompressedResponse(t *testing.T) {
182184 Header : h ,
183185 Body : io .NopCloser (responseBody ),
184186 }
185- resp , err := InstantQueryCodec .DecodeResponse (context .Background (), response , nil )
187+ resp , err := testInstantQueryCodec .DecodeResponse (context .Background (), response , nil )
186188 require .Equal (t , tc .err , err )
187189
188190 if err == nil {
@@ -376,7 +378,7 @@ func TestResponse(t *testing.T) {
376378 }
377379 }
378380
379- resp , err := InstantQueryCodec .DecodeResponse (context .Background (), response , nil )
381+ resp , err := testInstantQueryCodec .DecodeResponse (context .Background (), response , nil )
380382 require .NoError (t , err )
381383
382384 // Reset response, as the above call will have consumed the body reader.
@@ -386,7 +388,7 @@ func TestResponse(t *testing.T) {
386388 Body : io .NopCloser (bytes .NewBuffer ([]byte (tc .jsonBody ))),
387389 ContentLength : int64 (len (tc .jsonBody )),
388390 }
389- resp2 , err := InstantQueryCodec .EncodeResponse (context .Background (), resp )
391+ resp2 , err := testInstantQueryCodec .EncodeResponse (context .Background (), resp )
390392 require .NoError (t , err )
391393 assert .Equal (t , response , resp2 )
392394 })
@@ -645,7 +647,7 @@ func TestMergeResponse(t *testing.T) {
645647 if tc .cancelBeforeDecode {
646648 cancelCtx ()
647649 }
648- dr , err := InstantQueryCodec .DecodeResponse (ctx , hr , nil )
650+ dr , err := testInstantQueryCodec .DecodeResponse (ctx , hr , nil )
649651 assert .Equal (t , tc .expectedDecodeErr , err )
650652 if err != nil {
651653 cancelCtx ()
@@ -657,13 +659,13 @@ func TestMergeResponse(t *testing.T) {
657659 if tc .cancelBeforeMerge {
658660 cancelCtx ()
659661 }
660- resp , err := InstantQueryCodec .MergeResponse (ctx , tc .req , resps ... )
662+ resp , err := testInstantQueryCodec .MergeResponse (ctx , tc .req , resps ... )
661663 assert .Equal (t , tc .expectedErr , err )
662664 if err != nil {
663665 cancelCtx ()
664666 return
665667 }
666- dr , err := InstantQueryCodec .EncodeResponse (ctx , resp )
668+ dr , err := testInstantQueryCodec .EncodeResponse (ctx , resp )
667669 assert .Equal (t , tc .expectedErr , err )
668670 contents , err := io .ReadAll (dr .Body )
669671 assert .Equal (t , tc .expectedErr , err )
@@ -1660,7 +1662,7 @@ func TestMergeResponseProtobuf(t *testing.T) {
16601662 if tc .cancelBeforeDecode {
16611663 cancelCtx ()
16621664 }
1663- dr , err := InstantQueryCodec .DecodeResponse (ctx , hr , nil )
1665+ dr , err := testInstantQueryCodec .DecodeResponse (ctx , hr , nil )
16641666 assert .Equal (t , tc .expectedDecodeErr , err )
16651667 if err != nil {
16661668 cancelCtx ()
@@ -1672,13 +1674,13 @@ func TestMergeResponseProtobuf(t *testing.T) {
16721674 if tc .cancelBeforeMerge {
16731675 cancelCtx ()
16741676 }
1675- resp , err := InstantQueryCodec .MergeResponse (ctx , tc .req , resps ... )
1677+ resp , err := testInstantQueryCodec .MergeResponse (ctx , tc .req , resps ... )
16761678 assert .Equal (t , tc .expectedErr , err )
16771679 if err != nil {
16781680 cancelCtx ()
16791681 return
16801682 }
1681- dr , err := InstantQueryCodec .EncodeResponse (ctx , resp )
1683+ dr , err := testInstantQueryCodec .EncodeResponse (ctx , resp )
16821684 assert .Equal (t , tc .expectedErr , err )
16831685 contents , err := io .ReadAll (dr .Body )
16841686 assert .Equal (t , tc .expectedErr , err )
@@ -1743,7 +1745,7 @@ func Benchmark_Decode(b *testing.B) {
17431745 StatusCode : 200 ,
17441746 Body : io .NopCloser (bytes .NewBuffer (body )),
17451747 }
1746- _ , err := InstantQueryCodec .DecodeResponse (context .Background (), response , nil )
1748+ _ , err := testInstantQueryCodec .DecodeResponse (context .Background (), response , nil )
17471749 require .NoError (b , err )
17481750 }
17491751 })
@@ -1806,7 +1808,7 @@ func Benchmark_Decode_Protobuf(b *testing.B) {
18061808 Header : http.Header {"Content-Type" : []string {"application/x-protobuf" }},
18071809 Body : io .NopCloser (bytes .NewBuffer (body )),
18081810 }
1809- _ , err := InstantQueryCodec .DecodeResponse (context .Background (), response , nil )
1811+ _ , err := testInstantQueryCodec .DecodeResponse (context .Background (), response , nil )
18101812 require .NoError (b , err )
18111813 }
18121814 })
0 commit comments