@@ -23,6 +23,7 @@ import (
2323 "context"
2424 "errors"
2525 "fmt"
26+ "math"
2627 "path"
2728 "strings"
2829
@@ -32,6 +33,7 @@ import (
3233 metricspb "github.com/census-instrumentation/opencensus-proto/gen-go/metrics/v1"
3334 resourcepb "github.com/census-instrumentation/opencensus-proto/gen-go/resource/v1"
3435 timestamppb "github.com/golang/protobuf/ptypes/timestamp"
36+ promvalue "github.com/prometheus/prometheus/pkg/value"
3537 distributionpb "google.golang.org/genproto/googleapis/api/distribution"
3638 labelpb "google.golang.org/genproto/googleapis/api/label"
3739 googlemetricpb "google.golang.org/genproto/googleapis/api/metric"
@@ -481,13 +483,20 @@ func protoToMetricPoint(value interface{}) (*monitoringpb.TypedValue, error) {
481483 return nil , fmt .Errorf ("protoToMetricPoint: unknown Data type: %T" , value )
482484
483485 case * metricspb.Point_Int64Value :
486+ // drop handle stale NaNs that were cast to integers
487+ if isStaleInt64 (v .Int64Value ) {
488+ return nil , nil
489+ }
484490 return & monitoringpb.TypedValue {
485491 Value : & monitoringpb.TypedValue_Int64Value {
486492 Int64Value : v .Int64Value ,
487493 },
488494 }, nil
489495
490496 case * metricspb.Point_DoubleValue :
497+ if promvalue .IsStaleNaN (v .DoubleValue ) {
498+ return nil , nil
499+ }
491500 return & monitoringpb.TypedValue {
492501 Value : & monitoringpb.TypedValue_DoubleValue {
493502 DoubleValue : v .DoubleValue ,
@@ -498,6 +507,9 @@ func protoToMetricPoint(value interface{}) (*monitoringpb.TypedValue, error) {
498507 dv := v .DistributionValue
499508 var mv * monitoringpb.TypedValue_DistributionValue
500509 if dv != nil {
510+ if isStaleInt64 (dv .Count ) || promvalue .IsStaleNaN (dv .Sum ) {
511+ return nil , nil
512+ }
501513 var mean float64
502514 if dv .Count > 0 {
503515 mean = float64 (dv .Sum ) / float64 (dv .Count )
@@ -534,6 +546,10 @@ func protoToMetricPoint(value interface{}) (*monitoringpb.TypedValue, error) {
534546 }
535547}
536548
549+ func isStaleInt64 (v int64 ) bool {
550+ return v == int64 (math .Float64frombits (promvalue .StaleNaN ))
551+ }
552+
537553func bucketCounts (buckets []* metricspb.DistributionValue_Bucket ) []int64 {
538554 bucketCounts := make ([]int64 , len (buckets ))
539555 for i , bucket := range buckets {
0 commit comments