Skip to content
This repository was archived by the owner on Jul 27, 2023. It is now read-only.

Commit 8b22bad

Browse files
committed
[proc] do not skip container if all its processes are skipped
1 parent 00b8aa3 commit 8b22bad

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

checks/process.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,9 @@ func createProcCtrMessages(
124124
ctrProcs := make([]*model.Process, 0)
125125
ctrs := make([]*model.Container, 0, len(containers))
126126
for _, ctr := range containers {
127-
// if all processes are skipped for this container, don't send the container
128-
if _, ok := procsByCtr[ctr.Id]; !ok {
129-
continue
127+
if procs, ok := procsByCtr[ctr.Id]; ok {
128+
ctrProcs = append(ctrProcs, procs...)
130129
}
131-
ctrProcs = append(ctrProcs, procsByCtr[ctr.Id]...)
132130
ctrs = append(ctrs, ctr)
133131
}
134132

checks/process_test.go

+13-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package checks
22

33
import (
4-
"errors"
54
"regexp"
65
"runtime"
76
"strconv"
@@ -20,10 +19,7 @@ import (
2019
"github.com/DataDog/gopsutil/process"
2120
)
2221

23-
func procCtrGenerator(pCount int, cCount int, containeredProcs int) ([]*process.FilledProcess, []*containers.Container, error) {
24-
if (pCount < cCount) || (containeredProcs > pCount) {
25-
return nil, nil, errors.New("The process and container count specified is not valid")
26-
}
22+
func procCtrGenerator(pCount int, cCount int, containeredProcs int) ([]*process.FilledProcess, []*containers.Container) {
2723
procs := make([]*process.FilledProcess, 0, pCount)
2824
for i := 0; i < pCount; i++ {
2925
procs = append(procs, makeProcess(int32(i), strconv.Itoa(i)))
@@ -45,7 +41,7 @@ func procCtrGenerator(pCount int, cCount int, containeredProcs int) ([]*process.
4541
ctrIdx++
4642
}
4743

48-
return procs, ctrs, nil
44+
return procs, ctrs
4945
}
5046

5147
func procsToHash(procs []*process.FilledProcess) (procsByPid map[int32]*process.FilledProcess) {
@@ -113,6 +109,14 @@ func TestRandomizeMessages(t *testing.T) {
113109
maxSize: 30,
114110
chunks: 4,
115111
},
112+
{
113+
testName: "no-processes",
114+
pCount: 0,
115+
cCount: 30,
116+
cProcs: 0,
117+
maxSize: 10,
118+
chunks: 1,
119+
},
116120
{
117121
testName: "container-process-mixed-1",
118122
pCount: 100,
@@ -148,9 +152,8 @@ func TestRandomizeMessages(t *testing.T) {
148152
} {
149153

150154
t.Run(tc.testName, func(t *testing.T) {
151-
procs, ctrs, err := procCtrGenerator(tc.pCount, tc.cCount, tc.cProcs)
155+
procs, ctrs := procCtrGenerator(tc.pCount, tc.cCount, tc.cProcs)
152156
procsByPid := procsToHash(procs)
153-
assert.NoError(t, err)
154157

155158
lastRun := time.Now().Add(-5 * time.Second)
156159
syst1, syst2 := cpu.TimesStat{}, cpu.TimesStat{}
@@ -264,9 +267,9 @@ func TestBasicProcessMessages(t *testing.T) {
264267
maxSize: 2,
265268
containers: []*containers.Container{c[1]},
266269
blacklist: []string{"foo"},
267-
expectedChunks: 1,
270+
expectedChunks: 2,
268271
totalProcs: 2,
269-
totalContainers: 0,
272+
totalContainers: 1,
270273
},
271274
} {
272275
t.Run(tc.testName, func(t *testing.T) {

0 commit comments

Comments
 (0)