Add staggering between identical start and end times (#321)
* Add staggering between identical start and end times
diff --git a/metrics.go b/metrics.go
index 1516c35..fee316d 100644
--- a/metrics.go
+++ b/metrics.go
@@ -411,12 +411,16 @@
return nil, err
}
+ interval := &monitoringpb.TimeInterval{
+ StartTime: startTime,
+ EndTime: timestampProto(pt.Time),
+ }
+ if startTime != nil {
+ interval = toValidTimeIntervalpb(startTime.AsTime(), pt.Time)
+ }
mpt := &monitoringpb.Point{
- Value: mptv,
- Interval: &monitoringpb.TimeInterval{
- StartTime: startTime,
- EndTime: timestampProto(pt.Time),
- },
+ Value: mptv,
+ Interval: interval,
}
return mpt, nil
}
diff --git a/metrics_test.go b/metrics_test.go
index 50be3a9..cf7d953 100644
--- a/metrics_test.go
+++ b/metrics_test.go
@@ -19,6 +19,7 @@
"fmt"
"strings"
"testing"
+ "time"
"github.com/golang/protobuf/ptypes/any"
"github.com/golang/protobuf/ptypes/timestamp"
@@ -542,6 +543,21 @@
},
},
},
+ {
+ in: &metricdata.Point{
+ Time: startTime.Add(5 * time.Nanosecond),
+ Value: int64(17),
+ },
+ want: &monitoringpb.Point{
+ Interval: &monitoringpb.TimeInterval{
+ StartTime: startTimestamp,
+ EndTime: timestampProto(startTime.Add(time.Millisecond)),
+ },
+ Value: &monitoringpb.TypedValue{
+ Value: &monitoringpb.TypedValue_Int64Value{Int64Value: 17},
+ },
+ },
+ },
}
for i, tt := range tests {