Skip to content
This repository was archived by the owner on Oct 3, 2023. It is now read-only.

Commit e781cdd

Browse files
authored
Ignore staleness markers (#300)
* ignore staleness markers * handle stale NaN if they are integers * handle stale sum+count NaNs in histograms
1 parent 074d8ef commit e781cdd

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ require (
1111
github.com/golang/protobuf v1.5.2
1212
github.com/google/go-cmp v0.5.6
1313
github.com/jstemmer/go-junit-report v0.9.1
14+
github.com/prometheus/prometheus v2.5.0+incompatible
1415
go.opencensus.io v0.23.0
1516
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616
1617
golang.org/x/net v0.0.0-20210503060351-7fd8e65b6420

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
176176
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
177177
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
178178
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
179+
github.com/prometheus/prometheus v2.5.0+incompatible h1:7QPitgO2kOFG8ecuRn9O/4L9+10He72rVRJvMXrE9Hg=
180+
github.com/prometheus/prometheus v2.5.0+incompatible/go.mod h1:oAIUtOny2rjMX0OWN5vPR5/q/twIROJvdqnQKDdil/s=
179181
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
180182
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
181183
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=

metrics_proto.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
537553
func bucketCounts(buckets []*metricspb.DistributionValue_Bucket) []int64 {
538554
bucketCounts := make([]int64, len(buckets))
539555
for i, bucket := range buckets {

0 commit comments

Comments
 (0)