use AddError everywhere (#2372)
This commit is contained in:
committed by
Daniel Nelson
parent
801f6cb8a0
commit
06baf7cf78
@@ -71,9 +71,8 @@ func (p *Procstat) Gather(acc telegraf.Accumulator) error {
|
||||
|
||||
procs, err := p.updateProcesses(p.procs)
|
||||
if err != nil {
|
||||
return fmt.Errorf(
|
||||
"E! Error: procstat getting process, exe: [%s] pidfile: [%s] pattern: [%s] user: [%s] %s",
|
||||
p.Exe, p.PidFile, p.Pattern, p.User, err.Error())
|
||||
acc.AddError(fmt.Errorf("E! Error: procstat getting process, exe: [%s] pidfile: [%s] pattern: [%s] user: [%s] %s",
|
||||
p.Exe, p.PidFile, p.Pattern, p.User, err.Error()))
|
||||
}
|
||||
p.procs = procs
|
||||
|
||||
|
||||
@@ -108,7 +108,7 @@ func TestGather_CreateProcessErrorOk(t *testing.T) {
|
||||
return nil, fmt.Errorf("createProcess error")
|
||||
},
|
||||
}
|
||||
require.NoError(t, p.Gather(&acc))
|
||||
require.NoError(t, acc.GatherError(p.Gather))
|
||||
}
|
||||
|
||||
func TestGather_CreatePIDFinderError(t *testing.T) {
|
||||
@@ -120,7 +120,7 @@ func TestGather_CreatePIDFinderError(t *testing.T) {
|
||||
},
|
||||
createProcess: newTestProc,
|
||||
}
|
||||
require.Error(t, p.Gather(&acc))
|
||||
require.Error(t, acc.GatherError(p.Gather))
|
||||
}
|
||||
|
||||
func TestGather_ProcessName(t *testing.T) {
|
||||
@@ -132,7 +132,7 @@ func TestGather_ProcessName(t *testing.T) {
|
||||
createPIDFinder: pidFinder([]PID{pid}, nil),
|
||||
createProcess: newTestProc,
|
||||
}
|
||||
require.NoError(t, p.Gather(&acc))
|
||||
require.NoError(t, acc.GatherError(p.Gather))
|
||||
|
||||
assert.Equal(t, "custom_name", acc.TagValue("procstat", "process_name"))
|
||||
}
|
||||
@@ -146,7 +146,7 @@ func TestGather_NoProcessNameUsesReal(t *testing.T) {
|
||||
createPIDFinder: pidFinder([]PID{pid}, nil),
|
||||
createProcess: newTestProc,
|
||||
}
|
||||
require.NoError(t, p.Gather(&acc))
|
||||
require.NoError(t, acc.GatherError(p.Gather))
|
||||
|
||||
assert.True(t, acc.HasTag("procstat", "process_name"))
|
||||
}
|
||||
@@ -159,7 +159,7 @@ func TestGather_NoPidTag(t *testing.T) {
|
||||
createPIDFinder: pidFinder([]PID{pid}, nil),
|
||||
createProcess: newTestProc,
|
||||
}
|
||||
require.NoError(t, p.Gather(&acc))
|
||||
require.NoError(t, acc.GatherError(p.Gather))
|
||||
assert.True(t, acc.HasInt32Field("procstat", "pid"))
|
||||
assert.False(t, acc.HasTag("procstat", "pid"))
|
||||
}
|
||||
@@ -173,7 +173,7 @@ func TestGather_PidTag(t *testing.T) {
|
||||
createPIDFinder: pidFinder([]PID{pid}, nil),
|
||||
createProcess: newTestProc,
|
||||
}
|
||||
require.NoError(t, p.Gather(&acc))
|
||||
require.NoError(t, acc.GatherError(p.Gather))
|
||||
assert.Equal(t, "42", acc.TagValue("procstat", "pid"))
|
||||
assert.False(t, acc.HasInt32Field("procstat", "pid"))
|
||||
}
|
||||
@@ -187,7 +187,7 @@ func TestGather_Prefix(t *testing.T) {
|
||||
createPIDFinder: pidFinder([]PID{pid}, nil),
|
||||
createProcess: newTestProc,
|
||||
}
|
||||
require.NoError(t, p.Gather(&acc))
|
||||
require.NoError(t, acc.GatherError(p.Gather))
|
||||
assert.True(t, acc.HasInt32Field("procstat", "custom_prefix_num_fds"))
|
||||
}
|
||||
|
||||
@@ -199,7 +199,7 @@ func TestGather_Exe(t *testing.T) {
|
||||
createPIDFinder: pidFinder([]PID{pid}, nil),
|
||||
createProcess: newTestProc,
|
||||
}
|
||||
require.NoError(t, p.Gather(&acc))
|
||||
require.NoError(t, acc.GatherError(p.Gather))
|
||||
|
||||
assert.Equal(t, exe, acc.TagValue("procstat", "exe"))
|
||||
}
|
||||
@@ -213,7 +213,7 @@ func TestGather_User(t *testing.T) {
|
||||
createPIDFinder: pidFinder([]PID{pid}, nil),
|
||||
createProcess: newTestProc,
|
||||
}
|
||||
require.NoError(t, p.Gather(&acc))
|
||||
require.NoError(t, acc.GatherError(p.Gather))
|
||||
|
||||
assert.Equal(t, user, acc.TagValue("procstat", "user"))
|
||||
}
|
||||
@@ -227,7 +227,7 @@ func TestGather_Pattern(t *testing.T) {
|
||||
createPIDFinder: pidFinder([]PID{pid}, nil),
|
||||
createProcess: newTestProc,
|
||||
}
|
||||
require.NoError(t, p.Gather(&acc))
|
||||
require.NoError(t, acc.GatherError(p.Gather))
|
||||
|
||||
assert.Equal(t, pattern, acc.TagValue("procstat", "pattern"))
|
||||
}
|
||||
@@ -239,7 +239,7 @@ func TestGather_MissingPidMethod(t *testing.T) {
|
||||
createPIDFinder: pidFinder([]PID{pid}, nil),
|
||||
createProcess: newTestProc,
|
||||
}
|
||||
require.Error(t, p.Gather(&acc))
|
||||
require.Error(t, acc.GatherError(p.Gather))
|
||||
}
|
||||
|
||||
func TestGather_PidFile(t *testing.T) {
|
||||
@@ -251,7 +251,7 @@ func TestGather_PidFile(t *testing.T) {
|
||||
createPIDFinder: pidFinder([]PID{pid}, nil),
|
||||
createProcess: newTestProc,
|
||||
}
|
||||
require.NoError(t, p.Gather(&acc))
|
||||
require.NoError(t, acc.GatherError(p.Gather))
|
||||
|
||||
assert.Equal(t, pidfile, acc.TagValue("procstat", "pidfile"))
|
||||
}
|
||||
@@ -266,7 +266,7 @@ func TestGather_PercentFirstPass(t *testing.T) {
|
||||
createPIDFinder: pidFinder([]PID{pid}, nil),
|
||||
createProcess: NewProc,
|
||||
}
|
||||
require.NoError(t, p.Gather(&acc))
|
||||
require.NoError(t, acc.GatherError(p.Gather))
|
||||
|
||||
assert.True(t, acc.HasFloatField("procstat", "cpu_time_user"))
|
||||
assert.False(t, acc.HasFloatField("procstat", "cpu_usage"))
|
||||
@@ -282,8 +282,8 @@ func TestGather_PercentSecondPass(t *testing.T) {
|
||||
createPIDFinder: pidFinder([]PID{pid}, nil),
|
||||
createProcess: NewProc,
|
||||
}
|
||||
require.NoError(t, p.Gather(&acc))
|
||||
require.NoError(t, p.Gather(&acc))
|
||||
require.NoError(t, acc.GatherError(p.Gather))
|
||||
require.NoError(t, acc.GatherError(p.Gather))
|
||||
|
||||
assert.True(t, acc.HasFloatField("procstat", "cpu_time_user"))
|
||||
assert.True(t, acc.HasFloatField("procstat", "cpu_usage"))
|
||||
|
||||
Reference in New Issue
Block a user