Skip to content

ROX-29500: Use stackrox protobufs instead of types.NetworkInfo #2189

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

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
d3c4a64
X-Smart-Branch-Parent: master
JoukoVirtanen Jun 27, 2025
037aa91
Reduced usage of NetworkInfo
JoukoVirtanen Jun 23, 2025
d9cc8be
Entirely removed types.NetworkInfo
JoukoVirtanen Jun 23, 2025
b325c41
Changed NetworkInfoBatch to NetworkConnectionBatch
JoukoVirtanen Jun 23, 2025
7871e22
Fixed TestProcessNetwork
JoukoVirtanen Jun 24, 2025
3c27b20
Fixed repeated_network_flow.go
JoukoVirtanen Jun 25, 2025
67010b6
Fixed listening_ports.go
JoukoVirtanen Jun 25, 2025
4bf0b9c
Fixed udp_networkflow.go
JoukoVirtanen Jun 25, 2025
340510f
Check for equality between connections checks for protocol
JoukoVirtanen Jun 26, 2025
23de1bb
Removed unused import
JoukoVirtanen Jun 26, 2025
b465bf6
Using EqualVT from generated code rather than own function
JoukoVirtanen Jun 28, 2025
b285896
Setting port variables
JoukoVirtanen Jul 2, 2025
f04ed83
Using EqualNetworkConnection for connections_and_endpoints.go
JoukoVirtanen Jul 2, 2025
712c132
adjustNetworkConnectionForComparison passes conn by value instead of …
JoukoVirtanen Jul 2, 2025
56cae48
Using bytes.Compare instead of CompareBytes
JoukoVirtanen Jul 2, 2025
1283ac1
Using proto.Equal instead of EqualVT
JoukoVirtanen Jul 3, 2025
f38392b
Removed NotNilTimestamp
JoukoVirtanen Jul 3, 2025
c0c605b
Fixed LessNetworkConnection
JoukoVirtanen Jul 3, 2025
9952557
Passing conn to adjustNetworkConnectionForComparison by reference rat…
JoukoVirtanen Jul 14, 2025
2fdd62b
Moved some vars to const
JoukoVirtanen Jul 14, 2025
1404d11
Moved adjustNetworkConnectionForComparison inside EqualNetworkConnection
JoukoVirtanen Jul 14, 2025
0e6a2eb
connections_and_endpoints.go doesn't compare close timestamps
JoukoVirtanen Jul 14, 2025
453bfdc
Use CloneVT to avoid mutation. Pass pointers to functions
JoukoVirtanen Jul 15, 2025
66f1706
Renamed NilTimestampStr back to NilTimestamp. Created placeholderIP f…
JoukoVirtanen Jul 15, 2025
2e99de6
Reduced usage of CloneVT()
JoukoVirtanen Jul 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 68 additions & 66 deletions integration-tests/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"strings"
"testing"

sensorAPI "github.com/stackrox/rox/generated/internalapi/sensor"

"github.com/stretchr/testify/suite"

"github.com/stackrox/collector/integration-tests/pkg/collector"
Expand Down Expand Up @@ -166,13 +168,13 @@ func TestConnectionsAndEndpointsNormal(t *testing.T) {
Server: suites.Container{
Name: "socat-server-0",
Cmd: "socat TCP4-LISTEN:40,reuseaddr,fork - &",
ExpectedNetwork: []types.NetworkInfo{
ExpectedNetwork: []*sensorAPI.NetworkConnection{
{
LocalAddress: ":40",
RemoteAddress: "CLIENT_IP",
Role: "ROLE_SERVER",
SocketFamily: "SOCKET_FAMILY_UNKNOWN",
CloseTimestamp: types.NilTimestamp,
LocalAddress: types.CreateNetworkAddress("", "", 40),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's worth it here and in other similar cases to introduce a separate variable keeping the client port. This will explain why there is 40 here and few lines above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

RemoteAddress: types.CreateNetworkAddress("", "", 0),
Role: sensorAPI.ClientServerRole_ROLE_SERVER,
SocketFamily: sensorAPI.SocketFamily_SOCKET_FAMILY_UNKNOWN,
CloseTimestamp: nil,
},
},
ExpectedEndpoints: []types.EndpointInfo{
Expand All @@ -189,13 +191,13 @@ func TestConnectionsAndEndpointsNormal(t *testing.T) {
Client: suites.Container{
Name: "socat-client-0",
Cmd: "echo hello | socat - TCP4:SERVER_IP:40",
ExpectedNetwork: []types.NetworkInfo{
ExpectedNetwork: []*sensorAPI.NetworkConnection{
{
LocalAddress: "",
RemoteAddress: "SERVER_IP:40",
Role: "ROLE_CLIENT",
SocketFamily: "SOCKET_FAMILY_UNKNOWN",
CloseTimestamp: types.NilTimestamp,
LocalAddress: types.CreateNetworkAddress("", "", 0),
RemoteAddress: types.CreateNetworkAddress("", "", 40),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I understand the original implementation was replacing SERVER_IP with the real IP address. I see that it was done purely for testing, but maybe it makes sense to set the RemoteAddress here correctly as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The server IP is unknown at this point, and SERVER_IP can't be passed to CreateNetworkAddress. Instead RemoteAddress is set in the test suite. The value for the port is set here, but the value for the AddressData is overwritten in the test suite.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still find it could be better. Even if the RemoteAddress set somewhere later, it makes sense to have all the information about the test right here where it's defined.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am now using placeholderIP instead of empty quotes for the RemoteAddress field.

Role: sensorAPI.ClientServerRole_ROLE_CLIENT,
SocketFamily: sensorAPI.SocketFamily_SOCKET_FAMILY_UNKNOWN,
CloseTimestamp: nil,
},
},
ExpectedEndpoints: nil,
Expand All @@ -211,13 +213,13 @@ func TestConnectionsAndEndpointsHighLowPorts(t *testing.T) {
Server: suites.Container{
Name: "socat-server-1",
Cmd: "socat TCP4-LISTEN:40000,reuseaddr,fork - &",
ExpectedNetwork: []types.NetworkInfo{
ExpectedNetwork: []*sensorAPI.NetworkConnection{
{
LocalAddress: ":40000",
RemoteAddress: "CLIENT_IP",
Role: "ROLE_SERVER",
SocketFamily: "SOCKET_FAMILY_UNKNOWN",
CloseTimestamp: types.NilTimestamp,
LocalAddress: types.CreateNetworkAddress("", "", 40000),
RemoteAddress: types.CreateNetworkAddress("", "", 0),
Role: sensorAPI.ClientServerRole_ROLE_SERVER,
SocketFamily: sensorAPI.SocketFamily_SOCKET_FAMILY_UNKNOWN,
CloseTimestamp: nil,
},
},
ExpectedEndpoints: []types.EndpointInfo{
Expand All @@ -234,13 +236,13 @@ func TestConnectionsAndEndpointsHighLowPorts(t *testing.T) {
Client: suites.Container{
Name: "socat-client-1",
Cmd: "echo hello | socat - TCP4:SERVER_IP:40000,sourceport=10000",
ExpectedNetwork: []types.NetworkInfo{
ExpectedNetwork: []*sensorAPI.NetworkConnection{
{
LocalAddress: "",
RemoteAddress: "SERVER_IP:40000",
Role: "ROLE_CLIENT",
SocketFamily: "SOCKET_FAMILY_UNKNOWN",
CloseTimestamp: types.NilTimestamp,
LocalAddress: types.CreateNetworkAddress("", "", 0),
RemoteAddress: types.CreateNetworkAddress("", "", 40000),
Role: sensorAPI.ClientServerRole_ROLE_CLIENT,
SocketFamily: sensorAPI.SocketFamily_SOCKET_FAMILY_UNKNOWN,
CloseTimestamp: nil,
},
},
ExpectedEndpoints: nil,
Expand All @@ -256,13 +258,13 @@ func TestConnectionsAndEndpointsServerHigh(t *testing.T) {
Server: suites.Container{
Name: "socat-server-2",
Cmd: "socat TCP4-LISTEN:60999,reuseaddr,fork - &",
ExpectedNetwork: []types.NetworkInfo{
ExpectedNetwork: []*sensorAPI.NetworkConnection{
{
LocalAddress: ":60999",
RemoteAddress: "CLIENT_IP",
Role: "ROLE_SERVER",
SocketFamily: "SOCKET_FAMILY_UNKNOWN",
CloseTimestamp: types.NilTimestamp,
LocalAddress: types.CreateNetworkAddress("", "", 60999),
RemoteAddress: types.CreateNetworkAddress("", "", 0),
Role: sensorAPI.ClientServerRole_ROLE_SERVER,
SocketFamily: sensorAPI.SocketFamily_SOCKET_FAMILY_UNKNOWN,
CloseTimestamp: nil,
},
},
ExpectedEndpoints: []types.EndpointInfo{
Expand All @@ -279,13 +281,13 @@ func TestConnectionsAndEndpointsServerHigh(t *testing.T) {
Client: suites.Container{
Name: "socat-client-2",
Cmd: "echo hello | socat - TCP4:SERVER_IP:60999",
ExpectedNetwork: []types.NetworkInfo{
ExpectedNetwork: []*sensorAPI.NetworkConnection{
{
LocalAddress: "",
RemoteAddress: "SERVER_IP:60999",
Role: "ROLE_CLIENT",
SocketFamily: "SOCKET_FAMILY_UNKNOWN",
CloseTimestamp: types.NilTimestamp,
LocalAddress: types.CreateNetworkAddress("", "", 0),
RemoteAddress: types.CreateNetworkAddress("", "", 60999),
Role: sensorAPI.ClientServerRole_ROLE_CLIENT,
SocketFamily: sensorAPI.SocketFamily_SOCKET_FAMILY_UNKNOWN,
CloseTimestamp: nil,
},
},
ExpectedEndpoints: nil,
Expand All @@ -301,13 +303,13 @@ func TestConnectionsAndEndpointsSourcePort(t *testing.T) {
Server: suites.Container{
Name: "socat-server-1",
Cmd: "socat TCP4-LISTEN:10000,reuseaddr,fork - &",
ExpectedNetwork: []types.NetworkInfo{
ExpectedNetwork: []*sensorAPI.NetworkConnection{
{
LocalAddress: ":10000",
RemoteAddress: "CLIENT_IP",
Role: "ROLE_SERVER",
SocketFamily: "SOCKET_FAMILY_UNKNOWN",
CloseTimestamp: types.NilTimestamp,
LocalAddress: types.CreateNetworkAddress("", "", 10000),
RemoteAddress: types.CreateNetworkAddress("", "", 0),
Role: sensorAPI.ClientServerRole_ROLE_SERVER,
SocketFamily: sensorAPI.SocketFamily_SOCKET_FAMILY_UNKNOWN,
CloseTimestamp: nil,
},
},
ExpectedEndpoints: []types.EndpointInfo{
Expand All @@ -324,13 +326,13 @@ func TestConnectionsAndEndpointsSourcePort(t *testing.T) {
Client: suites.Container{
Name: "socat-client-1",
Cmd: "echo hello | socat - TCP4:SERVER_IP:10000,sourceport=40000",
ExpectedNetwork: []types.NetworkInfo{
ExpectedNetwork: []*sensorAPI.NetworkConnection{
{
LocalAddress: "",
RemoteAddress: "SERVER_IP:10000",
Role: "ROLE_CLIENT",
SocketFamily: "SOCKET_FAMILY_UNKNOWN",
CloseTimestamp: types.NilTimestamp,
LocalAddress: types.CreateNetworkAddress("", "", 0),
RemoteAddress: types.CreateNetworkAddress("", "", 10000),
Role: sensorAPI.ClientServerRole_ROLE_CLIENT,
SocketFamily: sensorAPI.SocketFamily_SOCKET_FAMILY_UNKNOWN,
CloseTimestamp: nil,
},
},
ExpectedEndpoints: nil,
Expand Down Expand Up @@ -362,13 +364,13 @@ func TestConnectionsAndEndpointsUDPNormal(t *testing.T) {
Client: suites.Container{
Name: "socat-client-udp",
Cmd: "echo hello | socat - UDP:SERVER_IP:53",
ExpectedNetwork: []types.NetworkInfo{
ExpectedNetwork: []*sensorAPI.NetworkConnection{
{
LocalAddress: "",
RemoteAddress: "SERVER_IP:53",
Role: "ROLE_CLIENT",
SocketFamily: "SOCKET_FAMILY_UNKNOWN",
CloseTimestamp: types.NilTimestamp,
LocalAddress: types.CreateNetworkAddress("", "", 0),
RemoteAddress: types.CreateNetworkAddress("", "", 53),
Role: sensorAPI.ClientServerRole_ROLE_CLIENT,
SocketFamily: sensorAPI.SocketFamily_SOCKET_FAMILY_UNKNOWN,
CloseTimestamp: nil,
},
},
ExpectedEndpoints: nil,
Expand Down Expand Up @@ -400,13 +402,13 @@ func TestConnectionsAndEndpointsUDPNoReuseaddr(t *testing.T) {
Client: suites.Container{
Name: "socat-client-udp",
Cmd: "echo hello | socat - UDP:SERVER_IP:53",
ExpectedNetwork: []types.NetworkInfo{
ExpectedNetwork: []*sensorAPI.NetworkConnection{
{
LocalAddress: "",
RemoteAddress: "SERVER_IP:53",
Role: "ROLE_CLIENT",
SocketFamily: "SOCKET_FAMILY_UNKNOWN",
CloseTimestamp: types.NilTimestamp,
LocalAddress: types.CreateNetworkAddress("", "", 0),
RemoteAddress: types.CreateNetworkAddress("", "", 53),
Role: sensorAPI.ClientServerRole_ROLE_CLIENT,
SocketFamily: sensorAPI.SocketFamily_SOCKET_FAMILY_UNKNOWN,
CloseTimestamp: nil,
},
},
ExpectedEndpoints: nil,
Expand Down Expand Up @@ -438,13 +440,13 @@ func TestConnectionsAndEndpointsUDPNoFork(t *testing.T) {
Client: suites.Container{
Name: "socat-client-udp",
Cmd: "echo hello | socat - UDP:SERVER_IP:53",
ExpectedNetwork: []types.NetworkInfo{
ExpectedNetwork: []*sensorAPI.NetworkConnection{
{
LocalAddress: "",
RemoteAddress: "SERVER_IP:53",
Role: "ROLE_CLIENT",
SocketFamily: "SOCKET_FAMILY_UNKNOWN",
CloseTimestamp: types.NilTimestamp,
LocalAddress: types.CreateNetworkAddress("", "", 0),
RemoteAddress: types.CreateNetworkAddress("", "", 53),
Role: sensorAPI.ClientServerRole_ROLE_CLIENT,
SocketFamily: sensorAPI.SocketFamily_SOCKET_FAMILY_UNKNOWN,
CloseTimestamp: nil,
},
},
ExpectedEndpoints: nil,
Expand Down
26 changes: 14 additions & 12 deletions integration-tests/pkg/mock_sensor/expect_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@ import (

collectorAssert "github.com/stackrox/collector/integration-tests/pkg/assert"
"github.com/stackrox/collector/integration-tests/pkg/types"

sensorAPI "github.com/stackrox/rox/generated/internalapi/sensor"
)

// ExpectConnections waits up to the timeout for the gRPC server to receive
// the list of expected Connections. It will first check to see if the connections
// have been received already, and then monitor the live feed of connections
// until timeout or until all the events have been received.
func (s *MockSensor) ExpectConnections(t *testing.T, containerID string, timeout time.Duration, expected ...types.NetworkInfo) bool {
func (s *MockSensor) ExpectConnections(t *testing.T, containerID string, timeout time.Duration, expected ...*sensorAPI.NetworkConnection) bool {

to_find := funk.Filter(expected, func(x types.NetworkInfo) bool {
to_find := funk.Filter(expected, func(x *sensorAPI.NetworkConnection) bool {
return !s.HasConnection(containerID, x)
}).([]types.NetworkInfo)
}).([]*sensorAPI.NetworkConnection)

if len(to_find) == 0 {
return true
Expand All @@ -39,9 +41,9 @@ loop:
continue loop
}

to_find = funk.Filter(expected, func(x types.NetworkInfo) bool {
to_find = funk.Filter(expected, func(x *sensorAPI.NetworkConnection) bool {
return !s.HasConnection(containerID, x)
}).([]types.NetworkInfo)
}).([]*sensorAPI.NetworkConnection)

if len(to_find) == 0 {
return true
Expand All @@ -57,7 +59,7 @@ loop:
//
// It does not consider the content of the events, just that a certain number
// have been received
func (s *MockSensor) ExpectConnectionsN(t *testing.T, containerID string, timeout time.Duration, n int) []types.NetworkInfo {
func (s *MockSensor) ExpectConnectionsN(t *testing.T, containerID string, timeout time.Duration, n int) []*sensorAPI.NetworkConnection {
if len(s.Connections(containerID)) == n {
return s.Connections(containerID)
}
Expand All @@ -82,11 +84,11 @@ loop:
// ExpectSameElementsConnections compares a list of expected connections to the observed connections. This comparison is done at the beginning, when a new
// connection arrives, and after a timeout period. The number of connections must match and the expected and observed connections must match, but the order
// does not matter.
func (s *MockSensor) ExpectSameElementsConnections(t *testing.T, containerID string, timeout time.Duration, expected ...types.NetworkInfo) bool {
func (s *MockSensor) ExpectSameElementsConnections(t *testing.T, containerID string, timeout time.Duration, expected ...*sensorAPI.NetworkConnection) bool {
types.SortConnections(expected)

equal := func(c1, c2 types.NetworkInfo) bool {
return c1.Equal(c2)
equal := func(c1, c2 *sensorAPI.NetworkConnection) bool {
return types.EqualNetworkConnection(*c1, *c2)
}

connections := s.Connections(containerID)
Expand All @@ -113,8 +115,8 @@ func (s *MockSensor) ExpectSameElementsConnections(t *testing.T, containerID str
}
}

func (s *MockSensor) ExpectSameElementsConnectionsScrapes(t *testing.T, containerID string, timeout time.Duration, expected []types.NetworkInfoBatch) bool {
equal := func(c1, c2 types.NetworkInfoBatch) bool {
func (s *MockSensor) ExpectSameElementsConnectionsScrapes(t *testing.T, containerID string, timeout time.Duration, expected []types.NetworkConnectionBatch) bool {
equal := func(c1, c2 types.NetworkConnectionBatch) bool {
if len(c1) != len(c2) {
return false
}
Expand All @@ -123,7 +125,7 @@ func (s *MockSensor) ExpectSameElementsConnectionsScrapes(t *testing.T, containe
types.SortConnections(c2)

for i := range c2 {
if !c1[i].Equal(c2[i]) {
if !types.EqualNetworkConnection(*c1[i], *c2[i]) {
return false
}
}
Expand Down
Loading
Loading