aboutsummaryrefslogtreecommitdiff
path: root/src/rpc
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2023-01-11 17:09:37 +0100
committerAlex Auvolat <alex@adnab.me>2023-01-11 17:09:37 +0100
commitdac254a6e7413498df0e3b626769c2d2be3a4cfb (patch)
tree3eca3ebc2d0c1f9c2c5029e3197bcc925eeafcfd /src/rpc
parent638c5a3ce006eba9d90a6358655ba2091423efd7 (diff)
parent94d723f27cea7aa58d11af3e18a165283b40f19a (diff)
downloadgarage-dac254a6e7413498df0e3b626769c2d2be3a4cfb.tar.gz
garage-dac254a6e7413498df0e3b626769c2d2be3a4cfb.zip
Merge branch 'main' into k2v-watch-range-2
Diffstat (limited to 'src/rpc')
-rw-r--r--src/rpc/lib.rs2
-rw-r--r--src/rpc/system.rs10
-rw-r--r--src/rpc/system_metrics.rs33
3 files changed, 45 insertions, 0 deletions
diff --git a/src/rpc/lib.rs b/src/rpc/lib.rs
index 86f63568..a8cc0030 100644
--- a/src/rpc/lib.rs
+++ b/src/rpc/lib.rs
@@ -17,3 +17,5 @@ mod metrics;
pub mod rpc_helper;
pub use rpc_helper::*;
+
+pub mod system_metrics;
diff --git a/src/rpc/system.rs b/src/rpc/system.rs
index ed10aa4b..90f6a4c2 100644
--- a/src/rpc/system.rs
+++ b/src/rpc/system.rs
@@ -38,6 +38,9 @@ use crate::replication_mode::*;
use crate::ring::*;
use crate::rpc_helper::*;
+#[cfg(feature = "metrics")]
+use crate::system_metrics::*;
+
const DISCOVERY_INTERVAL: Duration = Duration::from_secs(60);
const STATUS_EXCHANGE_INTERVAL: Duration = Duration::from_secs(10);
@@ -103,6 +106,8 @@ pub struct System {
consul_discovery: Option<ConsulDiscovery>,
#[cfg(feature = "kubernetes-discovery")]
kubernetes_discovery: Option<KubernetesDiscoveryConfig>,
+ #[cfg(feature = "metrics")]
+ metrics: SystemMetrics,
replication_mode: ReplicationMode,
replication_factor: usize,
@@ -275,6 +280,9 @@ impl System {
cluster_layout_staging_hash: cluster_layout.staging_hash,
};
+ #[cfg(feature = "metrics")]
+ let metrics = SystemMetrics::new(replication_factor);
+
let ring = Ring::new(cluster_layout, replication_factor);
let (update_ring, ring) = watch::channel(Arc::new(ring));
@@ -365,6 +373,8 @@ impl System {
consul_discovery,
#[cfg(feature = "kubernetes-discovery")]
kubernetes_discovery: config.kubernetes_discovery.clone(),
+ #[cfg(feature = "metrics")]
+ metrics,
ring,
update_ring: Mutex::new(update_ring),
diff --git a/src/rpc/system_metrics.rs b/src/rpc/system_metrics.rs
new file mode 100644
index 00000000..d96b67e4
--- /dev/null
+++ b/src/rpc/system_metrics.rs
@@ -0,0 +1,33 @@
+use opentelemetry::{global, metrics::*, KeyValue};
+
+/// TableMetrics reference all counter used for metrics
+pub struct SystemMetrics {
+ pub(crate) _garage_build_info: ValueObserver<u64>,
+ pub(crate) _replication_factor: ValueObserver<u64>,
+}
+
+impl SystemMetrics {
+ pub fn new(replication_factor: usize) -> Self {
+ let meter = global::meter("garage_system");
+ Self {
+ _garage_build_info: meter
+ .u64_value_observer("garage_build_info", move |observer| {
+ observer.observe(
+ 1,
+ &[KeyValue::new(
+ "version",
+ garage_util::version::garage_version(),
+ )],
+ )
+ })
+ .with_description("Garage build info")
+ .init(),
+ _replication_factor: meter
+ .u64_value_observer("garage_replication_factor", move |observer| {
+ observer.observe(replication_factor as u64, &[])
+ })
+ .with_description("Garage replication factor setting")
+ .init(),
+ }
+ }
+}