Skip to content

Commit

Permalink
Start tracking recvmmsg and sendmmsg in order to fully support OCP Virt
Browse files Browse the repository at this point in the history
  • Loading branch information
Molter73 committed Sep 10, 2024
1 parent 88fb9ee commit 1bd8abd
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 4 deletions.
14 changes: 12 additions & 2 deletions collector/lib/CollectorConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ BoolEnvVar use_podman_ce("ROX_COLLECTOR_CE_USE_PODMAN", false);

BoolEnvVar enable_introspection("ROX_COLLECTOR_INTROSPECTION_ENABLE", false);

BoolEnvVar track_send_recv("ROX_COLLECTOR_TRACK_SEND_RECV", false);

// Collector arguments alternatives
StringEnvVar log_level("ROX_COLLECTOR_LOG_LEVEL");
IntEnvVar scrape_interval("ROX_COLLECTOR_SCRAPE_INTERVAL");
Expand Down Expand Up @@ -103,9 +105,16 @@ void CollectorConfig::InitCollectorConfig(CollectorArgs* args) {
use_docker_ce_ = use_docker_ce.value();
use_podman_ce_ = use_podman_ce.value();
enable_introspection_ = enable_introspection.value();
track_send_recv_ = track_send_recv.value();

for (const auto& syscall : kSyscalls) {
syscalls_.push_back(syscall);
syscalls_.emplace_back(syscall);
}

if (track_send_recv_) {
for (const auto& syscall : kSendRecvSyscalls) {
syscalls_.emplace_back(syscall);
}
}

// Get hostname
Expand Down Expand Up @@ -452,7 +461,8 @@ std::ostream& operator<<(std::ostream& os, const CollectorConfig& c) {
<< ", set_import_users:" << c.ImportUsers()
<< ", collect_connection_status:" << c.CollectConnectionStatus()
<< ", enable_detailed_metrics:" << c.EnableDetailedMetrics()
<< ", enable_external_ips:" << c.EnableExternalIPs();
<< ", enable_external_ips:" << c.EnableExternalIPs()
<< ", track_send_recv:" << c.TrackingSendRecv();
}

// Returns size of ring buffers to be allocated.
Expand Down
10 changes: 10 additions & 0 deletions collector/lib/CollectorConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ class CollectorConfig {
#endif
"vfork",
};
static constexpr const char* kSendRecvSyscalls[] = {
"sendto",
"sendmsg",
"sendmmsg",
"recvfrom",
"recvmsg",
"recvmmsg",
};
static const UnorderedSet<L4ProtoPortPair> kIgnoredL4ProtoPortPairs;
static constexpr bool kEnableProcessesListeningOnPorts = true;

Expand Down Expand Up @@ -82,6 +90,7 @@ class CollectorConfig {
bool UseDockerCe() const { return use_docker_ce_; }
bool UsePodmanCe() const { return use_podman_ce_; }
bool IsIntrospectionEnabled() const { return enable_introspection_; }
bool TrackingSendRecv() const { return track_send_recv_; }
const std::vector<double>& GetConnectionStatsQuantiles() const { return connection_stats_quantiles_; }
double GetConnectionStatsError() const { return connection_stats_error_; }
unsigned int GetConnectionStatsWindow() const { return connection_stats_window_; }
Expand Down Expand Up @@ -122,6 +131,7 @@ class CollectorConfig {
bool use_docker_ce_;
bool use_podman_ce_;
bool enable_introspection_;
bool track_send_recv_;
std::vector<double> connection_stats_quantiles_;
double connection_stats_error_;
unsigned int connection_stats_window_;
Expand Down
36 changes: 35 additions & 1 deletion collector/lib/NetworkSignalHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,25 @@ EventMap<Modifier> modifiers = {
{"connect<", Modifier::ADD},
{"accept<", Modifier::ADD},
{"getsockopt<", Modifier::ADD},
{"sendto<", Modifier::ADD},
{"sendto>", Modifier::ADD},
{"sendmsg<", Modifier::ADD},
{"sendmsg>", Modifier::ADD},
{"sendmmsg<", Modifier::ADD},
{"recvfrom<", Modifier::ADD},
{"recvfrom>", Modifier::ADD},
{"recvmsg<", Modifier::ADD},
{"recvmsg>", Modifier::ADD},
{"recvmmsg<", Modifier::ADD},
{"recvmmsg>", Modifier::ADD},
},
Modifier::INVALID,
};

} // namespace

NetworkSignalHandler::NetworkSignalHandler(sinsp* inspector, std::shared_ptr<ConnectionTracker> conn_tracker, system_inspector::Stats* stats)
: event_extractor_(std::make_unique<system_inspector::EventExtractor>()), conn_tracker_(std::move(conn_tracker)), stats_(stats), collect_connection_status_(true) {
: event_extractor_(std::make_unique<system_inspector::EventExtractor>()), conn_tracker_(std::move(conn_tracker)), stats_(stats), collect_connection_status_(true), track_send_recv_(false) {
event_extractor_->Init(inspector);
}

Expand Down Expand Up @@ -118,6 +129,7 @@ std::optional<Connection> NetworkSignalHandler::GetConnection(sinsp_evt* evt) {

const std::string* container_id = event_extractor_->get_container_id(evt);
if (!container_id) return std::nullopt;

return {Connection(*container_id, *local, *remote, l4proto, is_server)};
}

Expand All @@ -135,6 +147,28 @@ SignalHandler::Result NetworkSignalHandler::HandleSignal(sinsp_evt* evt) {
}

std::vector<std::string> NetworkSignalHandler::GetRelevantEvents() {
if (track_send_recv_) {
return {
"close<",
"shutdown<",
"connect<",
"accept<",
"getsockopt<",
"sendto<",
"sendto>",
"sendmsg<",
"sendmsg>",
"sendmmsg<",
"recvfrom<",
"recvfrom>",
"recvmsg<",
"recvmsg>",
"recvmmsg<",
"recvmmsg>",
"recvmsg<",
"recvmsg>",
};
}
return {"close<", "shutdown<", "connect<", "accept<", "getsockopt<"};
}

Expand Down
2 changes: 2 additions & 0 deletions collector/lib/NetworkSignalHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class NetworkSignalHandler final : public SignalHandler {
bool Stop() override;

void SetCollectConnectionStatus(bool collect_connection_status) { collect_connection_status_ = collect_connection_status; }
void SetTrackSendRecv(bool track_send_recv) { track_send_recv_ = track_send_recv; }

private:
std::optional<Connection> GetConnection(sinsp_evt* evt);
Expand All @@ -38,6 +39,7 @@ class NetworkSignalHandler final : public SignalHandler {
system_inspector::Stats* stats_;

bool collect_connection_status_;
bool track_send_recv_;
};

} // namespace collector
Expand Down
1 change: 1 addition & 0 deletions collector/lib/system-inspector/Service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ void Service::Init(const CollectorConfig& config, std::shared_ptr<ConnectionTrac
auto network_signal_handler_ = MakeUnique<NetworkSignalHandler>(inspector_.get(), conn_tracker, &userspace_stats_);

network_signal_handler_->SetCollectConnectionStatus(config.CollectConnectionStatus());
network_signal_handler_->SetTrackSendRecv(config.TrackingSendRecv());

AddSignalHandler(std::move(network_signal_handler_));
}
Expand Down

0 comments on commit 1bd8abd

Please sign in to comment.