Common System 0.2.0
Common interfaces and patterns for system integration
Loading...
Searching...
No Matches
kcenon::common::config::config_loader Class Reference

Loads and validates unified configuration from various sources. More...

#include <config_loader.h>

Collaboration diagram for kcenon::common::config::config_loader:
Collaboration graph

Static Public Member Functions

static Result< unified_configload (const std::string &path)
 Load configuration from a YAML file.
 
static Result< unified_configload_from_string (const std::string &yaml_content)
 Load configuration from a YAML string.
 
static Result< unified_configload_from_env ()
 Load configuration from environment variables only.
 
static unified_config defaults ()
 Get default configuration.
 
static VoidResult validate (const unified_config &config)
 Validate a configuration.
 
static std::vector< validation_issueget_validation_issues (const unified_config &config)
 Get all validation issues for a configuration.
 
static std::string expand_env_vars (const std::string &value)
 Expand environment variables in a string.
 

Static Private Member Functions

static VoidResult merge_env_overrides (unified_config &config)
 Apply environment variable overrides to configuration.
 
static void apply_env_override (const char *env_name, std::string &target)
 
static void apply_env_override (const char *env_name, size_t &target)
 
static void apply_env_override (const char *env_name, uint16_t &target)
 
static void apply_env_override_bool (const char *env_name, bool &target)
 
static void apply_env_override_double (const char *env_name, double &target)
 
static void apply_env_override_ms (const char *env_name, std::chrono::milliseconds &target)
 
static void apply_env_override_vector (const char *env_name, std::vector< std::string > &target)
 
static void validate_thread_config (const thread_config &config, std::vector< validation_issue > &issues)
 
static void validate_logger_config (const logger_config &config, std::vector< validation_issue > &issues)
 
static void validate_monitoring_config (const monitoring_config &config, std::vector< validation_issue > &issues)
 
static void validate_database_config (const database_config &config, std::vector< validation_issue > &issues)
 
static void validate_network_config (const network_config &config, std::vector< validation_issue > &issues)
 

Detailed Description

Loads and validates unified configuration from various sources.

The config_loader supports loading configuration from:

  • YAML files (when BUILD_WITH_YAML_CPP is defined)
  • Environment variables (UNIFIED_* prefix)
  • Programmatic defaults

Usage Example:

// Load from file with environment overrides
auto result = config_loader::load("config.yaml");
if (result.is_ok()) {
auto config = result.value();
// Use config...
}
// Load from environment only
auto env_result = config_loader::load_from_env();
// Get defaults
static unified_config defaults()
Get default configuration.
static Result< unified_config > load_from_env()
Load configuration from environment variables only.
static Result< unified_config > load(const std::string &path)
Load configuration from a YAML file.

Definition at line 94 of file config_loader.h.

Member Function Documentation

◆ apply_env_override() [1/3]

static void kcenon::common::config::config_loader::apply_env_override ( const char * env_name,
size_t & target )
inlinestaticprivate

Definition at line 423 of file config_loader.h.

423 {
424 const char* value = std::getenv(env_name);
425 if (value != nullptr) {
426 try {
427 target = std::stoull(value);
428 } catch (...) {
429 // Ignore invalid values
430 }
431 }
432 }

◆ apply_env_override() [2/3]

static void kcenon::common::config::config_loader::apply_env_override ( const char * env_name,
std::string & target )
inlinestaticprivate

Definition at line 416 of file config_loader.h.

416 {
417 const char* value = std::getenv(env_name);
418 if (value != nullptr) {
419 target = value;
420 }
421 }

Referenced by merge_env_overrides().

Here is the caller graph for this function:

◆ apply_env_override() [3/3]

static void kcenon::common::config::config_loader::apply_env_override ( const char * env_name,
uint16_t & target )
inlinestaticprivate

Definition at line 434 of file config_loader.h.

434 {
435 const char* value = std::getenv(env_name);
436 if (value != nullptr) {
437 try {
438 auto parsed = std::stoul(value);
439 if (parsed <= 65535) {
440 target = static_cast<uint16_t>(parsed);
441 }
442 } catch (...) {
443 // Ignore invalid values
444 }
445 }
446 }

◆ apply_env_override_bool()

static void kcenon::common::config::config_loader::apply_env_override_bool ( const char * env_name,
bool & target )
inlinestaticprivate

Definition at line 448 of file config_loader.h.

448 {
449 const char* value = std::getenv(env_name);
450 if (value != nullptr) {
451 std::string str_value(value);
452 // Convert to lowercase for comparison
453 std::transform(str_value.begin(), str_value.end(), str_value.begin(),
454 [](unsigned char c) { return std::tolower(c); });
455
456 if (str_value == "true" || str_value == "1" || str_value == "yes" || str_value == "on") {
457 target = true;
458 } else if (str_value == "false" || str_value == "0" || str_value == "no" || str_value == "off") {
459 target = false;
460 }
461 }
462 }

Referenced by merge_env_overrides().

Here is the caller graph for this function:

◆ apply_env_override_double()

static void kcenon::common::config::config_loader::apply_env_override_double ( const char * env_name,
double & target )
inlinestaticprivate

Definition at line 464 of file config_loader.h.

464 {
465 const char* value = std::getenv(env_name);
466 if (value != nullptr) {
467 try {
468 target = std::stod(value);
469 } catch (...) {
470 // Ignore invalid values
471 }
472 }
473 }

Referenced by merge_env_overrides().

Here is the caller graph for this function:

◆ apply_env_override_ms()

static void kcenon::common::config::config_loader::apply_env_override_ms ( const char * env_name,
std::chrono::milliseconds & target )
inlinestaticprivate

Definition at line 475 of file config_loader.h.

475 {
476 const char* value = std::getenv(env_name);
477 if (value != nullptr) {
478 try {
479 target = std::chrono::milliseconds{std::stoll(value)};
480 } catch (...) {
481 // Ignore invalid values
482 }
483 }
484 }

Referenced by merge_env_overrides().

Here is the caller graph for this function:

◆ apply_env_override_vector()

static void kcenon::common::config::config_loader::apply_env_override_vector ( const char * env_name,
std::vector< std::string > & target )
inlinestaticprivate

Definition at line 486 of file config_loader.h.

486 {
487 const char* value = std::getenv(env_name);
488 if (value != nullptr) {
489 target.clear();
490 std::string str_value(value);
491 std::stringstream ss(str_value);
492 std::string item;
493 while (std::getline(ss, item, ',')) {
494 // Trim whitespace
495 size_t start = item.find_first_not_of(" \t");
496 size_t end = item.find_last_not_of(" \t");
497 if (start != std::string::npos && end != std::string::npos) {
498 target.push_back(item.substr(start, end - start + 1));
499 }
500 }
501 }
502 }

Referenced by merge_env_overrides().

Here is the caller graph for this function:

◆ defaults()

static unified_config kcenon::common::config::config_loader::defaults ( )
inlinestatic

Get default configuration.

Returns
unified_config with all default values

Definition at line 238 of file config_loader.h.

238 {
240 }
static unified_config defaults()
Create a configuration with all default values.

References kcenon::common::config::unified_config::defaults().

Referenced by kcenon::common::config::config_watcher::config_watcher(), load_from_env(), and load_from_string().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ expand_env_vars()

static std::string kcenon::common::config::config_loader::expand_env_vars ( const std::string & value)
inlinestatic

Expand environment variables in a string.

Replaces ${VAR_NAME} patterns with the corresponding environment variable values. If a variable is not set, the pattern is left unchanged.

Parameters
valueString containing environment variable references
Returns
String with environment variables expanded

Definition at line 313 of file config_loader.h.

313 {
314 static const std::regex env_pattern(R"(\$\{([^}]+)\})");
315
316 std::string result = value;
317 std::smatch match;
318 std::string::const_iterator search_start = result.cbegin();
319
320 std::string output;
321 size_t last_pos = 0;
322
323 while (std::regex_search(search_start, result.cend(), match, env_pattern)) {
324 size_t match_pos = static_cast<size_t>(match.position()) +
325 static_cast<size_t>(std::distance(result.cbegin(), search_start));
326
327 // Append text before the match
328 output += result.substr(last_pos, match_pos - last_pos);
329
330 // Get environment variable
331 std::string var_name = match[1].str();
332 const char* env_value = std::getenv(var_name.c_str());
333
334 if (env_value != nullptr) {
335 output += env_value;
336 } else {
337 // Keep the original pattern if variable not found
338 output += match[0].str();
339 }
340
341 last_pos = match_pos + match[0].length();
342 search_start = match.suffix().first;
343 }
344
345 // Append remaining text
346 output += result.substr(last_pos);
347
348 return output;
349 }

Referenced by load_from_string().

Here is the caller graph for this function:

◆ get_validation_issues()

static std::vector< validation_issue > kcenon::common::config::config_loader::get_validation_issues ( const unified_config & config)
inlinestatic

Get all validation issues for a configuration.

Returns both errors and warnings.

Parameters
configConfiguration to validate
Returns
Vector of validation issues

Definition at line 291 of file config_loader.h.

291 {
292 std::vector<validation_issue> issues;
293
294 validate_thread_config(config.thread, issues);
295 validate_logger_config(config.logger, issues);
296 validate_monitoring_config(config.monitoring, issues);
297 validate_database_config(config.database, issues);
298 validate_network_config(config.network, issues);
299
300 return issues;
301 }
static void validate_logger_config(const logger_config &config, std::vector< validation_issue > &issues)
static void validate_database_config(const database_config &config, std::vector< validation_issue > &issues)
static void validate_monitoring_config(const monitoring_config &config, std::vector< validation_issue > &issues)
static void validate_network_config(const network_config &config, std::vector< validation_issue > &issues)
static void validate_thread_config(const thread_config &config, std::vector< validation_issue > &issues)

References kcenon::common::config::unified_config::database, kcenon::common::config::unified_config::logger, kcenon::common::config::unified_config::monitoring, kcenon::common::config::unified_config::network, kcenon::common::config::unified_config::thread, validate_database_config(), validate_logger_config(), validate_monitoring_config(), validate_network_config(), and validate_thread_config().

Here is the call graph for this function:

◆ load()

static Result< unified_config > kcenon::common::config::config_loader::load ( const std::string & path)
inlinestatic

Load configuration from a YAML file.

Loads the configuration from the specified file path, applies environment variable substitution, and merges with environment variable overrides.

Parameters
pathPath to the YAML configuration file
Returns
Result containing unified_config or error

Definition at line 106 of file config_loader.h.

106 {
107#ifdef BUILD_WITH_YAML_CPP
108 // Check if file exists
109 if (!std::filesystem::exists(path)) {
112 "Configuration file not found: " + path,
113 "config_loader"
114 );
115 }
116
117 try {
118 std::ifstream file(path);
119 if (!file.is_open()) {
122 "Failed to open configuration file: " + path,
123 "config_loader"
124 );
125 }
126
127 std::stringstream buffer;
128 buffer << file.rdbuf();
129 return load_from_string(buffer.str());
130 } catch (const std::exception& e) {
133 std::string("Failed to read configuration file: ") + e.what(),
134 "config_loader"
135 );
136 }
137#else
138 // Without yaml-cpp, we can only load from environment
139 (void)path; // Suppress unused parameter warning
142 "YAML support not available. Build with -DBUILD_WITH_YAML_CPP=ON",
143 "config_loader"
144 );
145#endif
146 }
static Result< unified_config > load_from_string(const std::string &yaml_content)
Load configuration from a YAML string.
Result< T > make_error(int code, const std::string &message, const std::string &module="")
Create an error result with code and message.
Definition utilities.h:91

References kcenon::common::config::config_error_codes::file_not_found, kcenon::common::config::config_error_codes::io_error, load_from_string(), kcenon::common::make_error(), and kcenon::common::config::config_error_codes::parse_error.

Referenced by kcenon::common::config::config_watcher::config_watcher(), kcenon::common::config::config_watcher::do_reload(), and kcenon::common::config::cli_config_parser::load_with_cli_overrides().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ load_from_env()

static Result< unified_config > kcenon::common::config::config_loader::load_from_env ( )
inlinestatic

Load configuration from environment variables only.

Creates a default configuration and applies all UNIFIED_* environment variable overrides.

Returns
Result containing unified_config or error

Definition at line 218 of file config_loader.h.

218 {
219 unified_config config = defaults();
220
221 auto result = merge_env_overrides(config);
222 if (result.is_err()) {
223 return make_error<unified_config>(result.error());
224 }
225
226 auto validation_result = validate(config);
227 if (validation_result.is_err()) {
228 return make_error<unified_config>(validation_result.error());
229 }
230
231 return Result<unified_config>::ok(std::move(config));
232 }
static Result< T > ok(U &&value)
Create a successful result with value (static factory)
Definition core.h:223
static VoidResult validate(const unified_config &config)
Validate a configuration.
static VoidResult merge_env_overrides(unified_config &config)
Apply environment variable overrides to configuration.

References defaults(), kcenon::common::make_error(), merge_env_overrides(), kcenon::common::Result< T >::ok(), and validate().

Referenced by kcenon::common::config::cli_config_parser::load_with_cli_overrides().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ load_from_string()

static Result< unified_config > kcenon::common::config::config_loader::load_from_string ( const std::string & yaml_content)
inlinestatic

Load configuration from a YAML string.

Parses the YAML content, applies environment variable substitution, and merges with environment variable overrides.

Parameters
yaml_contentYAML content as a string
Returns
Result containing unified_config or error

Definition at line 157 of file config_loader.h.

157 {
158#ifdef BUILD_WITH_YAML_CPP
159 try {
160 // Expand environment variables in the YAML content
161 std::string expanded = expand_env_vars(yaml_content);
162
163 YAML::Node root = YAML::Load(expanded);
164
165 // Start with defaults
166 unified_config config = defaults();
167
168 // Parse the YAML into config
169 auto parse_result = parse_yaml(root, config);
170 if (parse_result.is_err()) {
171 return make_error<unified_config>(parse_result.error());
172 }
173
174 // Apply environment variable overrides
175 auto env_result = merge_env_overrides(config);
176 if (env_result.is_err()) {
177 return make_error<unified_config>(env_result.error());
178 }
179
180 // Validate the configuration
181 auto validation_result = validate(config);
182 if (validation_result.is_err()) {
183 return make_error<unified_config>(validation_result.error());
184 }
185
186 return Result<unified_config>::ok(std::move(config));
187 } catch (const YAML::ParserException& e) {
190 std::string("YAML parse error: ") + e.what(),
191 "config_loader"
192 );
193 } catch (const std::exception& e) {
196 std::string("Failed to parse configuration: ") + e.what(),
197 "config_loader"
198 );
199 }
200#else
201 (void)yaml_content;
204 "YAML support not available. Build with -DBUILD_WITH_YAML_CPP=ON",
205 "config_loader"
206 );
207#endif
208 }
static std::string expand_env_vars(const std::string &value)
Expand environment variables in a string.

References defaults(), expand_env_vars(), kcenon::common::make_error(), merge_env_overrides(), kcenon::common::Result< T >::ok(), kcenon::common::config::config_error_codes::parse_error, and validate().

Referenced by load().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ merge_env_overrides()

static VoidResult kcenon::common::config::config_loader::merge_env_overrides ( unified_config & config)
inlinestaticprivate

Apply environment variable overrides to configuration.

Definition at line 355 of file config_loader.h.

355 {
356 // Thread configuration
357 apply_env_override("UNIFIED_THREAD_POOL_SIZE", config.thread.pool_size);
358 apply_env_override("UNIFIED_THREAD_QUEUE_TYPE", config.thread.queue_type);
359 apply_env_override("UNIFIED_THREAD_MAX_QUEUE_SIZE", config.thread.max_queue_size);
360 apply_env_override("UNIFIED_THREAD_NAME_PREFIX", config.thread.thread_name_prefix);
361
362 // Logger configuration
363 apply_env_override("UNIFIED_LOGGER_LEVEL", config.logger.level);
364 apply_env_override_bool("UNIFIED_LOGGER_ASYNC", config.logger.async);
365 apply_env_override("UNIFIED_LOGGER_BUFFER_SIZE", config.logger.buffer_size);
366 apply_env_override("UNIFIED_LOGGER_FILE_PATH", config.logger.file_path);
367 apply_env_override("UNIFIED_LOGGER_MAX_FILE_SIZE", config.logger.max_file_size);
368 apply_env_override("UNIFIED_LOGGER_MAX_BACKUP_FILES", config.logger.max_backup_files);
369 apply_env_override("UNIFIED_LOGGER_FORMAT_PATTERN", config.logger.format_pattern);
370 apply_env_override_vector("UNIFIED_LOGGER_WRITERS", config.logger.writers);
371
372 // Monitoring configuration
373 apply_env_override_bool("UNIFIED_MONITORING_ENABLED", config.monitoring.enabled);
374 apply_env_override_ms("UNIFIED_MONITORING_METRICS_INTERVAL_MS", config.monitoring.metrics_interval);
375 apply_env_override_ms("UNIFIED_MONITORING_HEALTH_CHECK_INTERVAL_MS", config.monitoring.health_check_interval);
376 apply_env_override("UNIFIED_MONITORING_PROMETHEUS_PORT", config.monitoring.prometheus_port);
377 apply_env_override("UNIFIED_MONITORING_PROMETHEUS_PATH", config.monitoring.prometheus_path);
378
379 // Tracing configuration
380 apply_env_override_bool("UNIFIED_MONITORING_TRACING_ENABLED", config.monitoring.tracing.enabled);
381 apply_env_override_double("UNIFIED_MONITORING_TRACING_SAMPLING_RATE", config.monitoring.tracing.sampling_rate);
382 apply_env_override("UNIFIED_MONITORING_TRACING_EXPORTER", config.monitoring.tracing.exporter);
383 apply_env_override("UNIFIED_MONITORING_TRACING_ENDPOINT", config.monitoring.tracing.endpoint);
384
385 // Database configuration
386 apply_env_override("UNIFIED_DATABASE_BACKEND", config.database.backend);
387 apply_env_override("UNIFIED_DATABASE_CONNECTION_STRING", config.database.connection_string);
388 apply_env_override_bool("UNIFIED_DATABASE_LOG_QUERIES", config.database.log_queries);
389 apply_env_override_ms("UNIFIED_DATABASE_SLOW_QUERY_THRESHOLD_MS", config.database.slow_query_threshold);
390 apply_env_override("UNIFIED_DATABASE_POOL_MIN_SIZE", config.database.pool.min_size);
391 apply_env_override("UNIFIED_DATABASE_POOL_MAX_SIZE", config.database.pool.max_size);
392 apply_env_override_ms("UNIFIED_DATABASE_POOL_IDLE_TIMEOUT_MS", config.database.pool.idle_timeout);
393 apply_env_override_ms("UNIFIED_DATABASE_POOL_ACQUIRE_TIMEOUT_MS", config.database.pool.acquire_timeout);
394
395 // Network configuration
396 apply_env_override("UNIFIED_NETWORK_COMPRESSION", config.network.compression);
397 apply_env_override("UNIFIED_NETWORK_BUFFER_SIZE", config.network.buffer_size);
398 apply_env_override_ms("UNIFIED_NETWORK_CONNECT_TIMEOUT_MS", config.network.connect_timeout);
399 apply_env_override_ms("UNIFIED_NETWORK_IO_TIMEOUT_MS", config.network.io_timeout);
400 apply_env_override_ms("UNIFIED_NETWORK_KEEPALIVE_INTERVAL_MS", config.network.keepalive_interval);
401 apply_env_override("UNIFIED_NETWORK_MAX_CONNECTIONS", config.network.max_connections);
402
403 // TLS configuration
404 apply_env_override_bool("UNIFIED_NETWORK_TLS_ENABLED", config.network.tls.enabled);
405 apply_env_override("UNIFIED_NETWORK_TLS_VERSION", config.network.tls.version);
406 apply_env_override("UNIFIED_NETWORK_TLS_CERT_PATH", config.network.tls.cert_path);
407 apply_env_override("UNIFIED_NETWORK_TLS_KEY_PATH", config.network.tls.key_path);
408 apply_env_override("UNIFIED_NETWORK_TLS_CA_PATH", config.network.tls.ca_path);
409 apply_env_override_bool("UNIFIED_NETWORK_TLS_VERIFY_PEER", config.network.tls.verify_peer);
410
411 return VoidResult::ok({});
412 }
static void apply_env_override_bool(const char *env_name, bool &target)
static void apply_env_override_vector(const char *env_name, std::vector< std::string > &target)
static void apply_env_override(const char *env_name, std::string &target)
static void apply_env_override_ms(const char *env_name, std::chrono::milliseconds &target)
static void apply_env_override_double(const char *env_name, double &target)

References kcenon::common::config::pool_config::acquire_timeout, apply_env_override(), apply_env_override_bool(), apply_env_override_double(), apply_env_override_ms(), apply_env_override_vector(), kcenon::common::config::logger_config::async, kcenon::common::config::database_config::backend, kcenon::common::config::logger_config::buffer_size, kcenon::common::config::network_config::buffer_size, kcenon::common::config::tls_config::ca_path, kcenon::common::config::tls_config::cert_path, kcenon::common::config::network_config::compression, kcenon::common::config::network_config::connect_timeout, kcenon::common::config::database_config::connection_string, kcenon::common::config::unified_config::database, kcenon::common::config::monitoring_config::enabled, kcenon::common::config::tls_config::enabled, kcenon::common::config::tracing_config::enabled, kcenon::common::config::tracing_config::endpoint, kcenon::common::config::tracing_config::exporter, kcenon::common::config::logger_config::file_path, kcenon::common::config::logger_config::format_pattern, kcenon::common::config::monitoring_config::health_check_interval, kcenon::common::config::pool_config::idle_timeout, kcenon::common::config::network_config::io_timeout, kcenon::common::config::network_config::keepalive_interval, kcenon::common::config::tls_config::key_path, kcenon::common::config::logger_config::level, kcenon::common::config::database_config::log_queries, kcenon::common::config::unified_config::logger, kcenon::common::config::logger_config::max_backup_files, kcenon::common::config::network_config::max_connections, kcenon::common::config::logger_config::max_file_size, kcenon::common::config::thread_config::max_queue_size, kcenon::common::config::pool_config::max_size, kcenon::common::config::monitoring_config::metrics_interval, kcenon::common::config::pool_config::min_size, kcenon::common::config::unified_config::monitoring, kcenon::common::config::unified_config::network, kcenon::common::Result< T >::ok(), kcenon::common::config::database_config::pool, kcenon::common::config::thread_config::pool_size, kcenon::common::config::monitoring_config::prometheus_path, kcenon::common::config::monitoring_config::prometheus_port, kcenon::common::config::thread_config::queue_type, kcenon::common::config::tracing_config::sampling_rate, kcenon::common::config::database_config::slow_query_threshold, kcenon::common::config::unified_config::thread, kcenon::common::config::thread_config::thread_name_prefix, kcenon::common::config::network_config::tls, kcenon::common::config::monitoring_config::tracing, kcenon::common::config::tls_config::verify_peer, kcenon::common::config::tls_config::version, and kcenon::common::config::logger_config::writers.

Referenced by load_from_env(), and load_from_string().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ validate()

static VoidResult kcenon::common::config::config_loader::validate ( const unified_config & config)
inlinestatic

Validate a configuration.

Checks all configuration values against their allowed ranges and valid options.

Parameters
configConfiguration to validate
Returns
VoidResult indicating success or validation error

Definition at line 251 of file config_loader.h.

251 {
252 std::vector<validation_issue> issues;
253
254 // Validate thread configuration
255 validate_thread_config(config.thread, issues);
256
257 // Validate logger configuration
258 validate_logger_config(config.logger, issues);
259
260 // Validate monitoring configuration
261 validate_monitoring_config(config.monitoring, issues);
262
263 // Validate database configuration
264 validate_database_config(config.database, issues);
265
266 // Validate network configuration
267 validate_network_config(config.network, issues);
268
269 // Check for errors (not warnings)
270 for (const auto& issue : issues) {
271 if (!issue.is_warning) {
274 "Validation failed for " + issue.field_path + ": " + issue.message,
275 "config_loader"
276 );
277 }
278 }
279
280 return VoidResult::ok({});
281 }

References kcenon::common::config::unified_config::database, kcenon::common::config::unified_config::logger, kcenon::common::make_error(), kcenon::common::config::unified_config::monitoring, kcenon::common::config::unified_config::network, kcenon::common::Result< T >::ok(), kcenon::common::config::unified_config::thread, validate_database_config(), validate_logger_config(), validate_monitoring_config(), validate_network_config(), validate_thread_config(), and kcenon::common::config::config_error_codes::validation_error.

Referenced by kcenon::common::config::config_watcher::do_reload(), load_from_env(), load_from_string(), and kcenon::common::config::cli_config_parser::load_with_cli_overrides().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ validate_database_config()

static void kcenon::common::config::config_loader::validate_database_config ( const database_config & config,
std::vector< validation_issue > & issues )
inlinestaticprivate

Definition at line 776 of file config_loader.h.

776 {
777 // Backend validation (if specified)
778 if (!config.backend.empty()) {
779 static const std::vector<std::string> valid_backends = {"postgresql", "mysql", "sqlite", "mongodb", "redis"};
780 if (std::find(valid_backends.begin(), valid_backends.end(), config.backend) == valid_backends.end()) {
781 issues.push_back({"database.backend",
782 "Invalid backend: " + config.backend + ". Valid values: postgresql, mysql, sqlite, mongodb, redis",
783 false});
784 }
785 }
786
787 // Pool size validation
788 if (config.pool.min_size > config.pool.max_size) {
789 issues.push_back({"database.pool",
790 "min_size cannot be greater than max_size",
791 false});
792 }
793
794 if (config.pool.max_size == 0) {
795 issues.push_back({"database.pool.max_size",
796 "Pool max_size must be greater than 0",
797 false});
798 }
799 }

References kcenon::common::config::database_config::backend, kcenon::common::config::pool_config::max_size, kcenon::common::config::pool_config::min_size, and kcenon::common::config::database_config::pool.

Referenced by get_validation_issues(), and validate().

Here is the caller graph for this function:

◆ validate_logger_config()

static void kcenon::common::config::config_loader::validate_logger_config ( const logger_config & config,
std::vector< validation_issue > & issues )
inlinestaticprivate

Definition at line 725 of file config_loader.h.

725 {
726 // Log level validation
727 static const std::vector<std::string> valid_levels = {"trace", "debug", "info", "warn", "error", "critical", "off"};
728 if (std::find(valid_levels.begin(), valid_levels.end(), config.level) == valid_levels.end()) {
729 issues.push_back({"logger.level",
730 "Invalid log level: " + config.level + ". Valid values: trace, debug, info, warn, error, critical, off",
731 false});
732 }
733
734 // Writers validation
735 static const std::vector<std::string> valid_writers = {"console", "file", "rotating_file", "network", "json"};
736 for (const auto& writer : config.writers) {
737 if (std::find(valid_writers.begin(), valid_writers.end(), writer) == valid_writers.end()) {
738 issues.push_back({"logger.writers",
739 "Invalid writer: " + writer + ". Valid values: console, file, rotating_file, network, json",
740 false});
741 }
742 }
743
744 // Buffer size warning
745 if (config.async && config.buffer_size < 1024) {
746 issues.push_back({"logger.buffer_size",
747 "Buffer size is very small for async logging. Consider using at least 1024 bytes.",
748 true});
749 }
750 }

References kcenon::common::config::logger_config::async, kcenon::common::config::logger_config::buffer_size, kcenon::common::config::logger_config::level, and kcenon::common::config::logger_config::writers.

Referenced by get_validation_issues(), and validate().

Here is the caller graph for this function:

◆ validate_monitoring_config()

static void kcenon::common::config::config_loader::validate_monitoring_config ( const monitoring_config & config,
std::vector< validation_issue > & issues )
inlinestaticprivate

Definition at line 752 of file config_loader.h.

752 {
753 // Sampling rate validation
754 if (config.tracing.sampling_rate < 0.0 || config.tracing.sampling_rate > 1.0) {
755 issues.push_back({"monitoring.tracing.sampling_rate",
756 "Sampling rate must be between 0.0 and 1.0",
757 false});
758 }
759
760 // Exporter validation
761 static const std::vector<std::string> valid_exporters = {"otlp", "jaeger", "zipkin", "console"};
762 if (std::find(valid_exporters.begin(), valid_exporters.end(), config.tracing.exporter) == valid_exporters.end()) {
763 issues.push_back({"monitoring.tracing.exporter",
764 "Invalid exporter: " + config.tracing.exporter + ". Valid values: otlp, jaeger, zipkin, console",
765 false});
766 }
767
768 // Metrics interval warning
769 if (config.metrics_interval.count() < 1000) {
770 issues.push_back({"monitoring.metrics_interval",
771 "Metrics interval is very short (<1s). This may cause performance issues.",
772 true});
773 }
774 }

References kcenon::common::config::tracing_config::exporter, kcenon::common::config::monitoring_config::metrics_interval, kcenon::common::config::tracing_config::sampling_rate, and kcenon::common::config::monitoring_config::tracing.

Referenced by get_validation_issues(), and validate().

Here is the caller graph for this function:

◆ validate_network_config()

static void kcenon::common::config::config_loader::validate_network_config ( const network_config & config,
std::vector< validation_issue > & issues )
inlinestaticprivate

Definition at line 801 of file config_loader.h.

801 {
802 // Compression validation
803 static const std::vector<std::string> valid_compressions = {"none", "lz4", "gzip", "deflate", "zstd"};
804 if (std::find(valid_compressions.begin(), valid_compressions.end(), config.compression) == valid_compressions.end()) {
805 issues.push_back({"network.compression",
806 "Invalid compression: " + config.compression + ". Valid values: none, lz4, gzip, deflate, zstd",
807 false});
808 }
809
810 // TLS version validation
811 static const std::vector<std::string> valid_tls_versions = {"1.2", "1.3"};
812 if (std::find(valid_tls_versions.begin(), valid_tls_versions.end(), config.tls.version) == valid_tls_versions.end()) {
813 issues.push_back({"network.tls.version",
814 "Invalid TLS version: " + config.tls.version + ". Valid values: 1.2, 1.3",
815 false});
816 }
817
818 // Buffer size warning
819 if (config.buffer_size < 4096) {
820 issues.push_back({"network.buffer_size",
821 "Buffer size is very small (<4KB). This may cause performance issues.",
822 true});
823 }
824
825 // TLS certificate validation
826 if (config.tls.enabled && config.tls.verify_peer && config.tls.ca_path.empty()) {
827 issues.push_back({"network.tls.ca_path",
828 "TLS is enabled with verify_peer but no CA path specified.",
829 true});
830 }
831 }

References kcenon::common::config::network_config::buffer_size, kcenon::common::config::tls_config::ca_path, kcenon::common::config::network_config::compression, kcenon::common::config::tls_config::enabled, kcenon::common::config::network_config::tls, kcenon::common::config::tls_config::verify_peer, and kcenon::common::config::tls_config::version.

Referenced by get_validation_issues(), and validate().

Here is the caller graph for this function:

◆ validate_thread_config()

static void kcenon::common::config::config_loader::validate_thread_config ( const thread_config & config,
std::vector< validation_issue > & issues )
inlinestaticprivate

Definition at line 710 of file config_loader.h.

710 {
711 // Queue type validation
712 static const std::vector<std::string> valid_queue_types = {"mutex", "lockfree", "bounded"};
713 if (std::find(valid_queue_types.begin(), valid_queue_types.end(), config.queue_type) == valid_queue_types.end()) {
714 issues.push_back({"thread.queue_type",
715 "Invalid queue type: " + config.queue_type + ". Valid values: mutex, lockfree, bounded",
716 false});
717 }
718
719 // Max queue size validation
720 if (config.max_queue_size == 0) {
721 issues.push_back({"thread.max_queue_size", "Queue size must be greater than 0", false});
722 }
723 }

References kcenon::common::config::thread_config::max_queue_size, and kcenon::common::config::thread_config::queue_type.

Referenced by get_validation_issues(), and validate().

Here is the caller graph for this function:

The documentation for this class was generated from the following file: