From 5cb4d9a78d9541aad45df26bd9b9defe777af25f Mon Sep 17 00:00:00 2001 From: Zhang Jingqiang Date: Tue, 14 Jan 2025 23:31:51 +0800 Subject: [PATCH] rename MetricsTag to MetricTag --- g3keymess/src/control/capnp/proc.rs | 6 ++--- g3keymess/src/control/capnp/server.rs | 6 ++--- g3keymess/src/serve/server.rs | 4 +-- lib/g3-types/src/metrics/mod.rs | 2 +- lib/g3-types/src/metrics/tag.rs | 37 ++++++++++++--------------- lib/g3-yaml/src/value/metrics.rs | 6 ++--- 6 files changed, 29 insertions(+), 32 deletions(-) diff --git a/g3keymess/src/control/capnp/proc.rs b/g3keymess/src/control/capnp/proc.rs index 346913f58..97628d1a2 100644 --- a/g3keymess/src/control/capnp/proc.rs +++ b/g3keymess/src/control/capnp/proc.rs @@ -20,7 +20,7 @@ use anyhow::anyhow; use capnp::capability::Promise; use capnp_rpc::pry; -use g3_types::metrics::{MetricsTagName, MetricsTagValue}; +use g3_types::metrics::{MetricTagName, MetricTagValue}; use g3keymess_proto::proc_capnp::proc_control; use g3keymess_proto::server_capnp::server_control; @@ -161,9 +161,9 @@ impl proc_control::Server for ProcControlImpl { fn do_add_metrics_tag(name: &str, value: &str) -> anyhow::Result<()> { let name = - MetricsTagName::from_str(name).map_err(|e| anyhow!("invalid metrics tag name: {e}"))?; + MetricTagName::from_str(name).map_err(|e| anyhow!("invalid metrics tag name: {e}"))?; let value = - MetricsTagValue::from_str(value).map_err(|e| anyhow!("invalid metrics tag value: {e}"))?; + MetricTagValue::from_str(value).map_err(|e| anyhow!("invalid metrics tag value: {e}"))?; // add for server metrics crate::serve::foreach_server(|_, s| { diff --git a/g3keymess/src/control/capnp/server.rs b/g3keymess/src/control/capnp/server.rs index fdbbcd2ac..147503c46 100644 --- a/g3keymess/src/control/capnp/server.rs +++ b/g3keymess/src/control/capnp/server.rs @@ -21,7 +21,7 @@ use anyhow::anyhow; use capnp::capability::Promise; use capnp_rpc::pry; -use g3_types::metrics::{MetricsTagName, MetricsTagValue, NodeName}; +use g3_types::metrics::{MetricTagName, MetricTagValue, NodeName}; use g3keymess_proto::server_capnp::server_control; @@ -41,8 +41,8 @@ impl ServerControlImpl { fn do_add_metrics_tag(&self, name: &str, value: &str) -> anyhow::Result<()> { let name = - MetricsTagName::from_str(name).map_err(|e| anyhow!("invalid metrics tag name: {e}"))?; - let value = MetricsTagValue::from_str(value) + MetricTagName::from_str(name).map_err(|e| anyhow!("invalid metrics tag name: {e}"))?; + let value = MetricTagValue::from_str(value) .map_err(|e| anyhow!("invalid metrics tag value: {e}"))?; self.server.add_dynamic_metrics_tag(name, value); Ok(()) diff --git a/g3keymess/src/serve/server.rs b/g3keymess/src/serve/server.rs index c6902f089..afa59a841 100644 --- a/g3keymess/src/serve/server.rs +++ b/g3keymess/src/serve/server.rs @@ -26,7 +26,7 @@ use tokio::sync::{broadcast, Semaphore}; use g3_daemon::listen::ListenStats; use g3_daemon::server::ServerQuitPolicy; -use g3_types::metrics::{MetricsTagName, MetricsTagValue, NodeName, StaticMetricsTags}; +use g3_types::metrics::{MetricTagName, MetricTagValue, NodeName, StaticMetricsTags}; use super::{ KeyServerDurationRecorder, KeyServerDurationStats, KeyServerRuntime, KeyServerStats, @@ -164,7 +164,7 @@ impl KeyServer { self.prepare_reload(config) } - pub(crate) fn add_dynamic_metrics_tag(&self, name: MetricsTagName, value: MetricsTagValue) { + pub(crate) fn add_dynamic_metrics_tag(&self, name: MetricTagName, value: MetricTagValue) { let dynamic_tags = self.dynamic_metrics_tags.load(); let mut dynamic_tags = dynamic_tags.as_ref().clone(); dynamic_tags.insert(name, value); diff --git a/lib/g3-types/src/metrics/mod.rs b/lib/g3-types/src/metrics/mod.rs index b0b08c57b..dea9981ad 100644 --- a/lib/g3-types/src/metrics/mod.rs +++ b/lib/g3-types/src/metrics/mod.rs @@ -20,7 +20,7 @@ mod name; pub use name::NodeName; mod tag; -pub use tag::{MetricsTagName, MetricsTagValue, StaticMetricsTags}; +pub use tag::{MetricTagName, MetricTagValue, StaticMetricsTags}; #[derive(Debug, Error)] pub enum ParseError { diff --git a/lib/g3-types/src/metrics/tag.rs b/lib/g3-types/src/metrics/tag.rs index 6d117759e..bc6966b26 100644 --- a/lib/g3-types/src/metrics/tag.rs +++ b/lib/g3-types/src/metrics/tag.rs @@ -23,64 +23,64 @@ use smol_str::SmolStr; use super::{chars_allowed_in_opentsdb, ParseError}; #[derive(Clone, Debug, PartialEq, PartialOrd, Eq, Ord)] -pub struct MetricsTagName(SmolStr); +pub struct MetricTagName(SmolStr); #[derive(Clone, Debug, Eq, PartialEq)] -pub struct MetricsTagValue(SmolStr); +pub struct MetricTagValue(SmolStr); -pub type StaticMetricsTags = BTreeMap; +pub type StaticMetricsTags = BTreeMap; -impl MetricsTagName { +impl MetricTagName { #[inline] pub fn as_str(&self) -> &str { self.0.as_str() } } -impl AsRef for MetricsTagName { +impl AsRef for MetricTagName { fn as_ref(&self) -> &str { self.as_str() } } -impl FromStr for MetricsTagName { +impl FromStr for MetricTagName { type Err = ParseError; fn from_str(s: &str) -> Result { chars_allowed_in_opentsdb(s)?; - Ok(MetricsTagName(s.into())) + Ok(MetricTagName(s.into())) } } -impl fmt::Display for MetricsTagName { +impl fmt::Display for MetricTagName { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str(self.as_str()) } } -impl MetricsTagValue { +impl MetricTagValue { #[inline] pub fn as_str(&self) -> &str { self.0.as_str() } } -impl AsRef for MetricsTagValue { +impl AsRef for MetricTagValue { fn as_ref(&self) -> &str { self.as_str() } } -impl FromStr for MetricsTagValue { +impl FromStr for MetricTagValue { type Err = ParseError; fn from_str(s: &str) -> Result { chars_allowed_in_opentsdb(s)?; - Ok(MetricsTagValue(s.into())) + Ok(MetricTagValue(s.into())) } } -impl fmt::Display for MetricsTagValue { +impl fmt::Display for MetricTagValue { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str(self.as_str()) } @@ -92,18 +92,15 @@ mod tests { #[test] fn t_metrics_name() { - assert_eq!(MetricsTagName::from_str("abc-1").unwrap().as_str(), "abc-1"); + assert_eq!(MetricTagName::from_str("abc-1").unwrap().as_str(), "abc-1"); - assert!(MetricsTagName::from_str("a=b").is_err()); + assert!(MetricTagName::from_str("a=b").is_err()); } #[test] fn t_metrics_value() { - assert_eq!( - MetricsTagValue::from_str("abc-1").unwrap().as_str(), - "abc-1" - ); + assert_eq!(MetricTagValue::from_str("abc-1").unwrap().as_str(), "abc-1"); - assert!(MetricsTagValue::from_str("a=b").is_err()); + assert!(MetricTagValue::from_str("a=b").is_err()); } } diff --git a/lib/g3-yaml/src/value/metrics.rs b/lib/g3-yaml/src/value/metrics.rs index 9159113b7..d59cb05cd 100644 --- a/lib/g3-yaml/src/value/metrics.rs +++ b/lib/g3-yaml/src/value/metrics.rs @@ -21,7 +21,7 @@ use anyhow::{anyhow, Context}; use yaml_rust::Yaml; use g3_types::collection::WeightedValue; -use g3_types::metrics::{MetricsTagName, MetricsTagValue, NodeName, StaticMetricsTags}; +use g3_types::metrics::{MetricTagName, MetricTagValue, NodeName, StaticMetricsTags}; pub fn as_metrics_name(v: &Yaml) -> anyhow::Result { if let Yaml::String(s) = v { @@ -38,9 +38,9 @@ pub fn as_static_metrics_tags(v: &Yaml) -> anyhow::Result { if let Yaml::Hash(map) = v { let mut tags = BTreeMap::new(); crate::foreach_kv(map, |k, v| { - let name = MetricsTagName::from_str(k).context("invalid metrics tag name")?; + let name = MetricTagName::from_str(k).context("invalid metrics tag name")?; let value_s = crate::value::as_string(v).context("invalid metrics tag yaml value")?; - let value = MetricsTagValue::from_str(&value_s).context("invalid metrics tag value")?; + let value = MetricTagValue::from_str(&value_s).context("invalid metrics tag value")?; if tags.insert(name, value).is_some() { Err(anyhow!("found duplicate value for tag name {k}"))