Skip to content

Commit a6927e3

Browse files
committed
Print configuration as yaml for ease of debuggability
1 parent 34b6da9 commit a6927e3

File tree

1 file changed

+80
-12
lines changed

1 file changed

+80
-12
lines changed

collector/lib/CollectorConfig.cpp

Lines changed: 80 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include <filesystem>
44
#include <optional>
5+
#include <sstream>
56

67
#include <libsinsp/sinsp.h>
78

@@ -256,7 +257,7 @@ void CollectorConfig::HandleTls(const Json::Value& config, const CollectorArgs*
256257
}
257258

258259
void CollectorConfig::HandleNetworkConfig() {
259-
auto filler = [](std::vector<IPNet>& output, const std::vector<std::string>& input, const std::string& error_message, const std::string& notification_message) {
260+
auto filler = [](std::vector<IPNet>& output, const std::vector<std::string>& input, const std::string& notification_message, const std::string& error_message) {
260261
for (const std::string& str : input) {
261262
if (str.empty()) {
262263
continue;
@@ -387,19 +388,86 @@ std::string CollectorConfig::LogLevel() {
387388
return logging::GetLogLevelName(logging::GetLogLevel());
388389
}
389390

391+
namespace {
392+
393+
template <typename T>
394+
std::string VectorToYamlList(const std::vector<T>& v, size_t indent_level, bool compressed = false) {
395+
std::stringstream ss;
396+
if (compressed) {
397+
bool first = true;
398+
ss << "[ ";
399+
400+
for (const auto& item : v) {
401+
if (first) {
402+
first = false;
403+
} else {
404+
ss << ", ";
405+
}
406+
407+
ss << '"' << item << '"';
408+
}
409+
410+
ss << " ]";
411+
} else {
412+
std::string indent(indent_level * 2, ' ');
413+
for (const auto& item : v) {
414+
ss << indent << "- " << item << '\n';
415+
}
416+
}
417+
return ss.str();
418+
}
419+
420+
std::string UnorderedSetToYamlList(const UnorderedSet<L4ProtoPortPair>& p, size_t indent_level) {
421+
std::stringstream ss;
422+
std::string indent(indent_level * 2, ' ');
423+
for (const auto& [k, v] : p) {
424+
ss << indent << k << ": " << v << '\n';
425+
}
426+
return ss.str();
427+
}
428+
429+
} // namespace
430+
390431
std::ostream& operator<<(std::ostream& os, const CollectorConfig& c) {
391432
return os
392-
<< "collection_method:" << c.GetCollectionMethod()
393-
<< ", scrape_interval:" << c.ScrapeInterval()
394-
<< ", turn_off_scrape:" << c.TurnOffScrape()
395-
<< ", hostname:" << c.Hostname()
396-
<< ", processesListeningOnPorts:" << c.IsProcessesListeningOnPortsEnabled()
397-
<< ", logLevel:" << CollectorConfig::LogLevel()
398-
<< ", set_import_users:" << c.ImportUsers()
399-
<< ", collect_connection_status:" << c.CollectConnectionStatus()
400-
<< ", enable_detailed_metrics:" << c.EnableDetailedMetrics()
401-
<< ", enable_external_ips:" << c.EnableExternalIPs()
402-
<< ", track_send_recv:" << c.TrackingSendRecv();
433+
<< std::boolalpha << "\n"
434+
<< " collection_method: " << c.GetCollectionMethod() << "\n"
435+
<< " scrape_interval: " << c.ScrapeInterval() << "\n"
436+
<< " turn_off_scrape: " << c.TurnOffScrape() << "\n"
437+
<< " scrape_listen_endpoints: " << c.ScrapeListenEndpoints() << "\n"
438+
<< " syscalls: " << VectorToYamlList(c.Syscalls(), 1, true) << "\n"
439+
<< " hostname: " << c.Hostname() << "\n"
440+
<< " disable_network_flows: " << c.DisableNetworkFlows() << "\n"
441+
<< " ignored_l4proto_port_pairs: \n"
442+
<< UnorderedSetToYamlList(c.IgnoredL4ProtoPortPairs(), 2)
443+
<< " ignored_networks: \n"
444+
<< VectorToYamlList(c.IgnoredNetworks(), 1)
445+
<< " non_aggregated_networks: \n"
446+
<< VectorToYamlList(c.NonAggregatedNetworks(), 1)
447+
<< " enable_afterglow: " << c.EnableAfterglow() << "\n"
448+
<< " afterglow_period_micros: " << c.AfterglowPeriod() << "\n"
449+
<< " enable_core_dump: " << c.IsCoreDumpEnabled() << "\n"
450+
<< " processesListeningOnPorts: " << c.IsProcessesListeningOnPortsEnabled() << "\n"
451+
<< " logLevel: " << CollectorConfig::LogLevel() << "\n"
452+
<< " set_import_users: " << c.ImportUsers() << "\n"
453+
<< " collect_connection_status: " << c.CollectConnectionStatus() << "\n"
454+
<< " enable_detailed_metrics: " << c.EnableDetailedMetrics() << "\n"
455+
<< " enable_runtime_config: " << c.EnableRuntimeConfig() << "\n"
456+
<< " use_docker_ce: " << c.UseDockerCe() << "\n"
457+
<< " use_podman_ce: " << c.UsePodmanCe() << "\n"
458+
<< " enable_introspection: " << c.IsIntrospectionEnabled() << "\n"
459+
<< " enable_external_ips: " << c.EnableExternalIPs() << "\n"
460+
<< " track_send_recv: " << c.TrackingSendRecv() << "\n"
461+
<< " connection_stats:\n"
462+
<< " error: " << c.GetConnectionStatsError() << "\n"
463+
<< " window: " << c.GetConnectionStatsWindow() << "\n"
464+
<< " quantiles:\n"
465+
<< VectorToYamlList(c.GetConnectionStatsQuantiles(), 2)
466+
<< " system_inspector:\n"
467+
<< " cpu_buffer_size: " << c.GetSinspCpuPerBuffer() << "\n"
468+
<< " buffer_size: " << c.GetSinspBufferSize() << "\n"
469+
<< " total_buffer_size: " << c.GetSinspTotalBufferSize() << "\n"
470+
<< " thread_cache_size: " << c.GetSinspThreadCacheSize() << "\n";
403471
}
404472

405473
// Returns size of ring buffers to be allocated.

0 commit comments

Comments
 (0)