Skip to content

Commit

Permalink
Made changes needed for ConfigLoader
Browse files Browse the repository at this point in the history
  • Loading branch information
JoukoVirtanen committed Jan 11, 2025
1 parent e63b372 commit 60640e4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
20 changes: 16 additions & 4 deletions collector/lib/ConfigLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,28 @@ bool ConfigLoader::LoadConfiguration(CollectorConfig& config, const YAML::Node&
return true;
}

bool enable_external_ips = external_ips_node["enable"].as<bool>(false);
int64_t per_container_rate_limit = networking_node["perContainerRateLimit"].as<int64_t>(1024);
sensor::ExternalIpsEnabled enable_external_ips;
const std::string enabled_value = external_ips_node["enabled"] ? external_ips_node["enabled"].as<std::string>() : "";
std::string enabled_value_lower = enabled_value;
std::transform(enabled_value_lower.begin(), enabled_value_lower.end(), enabled_value_lower.begin(), ::tolower);

if (enabled_value_lower == "enabled") {
enable_external_ips = sensor::ExternalIpsEnabled::ENABLED;
} else if (enabled_value_lower == "disabled") {
enable_external_ips = sensor::ExternalIpsEnabled::DISABLED;
} else {
CLOG(ERROR) << "Unknown value for for networking.externalIps.enabled. Setting it to DISABLED";
enable_external_ips = sensor::ExternalIpsEnabled::DISABLED;
}
int64_t max_connections_per_minute = networking_node["maxConnectionsPerMinute"].as<int64_t>(1024);

sensor::CollectorConfig runtime_config;
auto* networking = runtime_config.mutable_networking();
networking
->mutable_external_ips()
->set_enable(enable_external_ips);
->set_enabled(enable_external_ips);
networking
->set_per_container_rate_limit(per_container_rate_limit);
->set_max_connections_per_minute(max_connections_per_minute);

config.SetRuntimeConfig(std::move(runtime_config));

Expand Down
10 changes: 2 additions & 8 deletions collector/test/ConfigLoaderTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,6 @@ TEST(CollectorConfigTest, TestYamlConfigToConfigEmptyOrMalformed) {
R"(
asdf
)",
R"(
networking:
externalIps:
enabled: DISABLED
maxConnectionsPerMinute: invalid
)",
R"()"};

for (const auto& yamlStr : tests) {
Expand Down Expand Up @@ -109,8 +103,8 @@ TEST(CollectorConfigTest, TestPerContainerRateLimit) {
{R"(
networking:
externalIps:
enabled: false
perContainerRateLimit: invalid
enabled: DISABLED
maxConnectionsPerMinute: invalid
)",
1024},
};
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/suites/runtime_config_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func (s *RuntimeConfigFileTestSuite) TestRuntimeConfigFileEnable() {
// External IPs enabled.
// Normalized connection must be reported as inactive
// Unnormalized connection will now be reported.
s.setExternalIpsEnabled(runtimeConfigFile, "enabled")
s.setExternalIpsEnabled(runtimeConfigFile, "ENABLED")
assert.AssertExternalIps(s.T(), "ENABLED", collectorIP)
expectedConnections = append(expectedConnections, activeUnnormalizedConnection, inactiveNormalizedConnection)
connectionSuccess = s.Sensor().ExpectSameElementsConnections(s.T(), s.ClientContainer, 10*time.Second, expectedConnections...)
Expand Down

0 comments on commit 60640e4

Please sign in to comment.