@@ -25,6 +25,8 @@ import (
25
25
"github.com/cortexproject/cortex/pkg/querier/tripperware"
26
26
)
27
27
28
+ var testInstantQueryCodec = NewInstantQueryCodec (string (tripperware .NonCompression ), string (tripperware .ProtobufCodecType ))
29
+
28
30
const 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"]]}]}]}}`
29
31
30
32
func sortPrometheusResponseHeader (headers []* tripperware.PrometheusResponseHeader ) {
@@ -35,7 +37,7 @@ func sortPrometheusResponseHeader(headers []*tripperware.PrometheusResponseHeade
35
37
36
38
func TestRequest (t * testing.T ) {
37
39
t .Parallel ()
38
- codec := InstantQueryCodec
40
+ codec := testInstantQueryCodec
39
41
40
42
for _ , tc := range []struct {
41
43
url string
@@ -182,7 +184,7 @@ func TestCompressedResponse(t *testing.T) {
182
184
Header : h ,
183
185
Body : io .NopCloser (responseBody ),
184
186
}
185
- resp , err := InstantQueryCodec .DecodeResponse (context .Background (), response , nil )
187
+ resp , err := testInstantQueryCodec .DecodeResponse (context .Background (), response , nil )
186
188
require .Equal (t , tc .err , err )
187
189
188
190
if err == nil {
@@ -376,7 +378,7 @@ func TestResponse(t *testing.T) {
376
378
}
377
379
}
378
380
379
- resp , err := InstantQueryCodec .DecodeResponse (context .Background (), response , nil )
381
+ resp , err := testInstantQueryCodec .DecodeResponse (context .Background (), response , nil )
380
382
require .NoError (t , err )
381
383
382
384
// Reset response, as the above call will have consumed the body reader.
@@ -386,7 +388,7 @@ func TestResponse(t *testing.T) {
386
388
Body : io .NopCloser (bytes .NewBuffer ([]byte (tc .jsonBody ))),
387
389
ContentLength : int64 (len (tc .jsonBody )),
388
390
}
389
- resp2 , err := InstantQueryCodec .EncodeResponse (context .Background (), resp )
391
+ resp2 , err := testInstantQueryCodec .EncodeResponse (context .Background (), resp )
390
392
require .NoError (t , err )
391
393
assert .Equal (t , response , resp2 )
392
394
})
@@ -645,7 +647,7 @@ func TestMergeResponse(t *testing.T) {
645
647
if tc .cancelBeforeDecode {
646
648
cancelCtx ()
647
649
}
648
- dr , err := InstantQueryCodec .DecodeResponse (ctx , hr , nil )
650
+ dr , err := testInstantQueryCodec .DecodeResponse (ctx , hr , nil )
649
651
assert .Equal (t , tc .expectedDecodeErr , err )
650
652
if err != nil {
651
653
cancelCtx ()
@@ -657,13 +659,13 @@ func TestMergeResponse(t *testing.T) {
657
659
if tc .cancelBeforeMerge {
658
660
cancelCtx ()
659
661
}
660
- resp , err := InstantQueryCodec .MergeResponse (ctx , tc .req , resps ... )
662
+ resp , err := testInstantQueryCodec .MergeResponse (ctx , tc .req , resps ... )
661
663
assert .Equal (t , tc .expectedErr , err )
662
664
if err != nil {
663
665
cancelCtx ()
664
666
return
665
667
}
666
- dr , err := InstantQueryCodec .EncodeResponse (ctx , resp )
668
+ dr , err := testInstantQueryCodec .EncodeResponse (ctx , resp )
667
669
assert .Equal (t , tc .expectedErr , err )
668
670
contents , err := io .ReadAll (dr .Body )
669
671
assert .Equal (t , tc .expectedErr , err )
@@ -1660,7 +1662,7 @@ func TestMergeResponseProtobuf(t *testing.T) {
1660
1662
if tc .cancelBeforeDecode {
1661
1663
cancelCtx ()
1662
1664
}
1663
- dr , err := InstantQueryCodec .DecodeResponse (ctx , hr , nil )
1665
+ dr , err := testInstantQueryCodec .DecodeResponse (ctx , hr , nil )
1664
1666
assert .Equal (t , tc .expectedDecodeErr , err )
1665
1667
if err != nil {
1666
1668
cancelCtx ()
@@ -1672,13 +1674,13 @@ func TestMergeResponseProtobuf(t *testing.T) {
1672
1674
if tc .cancelBeforeMerge {
1673
1675
cancelCtx ()
1674
1676
}
1675
- resp , err := InstantQueryCodec .MergeResponse (ctx , tc .req , resps ... )
1677
+ resp , err := testInstantQueryCodec .MergeResponse (ctx , tc .req , resps ... )
1676
1678
assert .Equal (t , tc .expectedErr , err )
1677
1679
if err != nil {
1678
1680
cancelCtx ()
1679
1681
return
1680
1682
}
1681
- dr , err := InstantQueryCodec .EncodeResponse (ctx , resp )
1683
+ dr , err := testInstantQueryCodec .EncodeResponse (ctx , resp )
1682
1684
assert .Equal (t , tc .expectedErr , err )
1683
1685
contents , err := io .ReadAll (dr .Body )
1684
1686
assert .Equal (t , tc .expectedErr , err )
@@ -1743,7 +1745,7 @@ func Benchmark_Decode(b *testing.B) {
1743
1745
StatusCode : 200 ,
1744
1746
Body : io .NopCloser (bytes .NewBuffer (body )),
1745
1747
}
1746
- _ , err := InstantQueryCodec .DecodeResponse (context .Background (), response , nil )
1748
+ _ , err := testInstantQueryCodec .DecodeResponse (context .Background (), response , nil )
1747
1749
require .NoError (b , err )
1748
1750
}
1749
1751
})
@@ -1806,7 +1808,7 @@ func Benchmark_Decode_Protobuf(b *testing.B) {
1806
1808
Header : http.Header {"Content-Type" : []string {"application/x-protobuf" }},
1807
1809
Body : io .NopCloser (bytes .NewBuffer (body )),
1808
1810
}
1809
- _ , err := InstantQueryCodec .DecodeResponse (context .Background (), response , nil )
1811
+ _ , err := testInstantQueryCodec .DecodeResponse (context .Background (), response , nil )
1810
1812
require .NoError (b , err )
1811
1813
}
1812
1814
})
0 commit comments