Skip to content

Ignore inactive connections #2029

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions integration-tests/pkg/mock_sensor/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ func (m *MockSensor) Connections(containerID string) []types.NetworkInfo {
if connections, ok := m.connections[containerID]; ok {
conns := make([]types.NetworkInfo, len(connections))
copy(conns, connections)

// Ignore all in-flight connections
conns = types.GetActiveConnections(conns)
types.SortConnections(conns)
return conns
}
Expand Down
18 changes: 18 additions & 0 deletions integration-tests/pkg/types/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,21 @@ func (n *NetworkInfo) Less(other NetworkInfo) bool {
func SortConnections(connections []NetworkInfo) {
sort.Slice(connections, func(i, j int) bool { return connections[i].Less(connections[j]) })
}

// GetActiveConnections - return only active out of the pool of all observed
// connections.
//
// If we observe an "in-flight" connection without a closed timestamp,
// sometimes it makes sense to ignore it as we will get it later with full
// information.
func GetActiveConnections(connections []NetworkInfo) []NetworkInfo {
result := []NetworkInfo{}

for _, c := range connections {
if c.IsActive() {
result = append(result, c)
}
}

return result
}
Loading