use AddError everywhere (#2372)

This commit is contained in:
Patrick Hemmer
2017-04-24 14:13:26 -04:00
committed by Daniel Nelson
parent 801f6cb8a0
commit 06baf7cf78
95 changed files with 341 additions and 531 deletions

View File

@@ -68,7 +68,6 @@ func (_ *Ping) SampleConfig() string {
func (p *Ping) Gather(acc telegraf.Accumulator) error {
var wg sync.WaitGroup
errorChannel := make(chan error, len(p.Urls)*2)
// Spin off a go routine for each url to ping
for _, url := range p.Urls {
@@ -80,14 +79,14 @@ func (p *Ping) Gather(acc telegraf.Accumulator) error {
out, err := p.pingHost(totalTimeout, args...)
if err != nil {
// Combine go err + stderr output
errorChannel <- errors.New(
strings.TrimSpace(out) + ", " + err.Error())
acc.AddError(errors.New(
strings.TrimSpace(out) + ", " + err.Error()))
}
tags := map[string]string{"url": u}
trans, rec, avg, stddev, err := processPingOutput(out)
if err != nil {
// fatal error
errorChannel <- err
acc.AddError(err)
return
}
// Calculate packet loss percentage
@@ -108,18 +107,8 @@ func (p *Ping) Gather(acc telegraf.Accumulator) error {
}
wg.Wait()
close(errorChannel)
// Get all errors and return them as one giant error
errorStrings := []string{}
for err := range errorChannel {
errorStrings = append(errorStrings, err.Error())
}
if len(errorStrings) == 0 {
return nil
}
return errors.New(strings.Join(errorStrings, "\n"))
return nil
}
func hostPinger(timeout float64, args ...string) (string, error) {