Skip to content

Commit

Permalink
Skip samples that have a NaN value. (#186)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkschulz authored Oct 10, 2019
1 parent 4e2773a commit 596df4c
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
4 changes: 4 additions & 0 deletions retrieval/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ func (b *sampleBuilder) next(ctx context.Context, samples []tsdb.RefSample) (*mo
sample := samples[0]
tailSamples := samples[1:]

if (math.IsNaN(sample.V)) {
return nil, 0, tailSamples, nil
}

entry, ok, err := b.series.get(ctx, sample.Ref)
if err != nil {
return nil, 0, samples, errors.Wrap(err, "get series information")
Expand Down
75 changes: 75 additions & 0 deletions retrieval/transform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package retrieval

import (
"context"
"math"
"reflect"
"testing"

Expand Down Expand Up @@ -760,6 +761,80 @@ func TestSampleBuilder(t *testing.T) {
},
},
},
// Samples with a NaN value should be dropped.
{
targets: targetMap{
"job1/instance1": &targets.Target{
Labels: promlabels.FromStrings("job", "job1", "instance", "instance1"),
DiscoveredLabels: promlabels.FromStrings("__resource_a", "resource2_a"),
},
},
series: seriesMap{
1: labels.FromStrings("job", "job1", "instance", "instance1", "__name__", "metric1_count"),
},
metadata: metadataMap{
"job1/instance1/metric1": &scrape.MetricMetadata{Type: textparse.MetricTypeSummary, Metric: "metric1_count"},
},
metricPrefix: "test.googleapis.com",
input: []tsdb.RefSample{
// A first non-NaN sample is necessary to avoid false-positives, since the
// first result will always be nil due to reset timestamp handling.
{Ref: 1, T: 2000, V: 5},
{Ref: 1, T: 4000, V: math.NaN()},
},
result: []*monitoring_pb.TimeSeries{
nil, // due to reset timestamp handling
nil, // due to NaN
},
},
// Samples with a NaN value should be dropped.
{
targets: targetMap{
"job1/instance1": &targets.Target{
Labels: promlabels.FromStrings("job", "job1", "instance", "instance1"),
DiscoveredLabels: promlabels.FromStrings("__resource_a", "resource2_a"),
},
},
series: seriesMap{
1: labels.FromStrings("job", "job1", "instance", "instance1", "__name__", "metric1_count"),
},
metadata: metadataMap{
"job1/instance1/metric1": &scrape.MetricMetadata{Type: textparse.MetricTypeSummary, Metric: "metric1_count"},
},
metricPrefix: "test.googleapis.com",
input: []tsdb.RefSample{
// A first non-NaN sample is necessary to avoid false-positives, since the
// first result will always be nil due to reset timestamp handling.
{Ref: 1, T: 2000, V: 5},
{Ref: 1, T: 4000, V: math.NaN()},
{Ref: 1, T: 5000, V: 9},
},
result: []*monitoring_pb.TimeSeries{
nil, // due to reset timestamp handling
nil, // due to NaN
{
Resource: &monitoredres_pb.MonitoredResource{
Type: "resource2",
Labels: map[string]string{"resource_a": "resource2_a"},
},
Metric: &metric_pb.Metric{
Type: "test.googleapis.com/metric1_count",
Labels: map[string]string{},
},
MetricKind: metric_pb.MetricDescriptor_CUMULATIVE,
ValueType: metric_pb.MetricDescriptor_INT64,
Points: []*monitoring_pb.Point{{
Interval: &monitoring_pb.TimeInterval{
StartTime: &timestamp_pb.Timestamp{Seconds: 2},
EndTime: &timestamp_pb.Timestamp{Seconds: 5},
},
Value: &monitoring_pb.TypedValue{
Value: &monitoring_pb.TypedValue_Int64Value{4},
},
}},
},
},
},
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
Expand Down

0 comments on commit 596df4c

Please sign in to comment.