Skip to content

Commit

Permalink
Rename detailed_networks to non_aggregated_networks
Browse files Browse the repository at this point in the history
  • Loading branch information
ovalenti committed Jul 4, 2024
1 parent b19de33 commit b7961b6
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 15 deletions.
10 changes: 5 additions & 5 deletions collector/lib/CollectorConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ BoolEnvVar network_drop_ignored("ROX_NETWORK_DROP_IGNORED", true);
StringListEnvVar ignored_networks("ROX_IGNORE_NETWORKS", std::vector<std::string>({"169.254.0.0/16", "fe80::/10"}));

// Connection endpoints matching a network prefix listed here will never be aggregated.
StringListEnvVar detailed_networks("ROX_DETAIL_NETWORKS", std::vector<std::string>());
StringListEnvVar non_aggregated_networks("ROX_NON_AGGREGATED_NETWORKS", std::vector<std::string>());

// If true, set curl to be verbose, adding further logging that might be useful for debugging.
BoolEnvVar set_curl_verbose("ROX_COLLECTOR_SET_CURL_VERBOSE", false);
Expand Down Expand Up @@ -188,18 +188,18 @@ void CollectorConfig::InitCollectorConfig(CollectorArgs* args) {
}
});

std::for_each(detailed_networks.value().begin(), detailed_networks.value().end(),
[&detailed_networks = this->detailed_networks_](const std::string& str) {
std::for_each(non_aggregated_networks.value().begin(), non_aggregated_networks.value().end(),
[&non_aggregated_networks = this->non_aggregated_networks_](const std::string& str) {
if (str.empty())
return;

std::optional<IPNet> net = IPNet::parse(str);

if (net) {
CLOG(INFO) << "Detail network : " << *net;
detailed_networks.emplace_back(std::move(*net));
non_aggregated_networks.emplace_back(std::move(*net));
} else {
CLOG(ERROR) << "Invalid network in ROX_DETAIL_NETWORKS : " << str;
CLOG(ERROR) << "Invalid network in ROX_NON_AGGREGATED_NETWORKS : " << str;
}
});

Expand Down
4 changes: 2 additions & 2 deletions collector/lib/CollectorConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class CollectorConfig {
bool DisableNetworkFlows() const { return disable_network_flows_; }
const UnorderedSet<L4ProtoPortPair>& IgnoredL4ProtoPortPairs() const { return ignored_l4proto_port_pairs_; }
const std::vector<IPNet>& IgnoredNetworks() const { return ignored_networks_; }
const std::vector<IPNet>& DetailedNetworks() const { return detailed_networks_; }
const std::vector<IPNet>& NonAggregatedNetworks() const { return non_aggregated_networks_; }
bool CurlVerbose() const { return curl_verbose_; }
bool EnableAfterglow() const { return enable_afterglow_; }
bool IsCoreDumpEnabled() const;
Expand Down Expand Up @@ -101,7 +101,7 @@ class CollectorConfig {
bool scrape_listen_endpoints_ = false;
UnorderedSet<L4ProtoPortPair> ignored_l4proto_port_pairs_;
std::vector<IPNet> ignored_networks_;
std::vector<IPNet> detailed_networks_;
std::vector<IPNet> non_aggregated_networks_;
bool curl_verbose_ = false;

HostConfig host_config_;
Expand Down
2 changes: 1 addition & 1 deletion collector/lib/CollectorService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ void CollectorService::RunForever() {
UnorderedSet<L4ProtoPortPair> ignored_l4proto_port_pairs(config_.IgnoredL4ProtoPortPairs());
conn_tracker->UpdateIgnoredL4ProtoPortPairs(std::move(ignored_l4proto_port_pairs));
conn_tracker->UpdateIgnoredNetworks(config_.IgnoredNetworks());
conn_tracker->UpdateDetailedNetworks(config_.DetailedNetworks());
conn_tracker->UpdateNonAggregatedNetworks(config_.NonAggregatedNetworks());
conn_tracker->EnableExternalIPs(config_.EnableExternalIPs());

auto network_connection_info_service_comm = std::make_shared<NetworkConnectionInfoServiceComm>(config_.Hostname(), config_.grpc_channel);
Expand Down
6 changes: 3 additions & 3 deletions collector/lib/ConnTracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ IPNet ConnectionTracker::NormalizeAddressNoLock(const Address& address) const {
}

// We want to keep private addresses and explicitely requested ones.
bool keep_addr = !address.IsPublic() || !detailed_networks_.Find(address).IsNull();
bool keep_addr = !address.IsPublic() || !non_aggregated_networks_.Find(address).IsNull();
const bool* known_private_networks_exists = Lookup(known_private_networks_exists_, address.family());
if (keep_addr && (known_private_networks_exists && !*known_private_networks_exists)) {
return IPNet(address, 0, true);
Expand Down Expand Up @@ -330,9 +330,9 @@ void ConnectionTracker::UpdateIgnoredNetworks(const std::vector<IPNet>& network_
}
}

void ConnectionTracker::UpdateDetailedNetworks(const std::vector<IPNet>& network_list) {
void ConnectionTracker::UpdateNonAggregatedNetworks(const std::vector<IPNet>& network_list) {
WITH_LOCK(mutex_) {
detailed_networks_ = NRadixTree(network_list);
non_aggregated_networks_ = NRadixTree(network_list);
}
}

Expand Down
4 changes: 2 additions & 2 deletions collector/lib/ConnTracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class ConnectionTracker {
void EnableExternalIPs(bool enable) { enable_external_ips_ = enable; }
void UpdateIgnoredL4ProtoPortPairs(UnorderedSet<L4ProtoPortPair>&& ignored_l4proto_port_pairs);
void UpdateIgnoredNetworks(const std::vector<IPNet>& network_list);
void UpdateDetailedNetworks(const std::vector<IPNet>& network_list);
void UpdateNonAggregatedNetworks(const std::vector<IPNet>& network_list);

// Emplace a connection into the state ConnMap, or update its timestamp if the supplied timestamp is more recent
// than the stored one.
Expand Down Expand Up @@ -201,7 +201,7 @@ class ConnectionTracker {
UnorderedMap<Address::Family, bool> known_private_networks_exists_;
UnorderedSet<L4ProtoPortPair> ignored_l4proto_port_pairs_;
NRadixTree ignored_networks_;
NRadixTree detailed_networks_;
NRadixTree non_aggregated_networks_;

Stats inserted_connections_counters_ = {};
};
Expand Down
4 changes: 2 additions & 2 deletions collector/test/ConnTrackerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ TEST(ConnTrackerTest, TestUpdateIgnoredNetworks) {
EXPECT_TRUE(tracker.FetchConnState().empty());
}

TEST(ConnTrackerTest, TestUpdateDetailedNetworks) {
TEST(ConnTrackerTest, TestUpdateNonAggregatedNetworks) {
Endpoint a(Address(192, 168, 1, 10), 9999);
Endpoint b(Address(245, 1, 1, 1), 80);

Expand All @@ -189,7 +189,7 @@ TEST(ConnTrackerTest, TestUpdateDetailedNetworks) {
auto state = tracker.FetchConnState(true);
EXPECT_THAT(state, UnorderedElementsAre(std::make_pair(conn_aggregated, ConnStatus(time_micros, true))));

tracker.UpdateDetailedNetworks({IPNet(Address(240, 0, 0, 0), 4)});
tracker.UpdateNonAggregatedNetworks({IPNet(Address(240, 0, 0, 0), 4)});

state = tracker.FetchConnState(true);
EXPECT_THAT(state, UnorderedElementsAre(std::make_pair(conn_detailed, ConnStatus(time_micros, true))));
Expand Down

0 comments on commit b7961b6

Please sign in to comment.