Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Statsd input panic when processing DataDog events #6121

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions plugins/inputs/statsd/datadog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ func TestEventGather(t *testing.T) {
}
acc := &testutil.Accumulator{}
s := NewTestStatsd()
s.acc = acc
require.NoError(t, s.Start(acc))
defer s.Stop()

for i := range tests {
t.Run(tests[i].name, func(t *testing.T) {
Expand Down Expand Up @@ -379,11 +380,13 @@ func TestEvents(t *testing.T) {
},
},
}
s := NewTestStatsd()
acc := &testutil.Accumulator{}
require.NoError(t, s.Start(acc))
defer s.Stop()
for i := range tests {
t.Run(tests[i].name, func(t *testing.T) {
s := NewTestStatsd()
acc := &testutil.Accumulator{}
s.acc = acc
acc.ClearMetrics()
err := s.parseEventMessage(tests[i].args.now, tests[i].args.message, tests[i].args.hostname)
require.Nil(t, err)
m := acc.Metrics[0]
Expand All @@ -406,7 +409,10 @@ func TestEvents(t *testing.T) {
func TestEventError(t *testing.T) {
now := time.Now()
s := NewTestStatsd()
s.acc = &testutil.Accumulator{}
acc := &testutil.Accumulator{}
require.NoError(t, s.Start(acc))
defer s.Stop()

// missing length header
err := s.parseEventMessage(now, "_e:title|text", "default-hostname")
require.Error(t, err)
Expand Down
5 changes: 4 additions & 1 deletion plugins/inputs/statsd/statsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,11 +309,14 @@ func (s *Statsd) Gather(acc telegraf.Accumulator) error {
return nil
}

func (s *Statsd) Start(_ telegraf.Accumulator) error {
func (s *Statsd) Start(ac telegraf.Accumulator) error {
if s.ParseDataDogTags {
s.DataDogExtensions = true
log.Printf("W! [inputs.statsd] The parse_data_dog_tags option is deprecated, use datadog_extensions instead.")
}

s.acc = ac

// Make data structures
s.gauges = make(map[string]cachedgauge)
s.counters = make(map[string]cachedcounter)
Expand Down