Skip to content

Commit

Permalink
Fix delete in place of keys in stackdriver output (influxdata#5465)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Bazire authored and danielnelson committed Feb 21, 2019
1 parent 0a2cc3a commit 33dfbfd
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 2 deletions.
4 changes: 3 additions & 1 deletion plugins/outputs/stackdriver/stackdriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,14 @@ func (s *Stackdriver) Write(metrics []telegraf.Metric) error {
for len(buckets) != 0 {
// can send up to 200 time series to stackdriver
timeSeries := make([]*monitoringpb.TimeSeries, 0, 200)
for i, k := range keys {
for i := 0; i < len(keys); i++ {
k := keys[i]
s := buckets[k]
timeSeries = append(timeSeries, s[0])
if len(s) == 1 {
delete(buckets, k)
keys = append(keys[:i], keys[i+1:]...)
i--
continue
}

Expand Down
73 changes: 72 additions & 1 deletion plugins/outputs/stackdriver/stackdriver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,51 @@ func TestWriteBatchable(t *testing.T) {
},
time.Unix(1, 0),
),
testutil.MustMetric("ram",
map[string]string{
"foo": "bar",
},
map[string]interface{}{
"value": 42,
},
time.Unix(4, 0),
),
testutil.MustMetric("ram",
map[string]string{
"foo": "foo",
},
map[string]interface{}{
"value": 43,
},
time.Unix(5, 0),
),
testutil.MustMetric("ram",
map[string]string{
"foo": "bar",
},
map[string]interface{}{
"value": 43,
},
time.Unix(3, 0),
),
testutil.MustMetric("disk",
map[string]string{
"foo": "foo",
},
map[string]interface{}{
"value": 43,
},
time.Unix(3, 0),
),
testutil.MustMetric("disk",
map[string]string{
"foo": "bar",
},
map[string]interface{}{
"value": 43,
},
time.Unix(1, 0),
),
}

err = s.Connect()
Expand All @@ -262,7 +307,7 @@ func TestWriteBatchable(t *testing.T) {

require.Len(t, mockMetric.reqs, 2)
request := mockMetric.reqs[0].(*monitoringpb.CreateTimeSeriesRequest)
require.Len(t, request.TimeSeries, 2)
require.Len(t, request.TimeSeries, 6)
ts := request.TimeSeries[0]
require.Len(t, ts.Points, 1)
require.Equal(t, ts.Points[0].Interval, &monitoringpb.TimeInterval{
Expand All @@ -288,6 +333,32 @@ func TestWriteBatchable(t *testing.T) {
Int64Value: int64(43),
},
})

ts = request.TimeSeries[2]
require.Len(t, ts.Points, 1)
require.Equal(t, ts.Points[0].Interval, &monitoringpb.TimeInterval{
EndTime: &googlepb.Timestamp{
Seconds: 3,
},
})
require.Equal(t, ts.Points[0].Value, &monitoringpb.TypedValue{
Value: &monitoringpb.TypedValue_Int64Value{
Int64Value: int64(43),
},
})

ts = request.TimeSeries[4]
require.Len(t, ts.Points, 1)
require.Equal(t, ts.Points[0].Interval, &monitoringpb.TimeInterval{
EndTime: &googlepb.Timestamp{
Seconds: 5,
},
})
require.Equal(t, ts.Points[0].Value, &monitoringpb.TypedValue{
Value: &monitoringpb.TypedValue_Int64Value{
Int64Value: int64(43),
},
})
}

func TestWriteIgnoredErrors(t *testing.T) {
Expand Down

0 comments on commit 33dfbfd

Please sign in to comment.