Initialize accumulator in statsd during Start (#6121)
This commit is contained in:
parent
169fd64788
commit
b15fe4a28e
|
@ -74,7 +74,8 @@ func TestEventGather(t *testing.T) {
|
||||||
}
|
}
|
||||||
acc := &testutil.Accumulator{}
|
acc := &testutil.Accumulator{}
|
||||||
s := NewTestStatsd()
|
s := NewTestStatsd()
|
||||||
s.acc = acc
|
require.NoError(t, s.Start(acc))
|
||||||
|
defer s.Stop()
|
||||||
|
|
||||||
for i := range tests {
|
for i := range tests {
|
||||||
t.Run(tests[i].name, func(t *testing.T) {
|
t.Run(tests[i].name, func(t *testing.T) {
|
||||||
|
@ -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 {
|
for i := range tests {
|
||||||
t.Run(tests[i].name, func(t *testing.T) {
|
t.Run(tests[i].name, func(t *testing.T) {
|
||||||
s := NewTestStatsd()
|
acc.ClearMetrics()
|
||||||
acc := &testutil.Accumulator{}
|
|
||||||
s.acc = acc
|
|
||||||
err := s.parseEventMessage(tests[i].args.now, tests[i].args.message, tests[i].args.hostname)
|
err := s.parseEventMessage(tests[i].args.now, tests[i].args.message, tests[i].args.hostname)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
m := acc.Metrics[0]
|
m := acc.Metrics[0]
|
||||||
|
@ -406,7 +409,10 @@ func TestEvents(t *testing.T) {
|
||||||
func TestEventError(t *testing.T) {
|
func TestEventError(t *testing.T) {
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
s := NewTestStatsd()
|
s := NewTestStatsd()
|
||||||
s.acc = &testutil.Accumulator{}
|
acc := &testutil.Accumulator{}
|
||||||
|
require.NoError(t, s.Start(acc))
|
||||||
|
defer s.Stop()
|
||||||
|
|
||||||
// missing length header
|
// missing length header
|
||||||
err := s.parseEventMessage(now, "_e:title|text", "default-hostname")
|
err := s.parseEventMessage(now, "_e:title|text", "default-hostname")
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
|
|
|
@ -309,11 +309,14 @@ func (s *Statsd) Gather(acc telegraf.Accumulator) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Statsd) Start(_ telegraf.Accumulator) error {
|
func (s *Statsd) Start(ac telegraf.Accumulator) error {
|
||||||
if s.ParseDataDogTags {
|
if s.ParseDataDogTags {
|
||||||
s.DataDogExtensions = true
|
s.DataDogExtensions = true
|
||||||
log.Printf("W! [inputs.statsd] The parse_data_dog_tags option is deprecated, use datadog_extensions instead.")
|
log.Printf("W! [inputs.statsd] The parse_data_dog_tags option is deprecated, use datadog_extensions instead.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s.acc = ac
|
||||||
|
|
||||||
// Make data structures
|
// Make data structures
|
||||||
s.gauges = make(map[string]cachedgauge)
|
s.gauges = make(map[string]cachedgauge)
|
||||||
s.counters = make(map[string]cachedcounter)
|
s.counters = make(map[string]cachedcounter)
|
||||||
|
|
Loading…
Reference in New Issue