11package codec
22
33import (
4+ "bytes"
5+ "fmt"
46 "testing"
57
68 "github.com/gogo/protobuf/proto"
9+ "github.com/prometheus/client_golang/prometheus"
10+ "github.com/prometheus/client_golang/prometheus/testutil"
711 "github.com/prometheus/common/model"
812 "github.com/prometheus/prometheus/model/histogram"
913 "github.com/prometheus/prometheus/model/labels"
@@ -437,7 +441,9 @@ func TestProtobufCodec_Encode(t *testing.T) {
437441
438442 for _ , test := range tests {
439443 t .Run (test .name , func (t * testing.T ) {
440- codec := ProtobufCodec {CortexInternal : test .cortexInternal }
444+ reg := prometheus .NewPedanticRegistry ()
445+ cm := NewInstrumentedCodecMetrics (reg )
446+ codec := NewInstrumentedCodec (ProtobufCodec {CortexInternal : test .cortexInternal }, cm )
441447 body , err := codec .Encode (& v1.Response {
442448 Status : tripperware .StatusSuccess ,
443449 Data : test .data ,
@@ -446,6 +452,21 @@ func TestProtobufCodec_Encode(t *testing.T) {
446452 b , err := proto .Marshal (test .expected )
447453 require .NoError (t , err )
448454 require .Equal (t , string (b ), string (body ))
455+ require .NoError (t , testutil .GatherAndCompare (reg , bytes .NewBufferString (fmt .Sprintf (`
456+ # HELP cortex_querier_codec_response_size Size of the encoded prometheus response from the queriers.
457+ # TYPE cortex_querier_codec_response_size histogram
458+ cortex_querier_codec_response_size_bucket{content_type="` + codec .ContentType ().String ()+ `",le="1.048576e+06"} 1
459+ cortex_querier_codec_response_size_bucket{content_type="` + codec .ContentType ().String ()+ `",le="2.62144e+06"} 1
460+ cortex_querier_codec_response_size_bucket{content_type="` + codec .ContentType ().String ()+ `",le="5.24288e+06"} 1
461+ cortex_querier_codec_response_size_bucket{content_type="` + codec .ContentType ().String ()+ `",le="1.048576e+07"} 1
462+ cortex_querier_codec_response_size_bucket{content_type="` + codec .ContentType ().String ()+ `",le="2.62144e+07"} 1
463+ cortex_querier_codec_response_size_bucket{content_type="` + codec .ContentType ().String ()+ `",le="5.24288e+07"} 1
464+ cortex_querier_codec_response_size_bucket{content_type="` + codec .ContentType ().String ()+ `",le="1.048576e+08"} 1
465+ cortex_querier_codec_response_size_bucket{content_type="` + codec .ContentType ().String ()+ `",le="2.62144e+08"} 1
466+ cortex_querier_codec_response_size_bucket{content_type="` + codec .ContentType ().String ()+ `",le="+Inf"} 1
467+ cortex_querier_codec_response_size_sum{content_type="` + codec .ContentType ().String ()+ `"} %v
468+ cortex_querier_codec_response_size_count{content_type="` + codec .ContentType ().String ()+ `"} 1
469+ ` , len (body ))), "cortex_querier_codec_response_size" ))
449470 })
450471 }
451472}
0 commit comments