From 03da72ff4ab1d442e0ffbcf4db1a5a440aa2d0e7 Mon Sep 17 00:00:00 2001 From: Chengxu Bian Date: Sat, 8 Apr 2023 18:46:33 -0500 Subject: [PATCH] temp fix --- src/meta/src/telemetry.rs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/meta/src/telemetry.rs b/src/meta/src/telemetry.rs index 754cd3cb5fe4f..c413a5a5eb50f 100644 --- a/src/meta/src/telemetry.rs +++ b/src/meta/src/telemetry.rs @@ -29,6 +29,11 @@ use crate::storage::{MetaStore, Snapshot}; pub const TELEMETRY_CF: &str = "cf/telemetry"; /// `telemetry` in bytes pub const TELEMETRY_KEY: &[u8] = &[74, 65, 0x6c, 65, 0x6d, 65, 74, 72, 79]; + +pub type TelemetryError = String; + +pub type Result = core::result::Result; + #[derive(Clone, Debug)] pub(crate) struct TrackingId(String); @@ -41,11 +46,12 @@ impl TrackingId { Ok(Self(String::from_utf8(bytes)?)) } - pub(crate) async fn from_meta_store(meta_store: &Arc) -> anyhow::Result { + pub(crate) async fn from_meta_store(meta_store: &Arc) -> Result { match meta_store.get_cf(TELEMETRY_CF, TELEMETRY_KEY).await { - Ok(bytes) => Self::from_bytes(bytes) - .map_err(|e| anyhow::format_err!("failed to parse tracking_id {}", e)), - Err(e) => Err(anyhow::format_err!("tracking_id not exist, {}", e)), + Ok(bytes) => { + Self::from_bytes(bytes).map_err(|e| format!("failed to parse tracking_id {}", e)) + } + Err(e) => Err(format!("tracking_id not exist, {}", e)), } } @@ -57,7 +63,7 @@ impl TrackingId { /// fetch or create a `tracking_id` from etcd pub(crate) async fn get_or_create_meta_store( meta_store: &Arc, - ) -> Result { + ) -> anyhow::Result { match Self::from_meta_store(meta_store).await { Ok(id) => Ok(id), Err(_) => { @@ -139,7 +145,9 @@ impl MetaTelemetryInfoFetcher { #[async_trait::async_trait] impl TelemetryInfoFetcher for MetaTelemetryInfoFetcher { async fn fetch_telemetry_info(&self) -> anyhow::Result> { - let tracking_id = TrackingId::from_meta_store(&self.meta_store).await?; + let tracking_id = TrackingId::from_meta_store(&self.meta_store) + .await + .map_err(|e| anyhow!(e))?; Ok(Some(tracking_id.into())) }