use AddError everywhere (#2372)
This commit is contained in:
committed by
Daniel Nelson
parent
801f6cb8a0
commit
06baf7cf78
@@ -5,7 +5,7 @@ package ntpq
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"log"
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -132,7 +132,7 @@ func (n *NTPQ) Gather(acc telegraf.Accumulator) error {
|
||||
case strings.HasSuffix(when, "h"):
|
||||
m, err := strconv.Atoi(strings.TrimSuffix(fields[index], "h"))
|
||||
if err != nil {
|
||||
log.Printf("E! Error ntpq: parsing int: %s", fields[index])
|
||||
acc.AddError(fmt.Errorf("E! Error ntpq: parsing int: %s", fields[index]))
|
||||
continue
|
||||
}
|
||||
// seconds in an hour
|
||||
@@ -141,7 +141,7 @@ func (n *NTPQ) Gather(acc telegraf.Accumulator) error {
|
||||
case strings.HasSuffix(when, "d"):
|
||||
m, err := strconv.Atoi(strings.TrimSuffix(fields[index], "d"))
|
||||
if err != nil {
|
||||
log.Printf("E! Error ntpq: parsing int: %s", fields[index])
|
||||
acc.AddError(fmt.Errorf("E! Error ntpq: parsing int: %s", fields[index]))
|
||||
continue
|
||||
}
|
||||
// seconds in a day
|
||||
@@ -150,7 +150,7 @@ func (n *NTPQ) Gather(acc telegraf.Accumulator) error {
|
||||
case strings.HasSuffix(when, "m"):
|
||||
m, err := strconv.Atoi(strings.TrimSuffix(fields[index], "m"))
|
||||
if err != nil {
|
||||
log.Printf("E! Error ntpq: parsing int: %s", fields[index])
|
||||
acc.AddError(fmt.Errorf("E! Error ntpq: parsing int: %s", fields[index]))
|
||||
continue
|
||||
}
|
||||
// seconds in a day
|
||||
@@ -161,7 +161,7 @@ func (n *NTPQ) Gather(acc telegraf.Accumulator) error {
|
||||
|
||||
m, err := strconv.Atoi(fields[index])
|
||||
if err != nil {
|
||||
log.Printf("E! Error ntpq: parsing int: %s", fields[index])
|
||||
acc.AddError(fmt.Errorf("E! Error ntpq: parsing int: %s", fields[index]))
|
||||
continue
|
||||
}
|
||||
mFields[key] = int64(m)
|
||||
@@ -178,7 +178,7 @@ func (n *NTPQ) Gather(acc telegraf.Accumulator) error {
|
||||
|
||||
m, err := strconv.ParseFloat(fields[index], 64)
|
||||
if err != nil {
|
||||
log.Printf("E! Error ntpq: parsing float: %s", fields[index])
|
||||
acc.AddError(fmt.Errorf("E! Error ntpq: parsing float: %s", fields[index]))
|
||||
continue
|
||||
}
|
||||
mFields[key] = m
|
||||
|
||||
@@ -21,7 +21,7 @@ func TestSingleNTPQ(t *testing.T) {
|
||||
}
|
||||
|
||||
acc := testutil.Accumulator{}
|
||||
assert.NoError(t, n.Gather(&acc))
|
||||
assert.NoError(t, acc.GatherError(n.Gather))
|
||||
|
||||
fields := map[string]interface{}{
|
||||
"when": int64(101),
|
||||
@@ -51,7 +51,7 @@ func TestMissingJitterField(t *testing.T) {
|
||||
}
|
||||
|
||||
acc := testutil.Accumulator{}
|
||||
assert.NoError(t, n.Gather(&acc))
|
||||
assert.NoError(t, acc.GatherError(n.Gather))
|
||||
|
||||
fields := map[string]interface{}{
|
||||
"when": int64(101),
|
||||
@@ -80,7 +80,7 @@ func TestBadIntNTPQ(t *testing.T) {
|
||||
}
|
||||
|
||||
acc := testutil.Accumulator{}
|
||||
assert.NoError(t, n.Gather(&acc))
|
||||
assert.Error(t, acc.GatherError(n.Gather))
|
||||
|
||||
fields := map[string]interface{}{
|
||||
"when": int64(101),
|
||||
@@ -109,7 +109,7 @@ func TestBadFloatNTPQ(t *testing.T) {
|
||||
}
|
||||
|
||||
acc := testutil.Accumulator{}
|
||||
assert.NoError(t, n.Gather(&acc))
|
||||
assert.Error(t, acc.GatherError(n.Gather))
|
||||
|
||||
fields := map[string]interface{}{
|
||||
"when": int64(2),
|
||||
@@ -138,7 +138,7 @@ func TestDaysNTPQ(t *testing.T) {
|
||||
}
|
||||
|
||||
acc := testutil.Accumulator{}
|
||||
assert.NoError(t, n.Gather(&acc))
|
||||
assert.NoError(t, acc.GatherError(n.Gather))
|
||||
|
||||
fields := map[string]interface{}{
|
||||
"when": int64(172800),
|
||||
@@ -168,7 +168,7 @@ func TestHoursNTPQ(t *testing.T) {
|
||||
}
|
||||
|
||||
acc := testutil.Accumulator{}
|
||||
assert.NoError(t, n.Gather(&acc))
|
||||
assert.NoError(t, acc.GatherError(n.Gather))
|
||||
|
||||
fields := map[string]interface{}{
|
||||
"when": int64(7200),
|
||||
@@ -198,7 +198,7 @@ func TestMinutesNTPQ(t *testing.T) {
|
||||
}
|
||||
|
||||
acc := testutil.Accumulator{}
|
||||
assert.NoError(t, n.Gather(&acc))
|
||||
assert.NoError(t, acc.GatherError(n.Gather))
|
||||
|
||||
fields := map[string]interface{}{
|
||||
"when": int64(120),
|
||||
@@ -228,7 +228,7 @@ func TestBadWhenNTPQ(t *testing.T) {
|
||||
}
|
||||
|
||||
acc := testutil.Accumulator{}
|
||||
assert.NoError(t, n.Gather(&acc))
|
||||
assert.Error(t, acc.GatherError(n.Gather))
|
||||
|
||||
fields := map[string]interface{}{
|
||||
"poll": int64(256),
|
||||
@@ -257,7 +257,7 @@ func TestMultiNTPQ(t *testing.T) {
|
||||
}
|
||||
|
||||
acc := testutil.Accumulator{}
|
||||
assert.NoError(t, n.Gather(&acc))
|
||||
assert.NoError(t, acc.GatherError(n.Gather))
|
||||
|
||||
fields := map[string]interface{}{
|
||||
"delay": float64(54.033),
|
||||
@@ -303,7 +303,7 @@ func TestBadHeaderNTPQ(t *testing.T) {
|
||||
}
|
||||
|
||||
acc := testutil.Accumulator{}
|
||||
assert.NoError(t, n.Gather(&acc))
|
||||
assert.NoError(t, acc.GatherError(n.Gather))
|
||||
|
||||
fields := map[string]interface{}{
|
||||
"when": int64(101),
|
||||
@@ -333,7 +333,7 @@ func TestMissingDelayColumnNTPQ(t *testing.T) {
|
||||
}
|
||||
|
||||
acc := testutil.Accumulator{}
|
||||
assert.NoError(t, n.Gather(&acc))
|
||||
assert.NoError(t, acc.GatherError(n.Gather))
|
||||
|
||||
fields := map[string]interface{}{
|
||||
"when": int64(101),
|
||||
@@ -361,7 +361,7 @@ func TestFailedNTPQ(t *testing.T) {
|
||||
}
|
||||
|
||||
acc := testutil.Accumulator{}
|
||||
assert.Error(t, n.Gather(&acc))
|
||||
assert.Error(t, acc.GatherError(n.Gather))
|
||||
}
|
||||
|
||||
type tester struct {
|
||||
|
||||
Reference in New Issue
Block a user