31 std::string
get_name()
const override {
return "app_liveness"; }
38 result.
status = health_status::healthy;
39 result.
message =
"Application is running";
50 std::string
get_name()
const override {
return "cache_readiness"; }
56 return std::chrono::milliseconds(2000);
64 result.
status = health_status::healthy;
65 result.
message =
"Cache is warmed";
69 result.
status = health_status::degraded;
70 result.
message =
"Cache warming in progress";
85 std::string
get_name()
const override {
return "database"; }
94 result.
status = health_status::healthy;
95 result.
message =
"Database connected";
99 result.
status = health_status::unhealthy;
100 result.
message =
"Database connection failed";
113 case health_status::healthy:
115 case health_status::degraded:
117 case health_status::unhealthy:
126 std::cout <<
"=== Health Check Example ===\n\n";
129 std::cout <<
"1. Health check types:\n";
130 std::cout <<
" liveness -> \"" <<
to_string(health_check_type::liveness) <<
"\"\n";
131 std::cout <<
" readiness -> \"" <<
to_string(health_check_type::readiness) <<
"\"\n";
132 std::cout <<
" dependency -> \"" <<
to_string(health_check_type::dependency) <<
"\"\n";
137 std::cout <<
" \"readiness\" -> " <<
to_string(parsed.value()) <<
"\n";
141 std::cout <<
"\n2. Running health checks:\n";
142 std::vector<std::unique_ptr<health_check>> checks;
143 checks.push_back(std::make_unique<app_liveness_check>());
144 checks.push_back(std::make_unique<cache_readiness_check>(
true));
145 checks.push_back(std::make_unique<database_dependency_check>(
true));
147 bool all_healthy =
true;
148 for (
const auto& hc : checks)
150 auto result = hc->check();
151 std::cout <<
" [" <<
to_string(hc->get_type()) <<
"] " << hc->get_name() <<
": "
153 <<
" (critical=" << (hc->is_critical() ?
"yes" :
"no")
154 <<
", timeout=" << hc->get_timeout().count() <<
"ms)\n";
156 if (result.status == health_status::unhealthy && hc->is_critical())
162 std::cout <<
"\n Overall: " << (all_healthy ?
"HEALTHY" :
"UNHEALTHY") <<
"\n";
165 std::cout <<
"\n3. Simulating database failure:\n";
167 auto result = db_down.
check();
169 << result.message <<
"\n";
171 std::cout <<
"\nDone.\n";
bool is_critical() const override
Check if this health check is critical.
std::string get_name() const override
Get the unique name of this health check.
health_check_type get_type() const override
Get the type of this health check.
health_check_result check() override
Perform the health check.
health_check_result check() override
Perform the health check.
cache_readiness_check(bool warmed)
bool is_critical() const override
Check if this health check is critical.
std::string get_name() const override
Get the unique name of this health check.
std::chrono::milliseconds get_timeout() const override
Get timeout duration for this health check.
health_check_type get_type() const override
Get the type of this health check.
bool is_critical() const override
Check if this health check is critical.
health_check_result check() override
Perform the health check.
health_check_type get_type() const override
Get the type of this health check.
database_dependency_check(bool connected)
std::string get_name() const override
Get the unique name of this health check.
Abstract base class for health checks.
Base classes and types for health checking functionality.
std::string status_string(health_status status)
health_status
Standard health status levels.
Result< health_check_type > health_check_type_from_string(const std::string &str)
Convert string to health check type.
health_check_type
Types of health checks supported by the system.
std::string to_string(log_level level)
Convert log level to string.
Umbrella header for Result<T> type and related utilities.
Result of a health check operation.