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"
)
@@ -35,23 +34,22 @@ func (n *Nginx) Description() string {
func (n *Nginx) Gather(acc telegraf.Accumulator) error {
var wg sync.WaitGroup
errChan := errchan.New(len(n.Urls))
for _, u := range n.Urls {
addr, err := url.Parse(u)
if err != nil {
return fmt.Errorf("Unable to parse address '%s': %s", u, err)
acc.AddError(fmt.Errorf("Unable to parse address '%s': %s", u, err))
}
wg.Add(1)
go func(addr *url.URL) {
defer wg.Done()
errChan.C <- n.gatherUrl(addr, acc)
acc.AddError(n.gatherUrl(addr, acc))
}(addr)
}
wg.Wait()
return errChan.Error()
return nil
}
var tr = &http.Transport{

View File

@@ -64,8 +64,8 @@ func TestNginxGeneratesMetrics(t *testing.T) {
var acc_nginx testutil.Accumulator
var acc_tengine testutil.Accumulator
err_nginx := n.Gather(&acc_nginx)
err_tengine := nt.Gather(&acc_tengine)
err_nginx := acc_nginx.GatherError(n.Gather)
err_tengine := acc_tengine.GatherError(nt.Gather)
require.NoError(t, err_nginx)
require.NoError(t, err_tengine)