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>
47 "cluster_nodes_total_number",
49 "Total number of nodes this node can detect in the cluster."
52 "cluster_communication_is_healthy",
54 "Whether cluster communication service is operating healthy (1 - healthy, 0 - we have a problem)"
58 boost::asio::thread_pool ctx_{1};
59 boost::asio::strand<boost::asio::thread_pool::executor_type> strand_ = boost::asio::make_strand(ctx_);
63 std::shared_ptr<data::BackendInterface> backend_;
65 std::chrono::steady_clock::duration readInterval_;
66 std::chrono::steady_clock::duration writeInterval_;
69 std::vector<ClioNode> otherNodesData_;
71 bool stopped_ =
false;
74 static constexpr std::chrono::milliseconds kDEFAULT_READ_INTERVAL{2100};
75 static constexpr std::chrono::milliseconds kDEFAULT_WRITE_INTERVAL{1200};
84 std::shared_ptr<data::BackendInterface> backend,
85 std::chrono::steady_clock::duration readInterval = kDEFAULT_READ_INTERVAL,
86 std::chrono::steady_clock::duration writeInterval = kDEFAULT_WRITE_INTERVAL
115 std::shared_ptr<boost::uuids::uuid>
131 std::expected<std::vector<ClioNode>, std::string>
136 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:33
Service to post and read messages to/from the cluster. It uses a backend to communicate with the clus...
Definition ClusterCommunicationService.hpp:45
std::shared_ptr< boost::uuids::uuid > selfUuid() const
Get the UUID of the current node.
Definition ClusterCommunicationService.cpp:101
void run()
Start the service.
Definition ClusterCommunicationService.cpp:63
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:45
std::expected< std::vector< ClioNode >, std::string > clusterData() const override
Get the data of all nodes in the cluster (including self).
Definition ClusterCommunicationService.cpp:116
void stop()
Stop the service.
Definition ClusterCommunicationService.cpp:90
ClioNode selfData() const override
Get the data of the current node.
Definition ClusterCommunicationService.cpp:108
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