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

Commit bffcda0

Browse files
committed
skip exporting points with no value due to prometheus staleness markers
1 parent 5a007e3 commit bffcda0

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

metrics_proto.go

+14
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,10 @@ func (se *statsExporter) protoMetricToTimeSeries(ctx context.Context, mappedRsc
257257
mb.recordDroppedTimeseries(1, err)
258258
continue
259259
}
260+
if len(sdPoints) == 0 {
261+
// Sending TimeSeries with no points is not allowed, so skip this one
262+
continue
263+
}
260264

261265
// Each TimeSeries has labelValues which MUST be correlated
262266
// with that from the MetricDescriptor
@@ -355,6 +359,11 @@ func (se *statsExporter) protoTimeSeriesToMonitoringPoints(ts *metricspb.TimeSer
355359
if err != nil {
356360
return nil, err
357361
}
362+
if spt == nil {
363+
// Skip any points that don't result in a correct value
364+
// For example if they are Prometheus staleness markers
365+
continue
366+
}
358367
sptl = append(sptl, spt)
359368
}
360369
return sptl, nil
@@ -444,6 +453,11 @@ func fromProtoPoint(startTime *timestamppb.Timestamp, pt *metricspb.Point) (*mon
444453
if err != nil {
445454
return nil, err
446455
}
456+
// We don't want to send points with no value as those are invalid
457+
// Pass the nil upwards instead to skip this point
458+
if mptv == nil {
459+
return nil, nil
460+
}
447461

448462
endTime := pt.Timestamp
449463
interval := &monitoringpb.TimeInterval{

metrics_proto_test.go

+16
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ package stackdriver
1717
import (
1818
"context"
1919
"fmt"
20+
"math"
2021
"strings"
2122
"testing"
2223

2324
resourcepb "github.com/census-instrumentation/opencensus-proto/gen-go/resource/v1"
2425
"github.com/golang/protobuf/ptypes/timestamp"
26+
promvalue "github.com/prometheus/prometheus/model/value"
2527
"google.golang.org/api/option"
2628
distributionpb "google.golang.org/genproto/googleapis/api/distribution"
2729
labelpb "google.golang.org/genproto/googleapis/api/label"
@@ -762,6 +764,20 @@ func TestProtoMetricsToMonitoringMetrics_fromProtoPoint(t *testing.T) {
762764
},
763765
},
764766
},
767+
{
768+
in: &metricspb.Point{
769+
Timestamp: endTimestamp,
770+
Value: &metricspb.Point_Int64Value{Int64Value: int64(math.Float64frombits(promvalue.StaleNaN))},
771+
},
772+
want: nil,
773+
},
774+
{
775+
in: &metricspb.Point{
776+
Timestamp: endTimestamp,
777+
Value: &metricspb.Point_DoubleValue{DoubleValue: math.Float64frombits(promvalue.StaleNaN)},
778+
},
779+
want: nil,
780+
},
765781
}
766782

767783
for i, tt := range tests {

0 commit comments

Comments
 (0)