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

@@ -12,7 +12,6 @@ import (
"time"
"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/internal/errchan"
"github.com/influxdata/telegraf/plugins/inputs"
)
@@ -66,7 +65,6 @@ func (r *Redis) Gather(acc telegraf.Accumulator) error {
}
var wg sync.WaitGroup
errChan := errchan.New(len(r.Servers))
for _, serv := range r.Servers {
if !strings.HasPrefix(serv, "tcp://") && !strings.HasPrefix(serv, "unix://") {
serv = "tcp://" + serv
@@ -74,7 +72,8 @@ func (r *Redis) Gather(acc telegraf.Accumulator) error {
u, err := url.Parse(serv)
if err != nil {
return fmt.Errorf("Unable to parse to address '%s': %s", serv, err)
acc.AddError(fmt.Errorf("Unable to parse to address '%s': %s", serv, err))
continue
} else if u.Scheme == "" {
// fallback to simple string based address (i.e. "10.0.0.1:10000")
u.Scheme = "tcp"
@@ -91,12 +90,12 @@ func (r *Redis) Gather(acc telegraf.Accumulator) error {
wg.Add(1)
go func(serv string) {
defer wg.Done()
errChan.C <- r.gatherServer(u, acc)
acc.AddError(r.gatherServer(u, acc))
}(serv)
}
wg.Wait()
return errChan.Error()
return nil
}
func (r *Redis) gatherServer(addr *url.URL, acc telegraf.Accumulator) error {

View File

@@ -25,7 +25,7 @@ func TestRedisConnect(t *testing.T) {
var acc testutil.Accumulator
err := r.Gather(&acc)
err := acc.GatherError(r.Gather)
require.NoError(t, err)
}