-
Notifications
You must be signed in to change notification settings - Fork 23
/
procfs_scraper.go
100 lines (85 loc) · 2.97 KB
/
procfs_scraper.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package suites
import (
"strconv"
"time"
"github.com/stackrox/collector/integration-tests/pkg/collector"
"github.com/stackrox/collector/integration-tests/pkg/common"
"github.com/stackrox/collector/integration-tests/pkg/config"
"github.com/stackrox/collector/integration-tests/pkg/types"
)
type ProcfsScraperTestSuite struct {
IntegrationTestSuiteBase
ServerContainer string
TurnOffScrape bool
RoxProcessesListeningOnPort bool
}
// Launches nginx container
// Launches gRPC server in insecure mode
// Launches collector
// Note it is important to launch the nginx container before collector, which is the opposite of
// other tests. The purpose is that we want ProcfsScraper to see the nginx endpoint and we do not want
// NetworkSignalHandler to see the nginx endpoint.
func (s *ProcfsScraperTestSuite) SetupSuite() {
s.RegisterCleanup("nginx")
s.StartContainerStats()
collectorOptions := collector.StartupOptions{
Env: map[string]string{
"ROX_PROCESSES_LISTENING_ON_PORT": strconv.FormatBool(s.RoxProcessesListeningOnPort),
},
Config: map[string]any{
"turnOffScrape": s.TurnOffScrape,
},
}
s.launchNginx()
s.StartCollector(false, &collectorOptions)
s.cleanupContainers("nginx")
}
func (s *ProcfsScraperTestSuite) launchNginx() {
image := config.Images().ImageByKey("nginx")
err := s.executor.PullImage(image)
s.Require().NoError(err)
// invokes default nginx
containerID, err := s.launchContainer("nginx", image)
s.Require().NoError(err)
s.ServerContainer = common.ContainerShortID(containerID)
}
func (s *ProcfsScraperTestSuite) TearDownSuite() {
s.StopCollector()
s.cleanupContainers("nginx")
s.WritePerfResults()
}
func (s *ProcfsScraperTestSuite) TestProcfsScraper() {
if !s.TurnOffScrape && s.RoxProcessesListeningOnPort {
// If scraping is on and the feature flag is enables we expect to find the nginx endpoint
processes := s.Sensor().Processes(s.ServerContainer)
s.Sensor().ExpectEndpoints(s.T(), s.ServerContainer, 10*time.Second, types.EndpointInfo{
Protocol: "L4_PROTOCOL_TCP",
CloseTimestamp: types.NilTimestamp,
Originator: &types.ProcessOriginator{
ProcessName: processes[0].Name,
ProcessExecFilePath: processes[0].ExePath,
ProcessArgs: processes[0].Args,
},
}, types.EndpointInfo{
Protocol: "L4_PROTOCOL_TCP",
CloseTimestamp: types.NilTimestamp,
Originator: &types.ProcessOriginator{
ProcessName: processes[0].Name,
ProcessExecFilePath: processes[0].ExePath,
ProcessArgs: processes[0].Args,
},
})
} else {
// If scraping is off or the feature flag is disabled
// we expect to find the endpoint but with no originator process
s.Sensor().ExpectEndpoints(s.T(), s.ServerContainer, 10*time.Second, types.EndpointInfo{
Protocol: "L4_PROTOCOL_TCP",
CloseTimestamp: types.NilTimestamp,
Originator: &types.ProcessOriginator{
ProcessName: "",
ProcessExecFilePath: "",
ProcessArgs: "",
},
})
}
}