22#include "cluster/ClioNode.hpp"
23#include "cluster/ClusterCommunicationServiceInterface.hpp"
24#include "data/BackendInterface.hpp"
25#include "util/log/Logger.hpp"
26#include "util/prometheus/Bool.hpp"
27#include "util/prometheus/Gauge.hpp"
28#include "util/prometheus/Prometheus.hpp"
30#include <boost/asio/spawn.hpp>
31#include <boost/asio/strand.hpp>
32#include <boost/asio/thread_pool.hpp>
33#include <boost/uuid/uuid.hpp>
46 "cluster_nodes_total_number",
48 "Total number of nodes this node can detect in the cluster."
51 "cluster_communication_is_healthy",
53 "Whether cluster communicaton service is operating healthy (1 - healthy, 0 - we have a problem)"
57 boost::asio::thread_pool ctx_{1};
58 boost::asio::strand<boost::asio::thread_pool::executor_type> strand_ = boost::asio::make_strand(ctx_);
62 std::shared_ptr<data::BackendInterface> backend_;
64 std::chrono::steady_clock::duration readInterval_;
65 std::chrono::steady_clock::duration writeInterval_;
68 std::vector<ClioNode> otherNodesData_;
70 bool stopped_ =
false;
73 static constexpr std::chrono::milliseconds kDEFAULT_READ_INTERVAL{2100};
74 static constexpr std::chrono::milliseconds kDEFAULT_WRITE_INTERVAL{1200};
83 std::shared_ptr<data::BackendInterface> backend,
84 std::chrono::steady_clock::duration readInterval = kDEFAULT_READ_INTERVAL,
85 std::chrono::steady_clock::duration writeInterval = kDEFAULT_WRITE_INTERVAL
114 std::shared_ptr<boost::uuids::uuid>
130 std::vector<ClioNode>
135 doRead(boost::asio::yield_context yield);
static util::prometheus::Bool boolMetric(std::string name, util::prometheus::Labels labels, std::optional< std::string > description=std::nullopt)
Get a bool based metric. It will be created if it doesn't exist.
Definition Prometheus.cpp:188
static util::prometheus::GaugeInt & gaugeInt(std::string name, util::prometheus::Labels labels, std::optional< std::string > description=std::nullopt)
Get an integer based gauge metric. It will be created if it doesn't exist.
Definition Prometheus.cpp:210
Interface for the cluster communication service.
Definition ClusterCommunicationServiceInterface.hpp:31
Service to post and read messages to/from the cluster. It uses a backend to communicate with the clus...
Definition ClusterCommunicationService.hpp:44
std::shared_ptr< boost::uuids::uuid > selfUuid() const
Get the UUID of the current node.
Definition ClusterCommunicationService.cpp:100
void run()
Start the service.
Definition ClusterCommunicationService.cpp:62
ClusterCommunicationService(std::shared_ptr< data::BackendInterface > backend, std::chrono::steady_clock::duration readInterval=kDEFAULT_READ_INTERVAL, std::chrono::steady_clock::duration writeInterval=kDEFAULT_WRITE_INTERVAL)
Construct a new Cluster Communication Service object.
Definition ClusterCommunicationService.cpp:44
std::vector< ClioNode > clusterData() const override
Get the data of all nodes in the cluster (including self).
Definition ClusterCommunicationService.cpp:115
void stop()
Stop the service.
Definition ClusterCommunicationService.cpp:89
ClioNode selfData() const override
Get the data of the current node.
Definition ClusterCommunicationService.cpp:107
A simple thread-safe logger for the channel specified in the constructor.
Definition Logger.hpp:111
Represents a node in the cluster.
Definition ClioNode.hpp:34
A prometheus gauge metric implementation. It can be increased, decreased or set to a value.
Definition Gauge.hpp:39