diag: Add verbose logs during config init

This commit is contained in:
John Colvin committed 2023-04-16 00:13:42 -04:00
1 parent 7da82d8444
commit 4f22ae04fe
3 files changed
+32 -10

No files matched your search

+26 -6
View File
@@ -7,6 +7,8 @@
#include "PreprocessInputStream.h"
#include "config.h"
#include "lib/collections/Contains.h"
#include "lib/core/FMT.h"
#include "lib/io/ProtoPrinter.h"
#include "lib/os/os.h"
#include "lib/utils/bts_array_size.h"
#include "lib/utils/bts_assert.h"
@@ -52,6 +54,8 @@ namespace bts {
namespace config {
namespace internal {
using bts::io::ProtoPrinter;
const char *MESSAGE_STRING_RULE = "rule";
const char *MESSAGE_STRING_VALUE = "value";
const char *MESSAGE_STRING_INCLUDE = "include";
@@ -114,6 +118,9 @@ void ConfigurationState::initialize_defaults(
if (_is_initialized)
return;
log.info(FMT(
"Initializing config defaults with files from the following dirs: {}",
FMT_JOIN(proto_dirs, ", ")));
generate_all_config_proto(log, proto_dirs);
std::shared_ptr<proto::Message> new_message(_prototype->New());
@@ -137,7 +144,7 @@ void ConfigurationState::initialize_defaults(
_is_initialized = true;
}
void ConfigurationState::initialize_builtins() {
void ConfigurationState::initialize_builtins(IConfigLog *log) {
SystemConfig sys;
sys.set_host_name(os::host_name());
@@ -207,6 +214,10 @@ void ConfigurationState::initialize_builtins() {
}
sys.set_num_cores(os::num_cores());
if (log != nullptr) {
log->info(FMT(
"Initialized SystemConfig:\n{}", ProtoPrinter::to_string(sys, 2)));
}
//
// Add the System value to the defaults
@@ -361,6 +372,8 @@ void ConfigurationState::initialize_settings() {
return;
ConfigLog log;
// For verbose config logs, uncomment line below
// log.set_print_errors(true);
initialize_defaults(log);
std::string settings = settings_path();
@@ -369,7 +382,7 @@ void ConfigurationState::initialize_settings() {
{
DEFER( // Do this even if load() fails
initialize_builtins(); initialize_macros();
initialize_builtins(&log); initialize_macros();
_deferred_queue->process(););
load(settings, log);
}
@@ -828,7 +841,8 @@ PathType::type get_path_type(std::string path) {
}
}
urdl::url url_from_string(std::string &path, bool required) {
urdl::url url_from_string(
const std::string &path, bool required, IConfigLog *log = nullptr) {
boost::system::error_code ec;
// attempt to parse the path as a URL - if that fails assume it is an
// absolute file path and append file:///
@@ -838,6 +852,11 @@ urdl::url url_from_string(std::string &path, bool required) {
std::string abs_path = boost::filesystem::absolute(path).string();
url = urdl::url::from_string(
file_prefix + os::normalize_path(abs_path), ec);
if (ec && log != nullptr) {
log->warning(
FMT("Failed to convert '{}' to a url. urdl::url::from_string resulted in error code {}",
path, ec));
}
}
bts_assert_msg(!required || !ec, ec.message().c_str());
@@ -908,7 +927,7 @@ int load_directory(
IConfigLog &log,
ConfigValueQueue &lookup) {
LogAggregator aggregate_log(log);
aggregate_log.info("URL: " + url);
aggregate_log.info(FMT("Loading config dir from '{}'", url));
const char last_char = url.at(url.length() - 1);
if (last_char != '/') {
@@ -985,12 +1004,12 @@ ConfigDownloader::Result load_file(
string url = url_from_string(path, required).to_string();
ConfigDownloader::Result result = downloader.get(url, url_stream);
if (!(result == ConfigDownloader::SUCCESS)) {
log.warning(FMT("Failed to load config from '{}'", url));
bts_assert_msg(!required || url_stream, (path + " not found.").c_str());
return result;
}
log.info("Loaded: " + path);
log.info(FMT("Parsing config loaded from '{}'", url));
proto::io::IstreamInputStream proto_stream(&url_stream);
parse_stream(path, proto_stream, out_message, log, lookup);
@@ -1003,6 +1022,7 @@ void parse_stream(
proto::Message &out_message,
IConfigLog &log,
ConfigValueQueue &lookup) {
log.info(FMT("ConfigurationState::parse_stream. file: {}", file));
ConfigErrorCollector error_collector(log, file.c_str());
bts::google::protobuf::TextFormat::Parser parser;
parser.RecordErrorsTo(&error_collector);
+1 -1
View File
@@ -86,7 +86,7 @@ class ConfigurationState {
private:
BTS_NO_COPY(ConfigurationState);
void initialize_builtins();
void initialize_builtins(IConfigLog *log = nullptr);
void initialize_introspection();
void initialize_macros();
void add_macro(const proto::Message *);
+5 -3
View File
@@ -20,7 +20,7 @@ class ProtoPrinter {
* Dumps \p message to an std::string
*/
template <class T>
static std::string to_string(const T &message);
static std::string to_string(const T &message, int initial_indent = 0);
template <class T>
class OutputWrapper {
@@ -45,9 +45,11 @@ ProtoPrinter::OutputWrapper<T>::OutputWrapper(const T *message) noexcept
: message(message) {}
template <class T>
std::string ProtoPrinter::to_string(const T &message) {
std::string ProtoPrinter::to_string(const T &message, int initial_indent) {
google::protobuf::TextFormat::Printer printer;
printer.SetInitialIndentLevel(initial_indent);
std::string str;
google::protobuf::TextFormat::PrintToString(message, &str);
printer.PrintToString(message, &str);
return str;
}