@@ -15,6 +15,7 @@ package retrieval
1515
1616import (
1717 "context"
18+ "math"
1819 "reflect"
1920 "testing"
2021
@@ -760,6 +761,80 @@ func TestSampleBuilder(t *testing.T) {
760761 },
761762 },
762763 },
764+ // Samples with a NaN value should be dropped.
765+ {
766+ targets : targetMap {
767+ "job1/instance1" : & targets.Target {
768+ Labels : promlabels .FromStrings ("job" , "job1" , "instance" , "instance1" ),
769+ DiscoveredLabels : promlabels .FromStrings ("__resource_a" , "resource2_a" ),
770+ },
771+ },
772+ series : seriesMap {
773+ 1 : labels .FromStrings ("job" , "job1" , "instance" , "instance1" , "__name__" , "metric1_count" ),
774+ },
775+ metadata : metadataMap {
776+ "job1/instance1/metric1" : & scrape.MetricMetadata {Type : textparse .MetricTypeSummary , Metric : "metric1_count" },
777+ },
778+ metricPrefix : "test.googleapis.com" ,
779+ input : []tsdb.RefSample {
780+ // A first non-NaN sample is necessary to avoid false-positives, since the
781+ // first result will always be nil due to reset timestamp handling.
782+ {Ref : 1 , T : 2000 , V : 5 },
783+ {Ref : 1 , T : 4000 , V : math .NaN ()},
784+ },
785+ result : []* monitoring_pb.TimeSeries {
786+ nil , // due to reset timestamp handling
787+ nil , // due to NaN
788+ },
789+ },
790+ // Samples with a NaN value should be dropped.
791+ {
792+ targets : targetMap {
793+ "job1/instance1" : & targets.Target {
794+ Labels : promlabels .FromStrings ("job" , "job1" , "instance" , "instance1" ),
795+ DiscoveredLabels : promlabels .FromStrings ("__resource_a" , "resource2_a" ),
796+ },
797+ },
798+ series : seriesMap {
799+ 1 : labels .FromStrings ("job" , "job1" , "instance" , "instance1" , "__name__" , "metric1_count" ),
800+ },
801+ metadata : metadataMap {
802+ "job1/instance1/metric1" : & scrape.MetricMetadata {Type : textparse .MetricTypeSummary , Metric : "metric1_count" },
803+ },
804+ metricPrefix : "test.googleapis.com" ,
805+ input : []tsdb.RefSample {
806+ // A first non-NaN sample is necessary to avoid false-positives, since the
807+ // first result will always be nil due to reset timestamp handling.
808+ {Ref : 1 , T : 2000 , V : 5 },
809+ {Ref : 1 , T : 4000 , V : math .NaN ()},
810+ {Ref : 1 , T : 5000 , V : 9 },
811+ },
812+ result : []* monitoring_pb.TimeSeries {
813+ nil , // due to reset timestamp handling
814+ nil , // due to NaN
815+ {
816+ Resource : & monitoredres_pb.MonitoredResource {
817+ Type : "resource2" ,
818+ Labels : map [string ]string {"resource_a" : "resource2_a" },
819+ },
820+ Metric : & metric_pb.Metric {
821+ Type : "test.googleapis.com/metric1_count" ,
822+ Labels : map [string ]string {},
823+ },
824+ MetricKind : metric_pb .MetricDescriptor_CUMULATIVE ,
825+ ValueType : metric_pb .MetricDescriptor_INT64 ,
826+ Points : []* monitoring_pb.Point {{
827+ Interval : & monitoring_pb.TimeInterval {
828+ StartTime : & timestamp_pb.Timestamp {Seconds : 2 },
829+ EndTime : & timestamp_pb.Timestamp {Seconds : 5 },
830+ },
831+ Value : & monitoring_pb.TypedValue {
832+ Value : & monitoring_pb.TypedValue_Int64Value {4 },
833+ },
834+ }},
835+ },
836+ },
837+ },
763838 }
764839 ctx , cancel := context .WithCancel (context .Background ())
765840 defer cancel ()
0 commit comments