This is an automated email from the ASF dual-hosted git repository.

xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/opendal.git


The following commit(s) were added to refs/heads/main by this push:
     new 833c2018f chore(layer/fastmetrics): upgrade fastmetrics to v0.7.0 
(#7227)
833c2018f is described below

commit 833c2018f6654964a0e1b577240d5b98ed3af588
Author: Qinxuan Chen <[email protected]>
AuthorDate: Thu Feb 26 21:09:40 2026 +0800

    chore(layer/fastmetrics): upgrade fastmetrics to v0.7.0 (#7227)
---
 core/Cargo.lock                    |   4 +-
 core/layers/fastmetrics/Cargo.toml |   2 +-
 core/layers/fastmetrics/src/lib.rs | 110 +++++++++++++++----------------------
 3 files changed, 48 insertions(+), 68 deletions(-)

diff --git a/core/Cargo.lock b/core/Cargo.lock
index 2b82c744e..d8c5d74ac 100644
--- a/core/Cargo.lock
+++ b/core/Cargo.lock
@@ -2995,9 +2995,9 @@ dependencies = [
 
 [[package]]
 name = "fastmetrics"
-version = "0.6.0"
+version = "0.7.0"
 source = "registry+https://github.com/rust-lang/crates.io-index";
-checksum = "06ad55eb18b0326516b75e7ff961ad85033154e82265e7819f77acf38a500acb"
+checksum = "690d70a0753d057db438a7deb0dc67f0e50a28b3204812abd94c6e9e6a027cce"
 dependencies = [
  "anyhow",
  "cfg-if",
diff --git a/core/layers/fastmetrics/Cargo.toml 
b/core/layers/fastmetrics/Cargo.toml
index 8d8eba921..da0cefd3e 100644
--- a/core/layers/fastmetrics/Cargo.toml
+++ b/core/layers/fastmetrics/Cargo.toml
@@ -31,7 +31,7 @@ version = { workspace = true }
 all-features = true
 
 [dependencies]
-fastmetrics = "0.6"
+fastmetrics = "0.7"
 opendal-core = { path = "../../core", version = "0.55.0", default-features = 
false }
 opendal-layer-observe-metrics-common = { path = "../observe-metrics-common", 
version = "0.55.0", default-features = false }
 
diff --git a/core/layers/fastmetrics/src/lib.rs 
b/core/layers/fastmetrics/src/lib.rs
index 3bde49b1f..257452078 100644
--- a/core/layers/fastmetrics/src/lib.rs
+++ b/core/layers/fastmetrics/src/lib.rs
@@ -24,7 +24,6 @@ use fastmetrics::encoder::EncodeLabelSet;
 use fastmetrics::encoder::LabelSetEncoder;
 use fastmetrics::metrics::counter::Counter;
 use fastmetrics::metrics::family::Family;
-use fastmetrics::metrics::family::MetricFactory;
 use fastmetrics::metrics::gauge::Gauge;
 use fastmetrics::metrics::histogram::Histogram;
 use fastmetrics::raw::LabelSetSchema;
@@ -42,7 +41,8 @@ use opendal_layer_observe_metrics_common as observe;
 /// ## Basic Usage
 ///
 /// ```no_run
-/// # use fastmetrics::format::text;
+/// # use fastmetrics::format::text::encode;
+/// # use fastmetrics::format::text::TextProfile;
 /// # use log::info;
 /// # use opendal_core::services;
 /// # use opendal_core::Operator;
@@ -69,7 +69,7 @@ use opendal_layer_observe_metrics_common as observe;
 ///
 /// // Export prometheus metrics.
 /// let mut output = String::new();
-/// text::encode(&mut output, &registry).unwrap();
+/// encode(&mut output, &registry, TextProfile::PrometheusV0_0_4).unwrap();
 /// println!("{}", output);
 /// # Ok(())
 /// # }
@@ -87,7 +87,8 @@ use opendal_layer_observe_metrics_common as observe;
 /// ```no_run
 /// # use std::sync::OnceLock;
 /// #
-/// # use fastmetrics::format::text;
+/// # use fastmetrics::format::text::encode;
+/// # use fastmetrics::format::text::TextProfile;
 /// # use fastmetrics::registry::with_global_registry;
 /// # use log::info;
 /// # use opendal_core::services;
@@ -123,7 +124,7 @@ use opendal_layer_observe_metrics_common as observe;
 ///
 /// // Export prometheus metrics.
 /// let mut output = String::new();
-/// with_global_registry(|registry| text::encode(&mut output, 
&registry).unwrap());
+/// with_global_registry(|reg| encode(&mut output, &reg, 
TextProfile::PrometheusV0_0_4).unwrap());
 /// println!("{}", output);
 /// # Ok(())
 /// # }
@@ -250,46 +251,36 @@ impl FastmetricsLayerBuilder {
     /// # }
     /// ```
     pub fn register(self, registry: &mut Registry) -> Result<FastmetricsLayer> 
{
-        let operation_bytes = Family::new(HistogramFactory {
-            buckets: self.bytes_buckets.clone(),
-        });
-        let operation_bytes_rate = Family::new(HistogramFactory {
-            buckets: self.bytes_rate_buckets.clone(),
-        });
-        let operation_entries = Family::new(HistogramFactory {
-            buckets: self.entries_buckets.clone(),
-        });
-        let operation_entries_rate = Family::new(HistogramFactory {
-            buckets: self.entries_rate_buckets.clone(),
-        });
-        let operation_duration_seconds = Family::new(HistogramFactory {
-            buckets: self.duration_seconds_buckets.clone(),
-        });
+        let Self {
+            bytes_buckets,
+            bytes_rate_buckets,
+            entries_buckets,
+            entries_rate_buckets,
+            duration_seconds_buckets,
+            ttfb_buckets,
+            disable_label_root,
+        } = self;
+
+        let new_hist_family = |buckets: Vec<f64>| -> Family<OperationLabels, 
Histogram> {
+            Family::new(move || Histogram::new(buckets.iter().copied()))
+        };
+
+        let operation_bytes = new_hist_family(bytes_buckets.clone());
+        let operation_bytes_rate = new_hist_family(bytes_rate_buckets.clone());
+        let operation_entries = new_hist_family(entries_buckets);
+        let operation_entries_rate = new_hist_family(entries_rate_buckets);
+        let operation_duration_seconds = 
new_hist_family(duration_seconds_buckets.clone());
         let operation_errors_total = Family::default();
         let operation_executing = Family::default();
-        let operation_ttfb_seconds = Family::new(HistogramFactory {
-            buckets: self.ttfb_buckets.clone(),
-        });
+        let operation_ttfb_seconds = new_hist_family(ttfb_buckets);
 
         let http_executing = Family::default();
-        let http_request_bytes = Family::new(HistogramFactory {
-            buckets: self.bytes_buckets.clone(),
-        });
-        let http_request_bytes_rate = Family::new(HistogramFactory {
-            buckets: self.bytes_rate_buckets.clone(),
-        });
-        let http_request_duration_seconds = Family::new(HistogramFactory {
-            buckets: self.duration_seconds_buckets.clone(),
-        });
-        let http_response_bytes = Family::new(HistogramFactory {
-            buckets: self.bytes_buckets.clone(),
-        });
-        let http_response_bytes_rate = Family::new(HistogramFactory {
-            buckets: self.bytes_rate_buckets.clone(),
-        });
-        let http_response_duration_seconds = Family::new(HistogramFactory {
-            buckets: self.duration_seconds_buckets.clone(),
-        });
+        let http_request_bytes = new_hist_family(bytes_buckets.clone());
+        let http_request_bytes_rate = 
new_hist_family(bytes_rate_buckets.clone());
+        let http_request_duration_seconds = 
new_hist_family(duration_seconds_buckets.clone());
+        let http_response_bytes = new_hist_family(bytes_buckets);
+        let http_response_bytes_rate = new_hist_family(bytes_rate_buckets);
+        let http_response_duration_seconds = 
new_hist_family(duration_seconds_buckets);
         let http_connection_errors_total = Family::default();
         let http_status_errors_total = Family::default();
 
@@ -313,7 +304,7 @@ impl FastmetricsLayerBuilder {
             http_connection_errors_total,
             http_status_errors_total,
 
-            disable_label_root: self.disable_label_root,
+            disable_label_root,
         };
         interceptor
             .register(registry)
@@ -346,36 +337,25 @@ impl FastmetricsLayerBuilder {
     }
 }
 
-#[derive(Clone)]
-struct HistogramFactory {
-    buckets: Vec<f64>,
-}
-
-impl MetricFactory<Histogram> for HistogramFactory {
-    fn new_metric(&self) -> Histogram {
-        Histogram::new(self.buckets.iter().cloned())
-    }
-}
-
 #[doc(hidden)]
 #[derive(Clone, Debug)]
 pub struct FastmetricsInterceptor {
-    operation_bytes: Family<OperationLabels, Histogram, HistogramFactory>,
-    operation_bytes_rate: Family<OperationLabels, Histogram, HistogramFactory>,
-    operation_entries: Family<OperationLabels, Histogram, HistogramFactory>,
-    operation_entries_rate: Family<OperationLabels, Histogram, 
HistogramFactory>,
-    operation_duration_seconds: Family<OperationLabels, Histogram, 
HistogramFactory>,
+    operation_bytes: Family<OperationLabels, Histogram>,
+    operation_bytes_rate: Family<OperationLabels, Histogram>,
+    operation_entries: Family<OperationLabels, Histogram>,
+    operation_entries_rate: Family<OperationLabels, Histogram>,
+    operation_duration_seconds: Family<OperationLabels, Histogram>,
     operation_errors_total: Family<OperationLabels, Counter>,
     operation_executing: Family<OperationLabels, Gauge>,
-    operation_ttfb_seconds: Family<OperationLabels, Histogram, 
HistogramFactory>,
+    operation_ttfb_seconds: Family<OperationLabels, Histogram>,
 
     http_executing: Family<OperationLabels, Gauge>,
-    http_request_bytes: Family<OperationLabels, Histogram, HistogramFactory>,
-    http_request_bytes_rate: Family<OperationLabels, Histogram, 
HistogramFactory>,
-    http_request_duration_seconds: Family<OperationLabels, Histogram, 
HistogramFactory>,
-    http_response_bytes: Family<OperationLabels, Histogram, HistogramFactory>,
-    http_response_bytes_rate: Family<OperationLabels, Histogram, 
HistogramFactory>,
-    http_response_duration_seconds: Family<OperationLabels, Histogram, 
HistogramFactory>,
+    http_request_bytes: Family<OperationLabels, Histogram>,
+    http_request_bytes_rate: Family<OperationLabels, Histogram>,
+    http_request_duration_seconds: Family<OperationLabels, Histogram>,
+    http_response_bytes: Family<OperationLabels, Histogram>,
+    http_response_bytes_rate: Family<OperationLabels, Histogram>,
+    http_response_duration_seconds: Family<OperationLabels, Histogram>,
     http_connection_errors_total: Family<OperationLabels, Counter>,
     http_status_errors_total: Family<OperationLabels, Counter>,
 

Reply via email to