diff --git a/proto/telemetry.proto b/proto/telemetry.proto index 3bb23ab96e16c..a362284a2fde6 100644 --- a/proto/telemetry.proto +++ b/proto/telemetry.proto @@ -24,7 +24,7 @@ enum TelemetryClusterType { TELEMETRY_CLUSTER_TYPE_SINGLE_NODE = 1; TELEMETRY_CLUSTER_TYPE_DOCKER_COMPOSE = 2; TELEMETRY_CLUSTER_TYPE_KUBERNETES = 3; - TELEMETRY_CLUSTER_TYPE_HOSTED = 4; + TELEMETRY_CLUSTER_TYPE_CLOUD_HOSTED = 4; } message SystemMemory { diff --git a/src/common/src/telemetry/mod.rs b/src/common/src/telemetry/mod.rs index fd0b68f02a4dc..9cf469af9cd8d 100644 --- a/src/common/src/telemetry/mod.rs +++ b/src/common/src/telemetry/mod.rs @@ -19,6 +19,7 @@ pub mod report; use std::env; use std::time::SystemTime; +use risingwave_pb::telemetry::PbTelemetryClusterType; use serde::{Deserialize, Serialize}; use sysinfo::System; use thiserror_ext::AsReport; @@ -30,45 +31,21 @@ use crate::RW_VERSION; pub const TELEMETRY_CLUSTER_TYPE: &str = "RW_TELEMETRY_TYPE"; pub const TELEMETRY_CLUSTER_TYPE_HOSTED: &str = "hosted"; // hosted on RisingWave Cloud -pub const TELEMETRY_CLUSTER_TYPE_TEST: &str = "test"; // test environment, eg. CI & Risedev pub const TELEMETRY_CLUSTER_TYPE_KUBERNETES: &str = "kubernetes"; pub const TELEMETRY_CLUSTER_TYPE_SINGLE_NODE: &str = "single-node"; pub const TELEMETRY_CLUSTER_TYPE_DOCKER_COMPOSE: &str = "docker-compose"; -#[derive(Debug, Clone, Serialize, Deserialize)] -pub enum TelemetryClusterType { - Hosted, - Test, - DockerCompose, - Kubernetes, - SingleNode, - Unspecified, -} -impl TelemetryClusterType { - pub fn from_env_var() -> Self { - let cluster_type = match env::var(TELEMETRY_CLUSTER_TYPE) { - Ok(cluster_type) => cluster_type, - Err(_) => return Self::Unspecified, - }; - match cluster_type.as_str() { - TELEMETRY_CLUSTER_TYPE_HOSTED => Self::Hosted, - TELEMETRY_CLUSTER_TYPE_DOCKER_COMPOSE => Self::DockerCompose, - TELEMETRY_CLUSTER_TYPE_KUBERNETES => Self::Kubernetes, - TELEMETRY_CLUSTER_TYPE_SINGLE_NODE => Self::SingleNode, - _ => Self::Unspecified, - } - } - - pub fn to_prost(&self) -> risingwave_pb::telemetry::PbTelemetryClusterType { - match self { - Self::Hosted => risingwave_pb::telemetry::PbTelemetryClusterType::Hosted, - Self::DockerCompose => risingwave_pb::telemetry::PbTelemetryClusterType::DockerCompose, - Self::Kubernetes => risingwave_pb::telemetry::PbTelemetryClusterType::Kubernetes, - Self::SingleNode => risingwave_pb::telemetry::PbTelemetryClusterType::SingleNode, - Self::Unspecified | Self::Test => { - risingwave_pb::telemetry::PbTelemetryClusterType::Unspecified - } - } +pub fn telemetry_cluster_type_from_env_var() -> PbTelemetryClusterType { + let cluster_type = match env::var(TELEMETRY_CLUSTER_TYPE) { + Ok(cluster_type) => cluster_type, + Err(_) => return PbTelemetryClusterType::Unspecified, + }; + match cluster_type.as_str() { + TELEMETRY_CLUSTER_TYPE_HOSTED => PbTelemetryClusterType::CloudHosted, + TELEMETRY_CLUSTER_TYPE_DOCKER_COMPOSE => PbTelemetryClusterType::DockerCompose, + TELEMETRY_CLUSTER_TYPE_KUBERNETES => PbTelemetryClusterType::Kubernetes, + TELEMETRY_CLUSTER_TYPE_SINGLE_NODE => PbTelemetryClusterType::SingleNode, + _ => PbTelemetryClusterType::Unspecified, } } @@ -208,8 +185,8 @@ pub fn current_timestamp() -> u64 { pub fn report_scarf_enabled() -> bool { telemetry_env_enabled() && !matches!( - TelemetryClusterType::from_env_var(), - TelemetryClusterType::Hosted + telemetry_cluster_type_from_env_var(), + PbTelemetryClusterType::CloudHosted ) } diff --git a/src/meta/src/telemetry.rs b/src/meta/src/telemetry.rs index 5d1461e078db1..c628f25f2a2fd 100644 --- a/src/meta/src/telemetry.rs +++ b/src/meta/src/telemetry.rs @@ -17,11 +17,12 @@ use risingwave_common::config::MetaBackend; use risingwave_common::telemetry::pb_compatible::TelemetryToProtobuf; use risingwave_common::telemetry::report::{TelemetryInfoFetcher, TelemetryReportCreator}; use risingwave_common::telemetry::{ - current_timestamp, SystemData, TelemetryClusterType, TelemetryNodeType, TelemetryReportBase, - TelemetryResult, + current_timestamp, telemetry_cluster_type_from_env_var, SystemData, TelemetryNodeType, + TelemetryReportBase, TelemetryResult, }; use risingwave_common::{GIT_SHA, RW_VERSION}; use risingwave_pb::common::WorkerType; +use risingwave_pb::telemetry::PbTelemetryClusterType; use serde::{Deserialize, Serialize}; use thiserror_ext::AsReport; @@ -69,7 +70,7 @@ pub struct MetaTelemetryReport { job_desc: Vec, // Get the ENV from key `TELEMETRY_CLUSTER_TYPE` - cluster_type: TelemetryClusterType, + cluster_type: PbTelemetryClusterType, } impl From for risingwave_pb::telemetry::StreamJobDesc { @@ -112,7 +113,7 @@ impl TelemetryToProtobuf for MetaTelemetryReport { }), stream_job_count: self.streaming_job_count as u32, stream_jobs: self.job_desc.into_iter().map(|job| job.into()).collect(), - cluster_type: self.cluster_type.to_prost() as i32, + cluster_type: self.cluster_type as i32, }; pb_report.encode_to_vec() } @@ -199,7 +200,7 @@ impl TelemetryReportCreator for MetaReportCreator { streaming_job_count, meta_backend: self.meta_backend, job_desc: stream_job_desc, - cluster_type: TelemetryClusterType::from_env_var(), + cluster_type: telemetry_cluster_type_from_env_var(), }) } @@ -212,8 +213,9 @@ impl TelemetryReportCreator for MetaReportCreator { mod test { use risingwave_common::config::MetaBackend; use risingwave_common::telemetry::{ - current_timestamp, SystemData, TelemetryClusterType, TelemetryNodeType, TelemetryReportBase, + current_timestamp, SystemData, TelemetryNodeType, TelemetryReportBase, }; + use risingwave_pb::telemetry::PbTelemetryClusterType; use crate::telemetry::{MetaTelemetryReport, NodeCount, RwVersion}; @@ -225,7 +227,7 @@ mod test { use crate::telemetry::TELEMETRY_META_REPORT_TYPE; - // we don't call `create_report` here because it rely on the metadata manager + // we don't call `create_report` here because it relies on the metadata manager let report = MetaTelemetryReport { base: TelemetryReportBase { tracking_id: "7d45669c-08c7-4571-ae3d-d3a3e70a2f7e".to_owned(), @@ -249,7 +251,7 @@ mod test { git_sha: "git_sha".to_owned(), }, job_desc: vec![], - cluster_type: TelemetryClusterType::Test, + cluster_type: PbTelemetryClusterType::Unspecified, }; let pb_bytes = report.to_pb_bytes();