|
Common System 0.2.0
Common interfaces and patterns for system integration
|
Manages dependencies between health checks as a DAG. More...
#include <health_dependency_graph.h>

Public Member Functions | |
| health_dependency_graph ()=default | |
| ~health_dependency_graph ()=default | |
| health_dependency_graph (const health_dependency_graph &)=delete | |
| health_dependency_graph & | operator= (const health_dependency_graph &)=delete |
| health_dependency_graph (health_dependency_graph &&)=delete | |
| health_dependency_graph & | operator= (health_dependency_graph &&)=delete |
| Result< bool > | add_node (const std::string &name, std::shared_ptr< health_check > check) |
| Add a health check node to the graph. | |
| Result< bool > | remove_node (const std::string &name) |
| Remove a health check node from the graph. | |
| Result< bool > | add_dependency (const std::string &dependent, const std::string &dependency) |
| Add a dependency between two nodes. | |
| Result< bool > | remove_dependency (const std::string &dependent, const std::string &dependency) |
| Remove a dependency between two nodes. | |
| std::set< std::string > | get_dependencies (const std::string &name) const |
| Get all dependencies of a node. | |
| std::set< std::string > | get_dependents (const std::string &name) const |
| Get all nodes that depend on a given node. | |
| bool | would_create_cycle (const std::string &from, const std::string &to) const |
| Check if adding a dependency would create a cycle. | |
| Result< std::vector< std::string > > | topological_sort () const |
| Get topological sort of all nodes. | |
| Result< health_check_result > | check_with_dependencies (const std::string &name) |
| Execute health check with its dependencies. | |
| std::set< std::string > | get_failure_impact (const std::string &name) const |
| Get the impact of a node failure. | |
| bool | has_node (const std::string &name) const |
| Check if a node exists. | |
| std::size_t | size () const |
| Get number of nodes. | |
| bool | empty () const |
| Check if graph is empty. | |
| void | clear () |
| Clear all nodes and dependencies. | |
| std::vector< std::string > | get_all_nodes () const |
| Get all node names. | |
Private Member Functions | |
| bool | would_create_cycle_internal (const std::string &from, const std::string &to) const |
| Result< health_check_result > | check_with_dependencies_internal (const std::string &name, std::unordered_map< std::string, health_check_result > &results) |
Private Attributes | |
| std::unordered_map< std::string, std::shared_ptr< health_check > > | nodes_ |
| std::unordered_map< std::string, std::set< std::string > > | dependencies_ |
| std::unordered_map< std::string, std::set< std::string > > | dependents_ |
| std::mutex | mutex_ |
Manages dependencies between health checks as a DAG.
This class allows defining dependencies between health checks and executing them in the correct order. It supports cycle detection and topological sorting for proper execution order.
Example usage:
Definition at line 54 of file health_dependency_graph.h.
|
default |
|
default |
|
delete |
|
delete |
|
inline |
Add a dependency between two nodes.
| dependent | The node that depends on another |
| dependency | The node being depended upon |
Definition at line 124 of file health_dependency_graph.h.
References dependencies_, kcenon::common::interfaces::dependency, dependents_, mutex_, nodes_, kcenon::common::ok(), and would_create_cycle_internal().
Referenced by kcenon::common::interfaces::health_monitor::add_dependency().


|
inline |
Add a health check node to the graph.
| name | Unique name for this node |
| check | Health check implementation |
Definition at line 70 of file health_dependency_graph.h.
References dependencies_, dependents_, mutex_, nodes_, and kcenon::common::ok().
Referenced by kcenon::common::interfaces::health_monitor::register_check().


|
inline |
Execute health check with its dependencies.
| name | Name of the node to check |
This method first checks all dependencies recursively. If any dependency fails with unhealthy status, the dependent check is marked as unhealthy without executing it.
Definition at line 271 of file health_dependency_graph.h.
References check_with_dependencies_internal(), mutex_, and nodes_.
Referenced by kcenon::common::interfaces::health_monitor::check(), and kcenon::common::interfaces::health_monitor::refresh().


|
inlineprivate |
Definition at line 400 of file health_dependency_graph.h.
References check_with_dependencies_internal(), dependencies_, kcenon::common::interfaces::health_check_result::message, kcenon::common::interfaces::health_check_result::metadata, nodes_, kcenon::common::ok(), kcenon::common::interfaces::health_check_result::status, and kcenon::common::interfaces::unhealthy.
Referenced by check_with_dependencies(), and check_with_dependencies_internal().


|
inline |
Clear all nodes and dependencies.
Definition at line 344 of file health_dependency_graph.h.
References dependencies_, dependents_, mutex_, and nodes_.
|
inlinenodiscard |
|
inlinenodiscard |
Get all node names.
Definition at line 355 of file health_dependency_graph.h.
References mutex_, and nodes_.
Referenced by kcenon::common::interfaces::health_monitor::get_check_names(), and kcenon::common::interfaces::health_monitor::refresh().

|
inlinenodiscard |
Get all dependencies of a node.
| name | Node name |
Definition at line 176 of file health_dependency_graph.h.
References dependencies_, and mutex_.
|
inlinenodiscard |
Get all nodes that depend on a given node.
| name | Node name |
Definition at line 191 of file health_dependency_graph.h.
References dependents_, and mutex_.
|
inlinenodiscard |
Get the impact of a node failure.
| name | Name of the failed node |
Definition at line 288 of file health_dependency_graph.h.
References dependents_, and mutex_.
|
inlinenodiscard |
Check if a node exists.
| name | Node name |
Definition at line 318 of file health_dependency_graph.h.
References mutex_, and nodes_.
Referenced by kcenon::common::interfaces::health_monitor::has_check().

|
delete |
|
delete |
|
inline |
Remove a dependency between two nodes.
| dependent | The dependent node |
| dependency | The dependency node |
Definition at line 155 of file health_dependency_graph.h.
References dependencies_, kcenon::common::interfaces::dependency, dependents_, mutex_, nodes_, and kcenon::common::ok().

|
inline |
Remove a health check node from the graph.
| name | Name of the node to remove |
Definition at line 96 of file health_dependency_graph.h.
References dependencies_, dependents_, mutex_, nodes_, and kcenon::common::ok().
Referenced by kcenon::common::interfaces::health_monitor::unregister_check().


|
inlinenodiscard |
|
inlinenodiscard |
Get topological sort of all nodes.
Definition at line 216 of file health_dependency_graph.h.
References dependencies_, dependents_, mutex_, nodes_, and kcenon::common::ok().

|
inlinenodiscard |
Check if adding a dependency would create a cycle.
| from | Source node |
| to | Target node |
Definition at line 207 of file health_dependency_graph.h.
References mutex_, and would_create_cycle_internal().

|
inlinenodiscardprivate |
Definition at line 366 of file health_dependency_graph.h.
References dependencies_.
Referenced by add_dependency(), and would_create_cycle().

|
private |
Definition at line 448 of file health_dependency_graph.h.
Referenced by add_dependency(), add_node(), check_with_dependencies_internal(), clear(), get_dependencies(), remove_dependency(), remove_node(), topological_sort(), and would_create_cycle_internal().
|
private |
Definition at line 449 of file health_dependency_graph.h.
Referenced by add_dependency(), add_node(), clear(), get_dependents(), get_failure_impact(), remove_dependency(), remove_node(), and topological_sort().
|
mutableprivate |
Definition at line 450 of file health_dependency_graph.h.
Referenced by add_dependency(), add_node(), check_with_dependencies(), clear(), empty(), get_all_nodes(), get_dependencies(), get_dependents(), get_failure_impact(), has_node(), remove_dependency(), remove_node(), size(), topological_sort(), and would_create_cycle().
|
private |
Definition at line 447 of file health_dependency_graph.h.
Referenced by add_dependency(), add_node(), check_with_dependencies(), check_with_dependencies_internal(), clear(), empty(), get_all_nodes(), has_node(), remove_dependency(), remove_node(), size(), and topological_sort().