@@ -681,3 +681,108 @@ func Test_sortPlanForQuery(t *testing.T) {
681681 })
682682 }
683683}
684+
685+ func TestMinTime (t * testing.T ) {
686+ t .Parallel ()
687+ for _ , tc := range []struct {
688+ name string
689+ resp * PrometheusResponse
690+ expected int64
691+ }{
692+ {
693+ name : "empty matrix" ,
694+ resp : & PrometheusResponse {
695+ Data : PrometheusData {
696+ ResultType : "matrix" ,
697+ Result : PrometheusQueryResult {
698+ Result : & PrometheusQueryResult_Matrix {
699+ Matrix : & Matrix {SampleStreams : []SampleStream {}},
700+ },
701+ },
702+ },
703+ },
704+ expected : - 1 ,
705+ },
706+ {
707+ name : "float samples only" ,
708+ resp : & PrometheusResponse {
709+ Data : PrometheusData {
710+ ResultType : "matrix" ,
711+ Result : PrometheusQueryResult {
712+ Result : & PrometheusQueryResult_Matrix {
713+ Matrix : & Matrix {SampleStreams : []SampleStream {
714+ {
715+ Labels : cortexpb .FromLabelsToLabelAdapters (labels .FromMap (map [string ]string {"foo" : "bar" })),
716+ Samples : []cortexpb.Sample {{TimestampMs : 1000 }, {TimestampMs : 2000 }},
717+ },
718+ }},
719+ },
720+ },
721+ },
722+ },
723+ expected : 1000 ,
724+ },
725+ {
726+ name : "histograms only" ,
727+ resp : & PrometheusResponse {
728+ Data : PrometheusData {
729+ ResultType : "matrix" ,
730+ Result : PrometheusQueryResult {
731+ Result : & PrometheusQueryResult_Matrix {
732+ Matrix : & Matrix {SampleStreams : []SampleStream {
733+ {
734+ Labels : cortexpb .FromLabelsToLabelAdapters (labels .FromMap (map [string ]string {"foo" : "bar" })),
735+ Histograms : []SampleHistogramPair {{TimestampMs : 3000 , Histogram : testHistogram1 }, {TimestampMs : 4000 , Histogram : testHistogram1 }},
736+ },
737+ }},
738+ },
739+ },
740+ },
741+ },
742+ expected : 3000 ,
743+ },
744+ {
745+ name : "both samples and histograms - samples first" ,
746+ resp : & PrometheusResponse {
747+ Data : PrometheusData {
748+ ResultType : "matrix" ,
749+ Result : PrometheusQueryResult {
750+ Result : & PrometheusQueryResult_Matrix {
751+ Matrix : & Matrix {SampleStreams : []SampleStream {
752+ {
753+ Labels : cortexpb .FromLabelsToLabelAdapters (labels .FromMap (map [string ]string {"foo" : "bar" })),
754+ Samples : []cortexpb.Sample {{TimestampMs : 1000 }},
755+ Histograms : []SampleHistogramPair {{TimestampMs : 5000 , Histogram : testHistogram1 }},
756+ },
757+ }},
758+ },
759+ },
760+ },
761+ },
762+ expected : 1000 ,
763+ },
764+ {
765+ name : "stream with empty samples and empty histograms" ,
766+ resp : & PrometheusResponse {
767+ Data : PrometheusData {
768+ ResultType : "matrix" ,
769+ Result : PrometheusQueryResult {
770+ Result : & PrometheusQueryResult_Matrix {
771+ Matrix : & Matrix {SampleStreams : []SampleStream {
772+ {
773+ Labels : cortexpb .FromLabelsToLabelAdapters (labels .FromMap (map [string ]string {"foo" : "bar" })),
774+ },
775+ }},
776+ },
777+ },
778+ },
779+ },
780+ expected : - 1 ,
781+ },
782+ } {
783+ t .Run (tc .name , func (t * testing.T ) {
784+ t .Parallel ()
785+ assert .Equal (t , tc .expected , tc .resp .minTime ())
786+ })
787+ }
788+ }
0 commit comments