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

Classes

class  composite_health_check
 Aggregates multiple health checks into a single check. More...
 
class  GlobalLoggerRegistry
 Thread-safe singleton registry for managing logger instances. More...
 
interface  health_check
 Abstract base class for health checks. More...
 
class  health_check_builder
 Fluent builder for creating health checks. More...
 
struct  health_check_result
 Result of a health check operation. More...
 
class  health_dependency_graph
 Manages dependencies between health checks as a DAG. More...
 
class  health_monitor
 Central health monitoring system. More...
 
struct  health_monitor_stats
 Statistics for health monitoring. More...
 
struct  http_request
 Represents an HTTP request. More...
 
struct  http_response
 Represents an HTTP response. More...
 
class  IDatabase
 Standard interface for database operations. More...
 
interface  IExecutor
 Abstract interface for task execution systems. More...
 
interface  IExecutorProvider
 Interface for modules that provide executor implementations. More...
 
interface  IHttpClient
 Abstract interface for HTTP client implementations. More...
 
interface  IHttpClientProvider
 Interface for modules that provide HTTP client implementations. More...
 
interface  IJob
 Abstract job interface for task execution. More...
 
interface  ILogger
 Standard interface for logging implementations. More...
 
interface  ILoggerProvider
 Interface for modules that provide logger implementations. More...
 
interface  ILoggerRegistry
 Phase 2: Global logger registry interface. More...
 
interface  IMetricCollector
 Abstract interface for collecting metrics across modules. More...
 
interface  IMetricCollectorProvider
 Interface for modules that provide metric collector implementations. More...
 
interface  IMonitor
 Standard interface for monitoring implementations. More...
 
interface  IMonitorable
 Interface for objects that can be monitored. More...
 
interface  IMonitorProvider
 Interface for modules that provide monitor implementations. More...
 
interface  IStats
 Interface for components that expose statistics. More...
 
interface  IThreadPool
 Extended interface for thread pool implementations. More...
 
interface  IThreadPoolProvider
 Interface for modules that provide thread pool implementations. More...
 
interface  IUdpClient
 Abstract interface for UDP client implementations. More...
 
interface  IUdpClientProvider
 Interface for modules that provide UDP client implementations. More...
 
class  lambda_health_check
 Health check implementation using a lambda function. More...
 
struct  log_entry
 Standard log entry structure. More...
 
struct  logger_config
 Configuration for logger instances. More...
 
struct  metric_value
 Standard metric value structure with type information. More...
 
struct  metrics_snapshot
 Complete snapshot of metrics at a point in time. More...
 
class  null_http_client
 Null implementation for when HTTP transport is disabled. More...
 
class  null_metric_collector
 No-op implementation for when metrics are disabled. More...
 
class  null_udp_client
 Null implementation for when UDP transport is disabled. More...
 
class  NullLogger
 A no-op logger implementation for fallback scenarios. More...
 
struct  registry_event
 Represents a single audit event for registry mutations. More...
 
class  RegistryAuditLog
 Thread-safe audit log for registry operations. More...
 
class  scoped_timer
 RAII helper for automatic timing measurements. More...
 
struct  stats_snapshot
 Point-in-time snapshot of component statistics. More...
 
struct  system_metrics
 Specialized metrics for system-level monitoring. More...
 
struct  thread_pool_metrics
 Specialized metrics for thread pool monitoring. More...
 
struct  udp_endpoint
 Represents a UDP endpoint (host and port) More...
 
struct  udp_send_options
 Options for UDP send operations. More...
 
struct  udp_statistics
 Statistics for UDP client operations. More...
 
struct  worker_metrics
 Specialized metrics for worker thread monitoring. More...
 

Typedefs

using metric_labels = std::unordered_map<std::string, std::string>
 Metric labels for dimensional data.
 
using kcenon::common::interfaces::ExecutorFactory = std::function<std::shared_ptr<IExecutor>()>
 Factory function type for creating executor instances.
 
using kcenon::common::interfaces::LoggerFactory = std::function<std::shared_ptr<ILogger>()>
 Factory function type for creating logger instances.
 
using recovery_handler = std::function<bool()>
 Recovery handler function type.
 
using MetricCollectorFactory = std::function<std::shared_ptr<IMetricCollector>()>
 Factory function type for creating metric collector instances.
 
using MonitorFactory = std::function<std::shared_ptr<IMonitor>()>
 Factory function type for creating monitor instances.
 
using source_location = kcenon::common::source_location
 
using stats_value
 Type-safe value type for statistics.
 
using kcenon::common::interfaces::ThreadPoolFactory = std::function<std::shared_ptr<IThreadPool>(size_t worker_count)>
 Factory function type for creating thread pool instances.
 
using http_headers = std::map<std::string, std::string>
 HTTP headers container type.
 
using HttpClientFactory = std::function<std::shared_ptr<IHttpClient>()>
 Factory function type for creating HTTP client instances.
 
using UdpClientFactory = std::function<std::shared_ptr<IUdpClient>()>
 Factory function type for creating UDP client instances.
 

Enumerations

enum class  kcenon::common::interfaces::log_level {
  trace = 0 , debug = 1 , info = 2 , warning = 3 ,
  warn = 3 , error = 4 , critical = 5 , fatal = 5 ,
  off = 6 , trace = 0 , debug = 1 , info = 2 ,
  warning = 3 , error = 4 , critical = 5 , off = 6
}
 Standard log levels. More...
 
enum class  health_check_type {
  liveness , readiness , startup , dependency ,
  custom
}
 Types of health checks supported by the system. More...
 
enum class  metric_type { gauge , counter , histogram , summary }
 Types of metrics supported by the monitoring system. More...
 
enum class  health_status { healthy = 0 , degraded = 1 , unhealthy = 2 , unknown = 3 }
 Standard health status levels. More...
 
enum class  registry_action {
  register_logger , unregister_logger , set_default_logger , register_factory ,
  set_default_factory , clear_loggers , freeze_logger_registry , register_service ,
  unregister_service , clear_services , freeze_service_container
}
 Types of registry mutation actions. More...
 
enum class  kcenon::common::interfaces::log_level {
  trace = 0 , debug = 1 , info = 2 , warning = 3 ,
  warn = 3 , error = 4 , critical = 5 , fatal = 5 ,
  off = 6 , trace = 0 , debug = 1 , info = 2 ,
  warning = 3 , error = 4 , critical = 5 , off = 6
}
 

Functions

GlobalLoggerRegistryget_registry ()
 Get the global logger registry instance.
 
std::shared_ptr< ILoggerget_logger ()
 Get the default logger from the global registry.
 
std::shared_ptr< ILoggerget_logger (const std::string &name)
 Get a named logger from the global registry.
 
std::string kcenon::common::interfaces::to_string (log_level level)
 Convert log level to string.
 
log_level kcenon::common::interfaces::from_string (const std::string &str)
 Parse log level from string (case-insensitive)
 
std::string to_string (health_check_type type)
 Convert health check type to string.
 
Result< health_check_typehealth_check_type_from_string (const std::string &str)
 Convert string to health check type.
 
health_monitorglobal_health_monitor ()
 Get the global health monitor instance.
 
std::string to_string (metric_type type)
 Convert metric type to string.
 
Result< metric_typemetric_type_from_string (const std::string &str)
 Convert string to metric type.
 
std::string to_string (health_status status)
 Convert health status to string.
 
const char * to_string (registry_action action)
 Convert registry_action to string representation.
 

Typedef Documentation

◆ ExecutorFactory

typedef std::function< std::shared_ptr< IExecutor >()> kcenon::common::interfaces::ExecutorFactory = std::function<std::shared_ptr<IExecutor>()>
export

Factory function type for creating executor instances.

Definition at line 130 of file executor_interface.h.

◆ http_headers

using kcenon::common::interfaces::http_headers = std::map<std::string, std::string>

HTTP headers container type.

Definition at line 31 of file http_client_interface.h.

◆ HttpClientFactory

using kcenon::common::interfaces::HttpClientFactory = std::function<std::shared_ptr<IHttpClient>()>

Factory function type for creating HTTP client instances.

Definition at line 265 of file http_client_interface.h.

◆ LoggerFactory

typedef std::function< std::shared_ptr< ILogger >()> kcenon::common::interfaces::LoggerFactory = std::function<std::shared_ptr<ILogger>()>
export

Factory function type for creating logger instances.

Definition at line 232 of file logger_interface.h.

◆ metric_labels

typedef std::unordered_map< std::string, std::string > kcenon::common::interfaces::metric_labels = std::unordered_map<std::string, std::string>

Metric labels for dimensional data.

Labels allow attaching key-value pairs to metrics for filtering and grouping in monitoring systems (e.g., Prometheus, StatsD).

Example:

metric_labels labels{{"service", "api"}, {"endpoint", "/users"}};
collector->increment("http_requests_total", 1.0, labels);
std::unordered_map< std::string, std::string > metric_labels
Metric labels for dimensional data.
Definition monitoring.h:38

Definition at line 38 of file monitoring.h.

◆ MetricCollectorFactory

using kcenon::common::interfaces::MetricCollectorFactory = std::function<std::shared_ptr<IMetricCollector>()>

Factory function type for creating metric collector instances.

Definition at line 249 of file metric_collector_interface.h.

◆ MonitorFactory

using kcenon::common::interfaces::MonitorFactory = std::function<std::shared_ptr<IMonitor>()>

Factory function type for creating monitor instances.

Definition at line 339 of file monitoring_interface.h.

◆ recovery_handler

using kcenon::common::interfaces::recovery_handler = std::function<bool()>

Recovery handler function type.

A recovery handler is called when a health check fails. It should attempt to recover the failed component.

Returns
true if recovery was successful

Definition at line 56 of file health_monitor.h.

◆ source_location

◆ stats_value

typedef std::variant< std::int64_t, double, std::string, bool > kcenon::common::interfaces::stats_value
Initial value:
std::variant<
std::int64_t,
double,
std::string,
bool
>

Type-safe value type for statistics.

Supports common metric types: counters, gauges, rates, and boolean flags. Integer counters (request counts, error counts) Floating-point gauges (rates, percentages, latencies) String values (state names, labels) Boolean flags (enabled/disabled, healthy/unhealthy)

Definition at line 30 of file stats_interface.h.

◆ ThreadPoolFactory

typedef std::function< std::shared_ptr< IThreadPool >(size_t worker_count)> kcenon::common::interfaces::ThreadPoolFactory = std::function<std::shared_ptr<IThreadPool>(size_t worker_count)>
export

Factory function type for creating thread pool instances.

Definition at line 163 of file thread_pool_interface.h.

◆ UdpClientFactory

using kcenon::common::interfaces::UdpClientFactory = std::function<std::shared_ptr<IUdpClient>()>

Factory function type for creating UDP client instances.

Definition at line 311 of file udp_client_interface.h.

Enumeration Type Documentation

◆ health_check_type

Types of health checks supported by the system.

Enumerator
liveness 
readiness 
startup 
dependency 
custom 

Definition at line 31 of file health_check.h.

31 {
32 liveness, // Basic alive check - is the service running?
33 readiness, // Ready to accept traffic?
34 startup, // Has the service completed initialization?
35 dependency, // External dependency check (database, cache, etc.)
36 custom // User-defined health check type
37};

◆ health_status

Standard health status levels.

Enumerator
healthy 
degraded 
unhealthy 
unknown 

Definition at line 207 of file monitoring_interface.h.

◆ log_level [1/2]

enum class kcenon::common::interfaces::log_level
exportstrong

Standard log levels.

Note
v3.0.0: Added 'warn' and 'fatal' as aliases for 'warning' and 'critical' respectively, for backward compatibility with logger_system::log_level.
Enumerator
trace 
debug 
info 
warning 
warn 

Alias for warning (backward compatibility)

error 
critical 
fatal 

Alias for critical (backward compatibility)

off 
trace 
debug 
info 
warning 
error 
critical 
off 

Definition at line 41 of file logger_interface.h.

◆ log_level [2/2]

enum class kcenon::common::interfaces::log_level
exportstrong
Enumerator
trace 
debug 
info 
warning 
warn 

Alias for warning (backward compatibility)

error 
critical 
fatal 

Alias for critical (backward compatibility)

off 
trace 
debug 
info 
warning 
error 
critical 
off 

Definition at line 51 of file logger.cppm.

51 {
52 trace = 0,
53 debug = 1,
54 info = 2,
55 warning = 3,
56 error = 4,
57 critical = 5,
58 off = 6
59};

◆ metric_type

Types of metrics supported by the monitoring system.

Enumerator
gauge 
counter 
histogram 
summary 

Definition at line 36 of file monitoring_interface.h.

36 {
37 gauge, // Instant value that can go up or down
38 counter, // Monotonic increasing value
39 histogram, // Distribution of values across buckets
40 summary // Statistical summary (min, max, mean, percentiles)
41};

◆ registry_action

Types of registry mutation actions.

Enumerator
register_logger 

Logger registration.

unregister_logger 

Logger unregistration.

set_default_logger 

Default logger set.

register_factory 

Factory registration (logger)

set_default_factory 

Default factory set (logger)

clear_loggers 

Clear all loggers.

freeze_logger_registry 

Freeze logger registry.

register_service 

Service registration.

unregister_service 

Service unregistration.

clear_services 

Clear all services.

freeze_service_container 

Freeze service container.

Definition at line 42 of file registry_audit_log.h.

Function Documentation

◆ from_string()

log_level kcenon::common::interfaces::from_string ( const std::string & str)
inlineexport

Parse log level from string (case-insensitive)

Supports aliases: WARN -> warning, FATAL -> critical

Definition at line 334 of file logger_interface.h.

334 {
335 std::string upper(str.size(), '\0');
336 std::transform(str.begin(), str.end(), upper.begin(),
337 [](unsigned char c) { return static_cast<char>(std::toupper(c)); });
338
339 // Handle aliases first
340 if (upper == "WARN") {
341 return log_level::warning;
342 }
343 if (upper == "FATAL") {
344 return log_level::critical;
345 }
346
347 // Use generic template for standard values
348 auto result = enum_from_string<log_level>(str);
349 return result.is_ok() ? result.value() : log_level::info; // default
350}

References critical, kcenon::common::enum_from_string(), info, and warning.

Here is the call graph for this function:

◆ get_logger() [1/2]

std::shared_ptr< ILogger > kcenon::common::interfaces::get_logger ( )
inline

Get the default logger from the global registry.

Convenience function to get the default logger. Returns NullLogger if no default logger is registered.

Returns
Default logger or NullLogger

Definition at line 752 of file global_logger_registry.h.

752 {
753 return GlobalLoggerRegistry::instance().get_default_logger();
754}

References kcenon::common::interfaces::GlobalLoggerRegistry::get_default_logger(), and kcenon::common::interfaces::GlobalLoggerRegistry::instance().

Referenced by kcenon::common::logging::flush(), kcenon::common::logging::flush(), kcenon::common::logging::is_enabled(), kcenon::common::logging::is_enabled(), kcenon::common::logging::log(), and kcenon::common::logging::log().

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

◆ get_logger() [2/2]

std::shared_ptr< ILogger > kcenon::common::interfaces::get_logger ( const std::string & name)
inline

Get a named logger from the global registry.

Convenience function to get a named logger. Returns NullLogger if the specified logger is not registered.

Parameters
nameLogger name
Returns
Named logger or NullLogger

Definition at line 765 of file global_logger_registry.h.

765 {
766 return GlobalLoggerRegistry::instance().get_logger(name);
767}

References kcenon::common::interfaces::GlobalLoggerRegistry::get_logger(), and kcenon::common::interfaces::GlobalLoggerRegistry::instance().

Here is the call graph for this function:

◆ get_registry()

GlobalLoggerRegistry & kcenon::common::interfaces::get_registry ( )
inline

Get the global logger registry instance.

Convenience function to access the GlobalLoggerRegistry singleton.

Returns
Reference to the GlobalLoggerRegistry

Definition at line 740 of file global_logger_registry.h.

740 {
741 return GlobalLoggerRegistry::instance();
742}

References kcenon::common::interfaces::GlobalLoggerRegistry::instance().

Here is the call graph for this function:

◆ global_health_monitor()

health_monitor & kcenon::common::interfaces::global_health_monitor ( )
inline

Get the global health monitor instance.

Returns
Reference to the global health monitor singleton

This function provides access to a global health monitor instance for application-wide health monitoring.

Example usage:

auto& monitor = global_health_monitor();
monitor.register_check("database", db_check);
health_monitor & global_health_monitor()
Get the global health monitor instance.

Definition at line 403 of file health_monitor.h.

403 {
404 static health_monitor instance;
405 return instance;
406}
Central health monitoring system.

◆ health_check_type_from_string()

Result< health_check_type > kcenon::common::interfaces::health_check_type_from_string ( const std::string & str)
inline

Convert string to health check type.

Definition at line 72 of file health_check.h.

72 {
73 return enum_from_string<health_check_type>(str);
74}

References kcenon::common::enum_from_string().

Referenced by main().

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

◆ metric_type_from_string()

Result< metric_type > kcenon::common::interfaces::metric_type_from_string ( const std::string & str)
inline

Convert string to metric type.

Definition at line 71 of file monitoring_interface.h.

71 {
72 return enum_from_string<metric_type>(str);
73}

References kcenon::common::enum_from_string().

Here is the call graph for this function:

◆ to_string() [1/5]

std::string kcenon::common::interfaces::to_string ( health_check_type type)
inline

Convert health check type to string.

Definition at line 65 of file health_check.h.

65 {
66 return enum_to_string(type);
67}
std::string enum_to_string(Enum value)
Convert an enum value to its string representation.

References kcenon::common::enum_to_string().

Here is the call graph for this function:

◆ to_string() [2/5]

std::string kcenon::common::interfaces::to_string ( health_status status)
inline

Convert health status to string.

Definition at line 366 of file monitoring_interface.h.

366 {
367 return enum_to_string(status);
368}

References kcenon::common::enum_to_string().

Here is the call graph for this function:

◆ to_string() [3/5]

std::string kcenon::common::interfaces::to_string ( log_level level)
inlineexport

Convert log level to string.

Definition at line 325 of file logger_interface.h.

325 {
326 return enum_to_string(level);
327}

References kcenon::common::enum_to_string().

Referenced by kcenon::common::interfaces::health_monitor::get_health_report(), kcenon::common::interfaces::health_monitor::get_overall_status_string(), kcenon::common::logging::ConsoleLogger::log(), kcenon::common::logging::ConsoleLogger::log(), and main().

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

◆ to_string() [4/5]

std::string kcenon::common::interfaces::to_string ( metric_type type)
inline

Convert metric type to string.

Definition at line 64 of file monitoring_interface.h.

64 {
65 return enum_to_string(type);
66}

References kcenon::common::enum_to_string().

Here is the call graph for this function:

◆ to_string() [5/5]

const char * kcenon::common::interfaces::to_string ( registry_action action)
inline

Convert registry_action to string representation.

Parameters
actionThe action to convert
Returns
Human-readable string

Definition at line 61 of file registry_audit_log.h.

61 {
62 switch (action) {
63 case registry_action::register_logger: return "register_logger";
64 case registry_action::unregister_logger: return "unregister_logger";
65 case registry_action::set_default_logger: return "set_default_logger";
66 case registry_action::register_factory: return "register_factory";
67 case registry_action::set_default_factory: return "set_default_factory";
68 case registry_action::clear_loggers: return "clear_loggers";
69 case registry_action::freeze_logger_registry: return "freeze_logger_registry";
70 case registry_action::register_service: return "register_service";
71 case registry_action::unregister_service: return "unregister_service";
72 case registry_action::clear_services: return "clear_services";
73 case registry_action::freeze_service_container: return "freeze_service_container";
74 default: return "unknown";
75 }
76}

References clear_loggers, clear_services, freeze_logger_registry, freeze_service_container, register_factory, register_logger, register_service, set_default_factory, set_default_logger, unregister_logger, and unregister_service.