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

@@ -9,7 +9,6 @@ import (
"time"
"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/internal/errchan"
"github.com/influxdata/telegraf/plugins/inputs"
)
@@ -58,11 +57,10 @@ func (d *DnsQuery) Description() string {
func (d *DnsQuery) Gather(acc telegraf.Accumulator) error {
d.setDefaultValues()
errChan := errchan.New(len(d.Domains) * len(d.Servers))
for _, domain := range d.Domains {
for _, server := range d.Servers {
dnsQueryTime, err := d.getDnsQueryTime(domain, server)
errChan.C <- err
acc.AddError(err)
tags := map[string]string{
"server": server,
"domain": domain,
@@ -74,7 +72,7 @@ func (d *DnsQuery) Gather(acc telegraf.Accumulator) error {
}
}
return errChan.Error()
return nil
}
func (d *DnsQuery) setDefaultValues() {

View File

@@ -24,7 +24,7 @@ func TestGathering(t *testing.T) {
}
var acc testutil.Accumulator
err := dnsConfig.Gather(&acc)
err := acc.GatherError(dnsConfig.Gather)
assert.NoError(t, err)
metric, ok := acc.Get("dns_query")
require.True(t, ok)
@@ -44,7 +44,7 @@ func TestGatheringMxRecord(t *testing.T) {
var acc testutil.Accumulator
dnsConfig.RecordType = "MX"
err := dnsConfig.Gather(&acc)
err := acc.GatherError(dnsConfig.Gather)
assert.NoError(t, err)
metric, ok := acc.Get("dns_query")
require.True(t, ok)
@@ -70,7 +70,7 @@ func TestGatheringRootDomain(t *testing.T) {
}
fields := map[string]interface{}{}
err := dnsConfig.Gather(&acc)
err := acc.GatherError(dnsConfig.Gather)
assert.NoError(t, err)
metric, ok := acc.Get("dns_query")
require.True(t, ok)
@@ -96,7 +96,7 @@ func TestMetricContainsServerAndDomainAndRecordTypeTags(t *testing.T) {
}
fields := map[string]interface{}{}
err := dnsConfig.Gather(&acc)
err := acc.GatherError(dnsConfig.Gather)
assert.NoError(t, err)
metric, ok := acc.Get("dns_query")
require.True(t, ok)
@@ -121,7 +121,7 @@ func TestGatheringTimeout(t *testing.T) {
channel := make(chan error, 1)
go func() {
channel <- dnsConfig.Gather(&acc)
channel <- acc.GatherError(dnsConfig.Gather)
}()
select {
case res := <-channel: