Skip to content

Commit f0a9eb5

Browse files
CriGoTdanielnelson
authored andcommitted
Initialize accumulator in statsd during Start (#6121)
(cherry picked from commit b15fe4a)
1 parent 93a004e commit f0a9eb5

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

plugins/inputs/statsd/datadog_test.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ func TestEventGather(t *testing.T) {
7474
}
7575
acc := &testutil.Accumulator{}
7676
s := NewTestStatsd()
77-
s.acc = acc
77+
require.NoError(t, s.Start(acc))
78+
defer s.Stop()
7879

7980
for i := range tests {
8081
t.Run(tests[i].name, func(t *testing.T) {
@@ -379,11 +380,13 @@ func TestEvents(t *testing.T) {
379380
},
380381
},
381382
}
383+
s := NewTestStatsd()
384+
acc := &testutil.Accumulator{}
385+
require.NoError(t, s.Start(acc))
386+
defer s.Stop()
382387
for i := range tests {
383388
t.Run(tests[i].name, func(t *testing.T) {
384-
s := NewTestStatsd()
385-
acc := &testutil.Accumulator{}
386-
s.acc = acc
389+
acc.ClearMetrics()
387390
err := s.parseEventMessage(tests[i].args.now, tests[i].args.message, tests[i].args.hostname)
388391
require.Nil(t, err)
389392
m := acc.Metrics[0]
@@ -406,7 +409,10 @@ func TestEvents(t *testing.T) {
406409
func TestEventError(t *testing.T) {
407410
now := time.Now()
408411
s := NewTestStatsd()
409-
s.acc = &testutil.Accumulator{}
412+
acc := &testutil.Accumulator{}
413+
require.NoError(t, s.Start(acc))
414+
defer s.Stop()
415+
410416
// missing length header
411417
err := s.parseEventMessage(now, "_e:title|text", "default-hostname")
412418
require.Error(t, err)

plugins/inputs/statsd/statsd.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,11 +309,14 @@ func (s *Statsd) Gather(acc telegraf.Accumulator) error {
309309
return nil
310310
}
311311

312-
func (s *Statsd) Start(_ telegraf.Accumulator) error {
312+
func (s *Statsd) Start(ac telegraf.Accumulator) error {
313313
if s.ParseDataDogTags {
314314
s.DataDogExtensions = true
315315
log.Printf("W! [inputs.statsd] The parse_data_dog_tags option is deprecated, use datadog_extensions instead.")
316316
}
317+
318+
s.acc = ac
319+
317320
// Make data structures
318321
s.gauges = make(map[string]cachedgauge)
319322
s.counters = make(map[string]cachedcounter)

0 commit comments

Comments
 (0)