Skip to content

Commit

Permalink
wsd: dump the config
Browse files Browse the repository at this point in the history
This dumps the non-default config entries
at startup as well as using SIGUSR1.

Should help capture config values that
affect the functionality and behavior
that are relevant to troubleshooting.

Change-Id: I8e17d63828faae05bd613616493ae4f493760170
Signed-off-by: Ashod Nakashian <[email protected]>
  • Loading branch information
Ashod authored and caolanm committed Nov 6, 2024
1 parent e80f8ba commit d7fae37
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 8 deletions.
45 changes: 45 additions & 0 deletions common/ConfigUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,51 @@ bool isInitialized()
return Config;
}

/// Recursively extract the sub-keys of the given parent key.
void extract(const std::string& parentKey, const Poco::Util::AbstractConfiguration* config,
std::map<std::string, std::string>& map)
{
std::vector<std::string> keys;
config->keys(parentKey, keys);
for (const auto& subKey : keys)
{
const auto key = parentKey + '.' + subKey;
if (config->has(key))
{
map.emplace(key, config->getString(key));
extract(key, config, map);
}
}
}

std::map<std::string, std::string> extractAll(const Poco::Util::AbstractConfiguration* config)
{
std::map<std::string, std::string> map;

std::vector<std::string> keys;
config->keys(keys);
for (const auto& key : keys)
{
if (config->has(key))
{
extract(key, config, map);
}
}

// These keys have no values, but Poco gives us the values of
// their children concatenated, which is worse than useless.
// E.g. logging.file: /tmp/coolwsd.lognevertimestamptrue10 days10truefalse
map.erase("admin_console.logging");
map.erase("logging.anonymize");
map.erase("logging.file");
map.erase("net.lok_allow");
map.erase("net.post_allow");
map.erase("per_document.cleanup");
map.erase("ssl.sts");

return map;
}

std::string getString(const std::string& key, const std::string& def)
{
assert(Config && "Config is not initialized.");
Expand Down
4 changes: 4 additions & 0 deletions common/ConfigUtil.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <Util.hpp>

#include <string>
#include <map>

namespace ConfigUtil
{
Expand All @@ -35,6 +36,9 @@ void initialize(const Poco::Util::AbstractConfiguration* config);
/// Check if the config has been initialized
bool isInitialized();

/// Extract all entries as key-value pairs. We use map to have the entries sorted.
std::map<std::string, std::string> extractAll(const Poco::Util::AbstractConfiguration* config);

/// Returns the value of an entry as string or @def if it is not found.
std::string getString(const std::string& key, const std::string& def);

Expand Down
33 changes: 25 additions & 8 deletions wsd/COOLWSD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ static std::atomic<int> OutstandingForks(0);
std::map<std::string, std::shared_ptr<DocumentBroker>> DocBrokers;
std::mutex DocBrokersMutex;
static Poco::AutoPtr<Poco::Util::XMLConfiguration> KitXmlConfig;
static std::string LoggableConfigEntries;

extern "C"
{
Expand Down Expand Up @@ -2061,18 +2062,18 @@ void COOLWSD::innerInitialize(Poco::Util::Application& self)
{ "logging.file.property[0][@name]", "path" },
{ "logging.file.property[1]", "never" },
{ "logging.file.property[1][@name]", "rotation" },
{ "logging.file.property[2]", "true" },
{ "logging.file.property[2][@name]", "compress" },
{ "logging.file.property[3]", "false" },
{ "logging.file.property[3][@name]", "flush" },
{ "logging.file.property[2]", "false" },
{ "logging.file.property[2][@name]", "archive" },
{ "logging.file.property[3]", "true" },
{ "logging.file.property[3][@name]", "compress" },
{ "logging.file.property[4]", "10 days" },
{ "logging.file.property[4][@name]", "purgeAge" },
{ "logging.file.property[5]", "10" },
{ "logging.file.property[5][@name]", "purgeCount" },
{ "logging.file.property[6]", "true" },
{ "logging.file.property[6][@name]", "rotateOnOpen" },
{ "logging.file.property[7]", "false" },
{ "logging.file.property[7][@name]", "archive" },
{ "logging.file.property[7][@name]", "flush" },
{ "logging.file[@enable]", "false" },
{ "logging.level", COOLWSD_LOGLEVEL },
{ "logging.level_startup", "trace" },
Expand Down Expand Up @@ -2117,7 +2118,7 @@ void COOLWSD::innerInitialize(Poco::Util::Application& self)
{ "per_view.idle_timeout_secs", "900" },
{ "per_view.out_of_focus_timeout_secs", "300" },
{ "per_view.custom_os_info", "" },
{ "per_view.min_saved_message_timeout_secs", "0"},
{ "per_view.min_saved_message_timeout_secs", "0" },
{ "security.capabilities", "true" },
{ "security.seccomp", "true" },
{ "security.jwt_expiry_secs", "1800" },
Expand Down Expand Up @@ -2365,9 +2366,24 @@ void COOLWSD::innerInitialize(Poco::Util::Application& self)

// First log entry.
ServerName = config().getString("server_name");
LOG_INF("Initializing coolwsd server [" << ServerName << "]. Experimental features are "
<< (EnableExperimental ? "enabled." : "disabled."));
LOG_INF("Initializing coolwsd " << Util::getCoolVersion() << " server [" << ServerName
<< "]. Experimental features are "
<< (EnableExperimental ? "enabled." : "disabled."));

const std::map<std::string, std::string> allConfigs = ConfigUtil::extractAll(&conf);
std::ostringstream ossConfig;
ossConfig << "Loaded config file [" << configFilePath << "] (non-default values):\n";
for (const auto& pair : allConfigs)
{
const auto it = DefAppConfig.find(pair.first);
if (it == DefAppConfig.end() || it->second != pair.second)
{
ossConfig << pair.first << ": " << pair.second << '\n';
}
}

LoggableConfigEntries = ossConfig.str();
LOG_INF(LoggableConfigEntries);

// Initialize the UnitTest subsystem.
if (!UnitWSD::init(UnitWSD::UnitType::Wsd, UnitTestLibrary))
Expand Down Expand Up @@ -4159,6 +4175,7 @@ class COOLWSDServer
<< "\n IsProxyPrefixEnabled: " << (COOLWSD::IsProxyPrefixEnabled ? "yes" : "no")
<< "\n OverrideWatermark: " << COOLWSD::OverrideWatermark
<< "\n UserInterface: " << COOLWSD::UserInterface
<< "\n Config: " << LoggableConfigEntries
;

std::string smap;
Expand Down

0 comments on commit d7fae37

Please sign in to comment.