-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bugfix/procstat adds new procstat metric about pgrep search #4307
Changes from 8 commits
733d325
c9269b8
6c18bfd
67b1472
01bf4c3
a863c4a
849df3d
0c19b69
4f69d17
2ab9b2a
87eb98e
dc2b9a8
c576243
236120c
d5ebb1e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ import ( | |
"testing" | ||
"time" | ||
|
||
"github.com/influxdata/telegraf/internal" | ||
"github.com/influxdata/telegraf/testutil" | ||
"github.com/shirou/gopsutil/cpu" | ||
"github.com/shirou/gopsutil/process" | ||
|
@@ -369,3 +370,39 @@ func TestGather_cgroupPIDs(t *testing.T) { | |
assert.Equal(t, []PID{1234, 5678}, pids) | ||
assert.Equal(t, td, tags["cgroup"]) | ||
} | ||
|
||
func TestExitStatus(t *testing.T) { | ||
out, err := exec.Command("pgrep", "-G", "sys").Output() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This command could return different results on different systems, so it could create random failures, perhaps you can make the needed error by hand. Also, it tests a function in |
||
t.Logf("cmd out: %v", out) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove any logging in the test cases, use assertions to document results. |
||
exitNum, _ := internal.ExitStatus(err) | ||
t.Logf("error status: %v", exitNum) | ||
require.Equal(t, 1, exitNum) | ||
} | ||
|
||
func TestNoPgrepResults(t *testing.T) { | ||
p := Procstat{ | ||
PidFinder: "pgrep", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment as above for this and the next test. You should be able to use testPgrep in this same file to fake the results. |
||
//executing this command should result exit status 1 | ||
Exe: "-Gsys", | ||
} | ||
|
||
var acc testutil.Accumulator | ||
err := acc.GatherError(p.Gather) | ||
|
||
t.Logf("gather err: %v", err) | ||
require.NoError(t, err) | ||
} | ||
|
||
func TestProcstatMetrics(t *testing.T) { | ||
p := Procstat{ | ||
PidFinder: "pgrep", | ||
//executing this command should result exit status 1 | ||
Exe: "-Gsys", | ||
} | ||
var acc testutil.Accumulator | ||
err := acc.GatherError(p.Gather) | ||
require.NoError(t, err) | ||
t.Logf("num of pids: %v", len(p.procs)) | ||
t.Logf("num of metrics: %v", len(acc.Metrics)) | ||
require.Equal(t, len(p.procs)+1, len(acc.Metrics)) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep only the old error message.