From dd07f62f87305e8e7f1543a1725673505ab2bff2 Mon Sep 17 00:00:00 2001 From: tabVersion Date: Fri, 21 Jun 2024 15:12:20 +0800 Subject: [PATCH] collect deploy mode in telemetry --- proto/telemetry.proto | 13 +++++++++ src/common/src/telemetry/mod.rs | 51 +++++++++++++++++++++++++++++---- src/meta/src/telemetry.rs | 8 +++++- 3 files changed, 65 insertions(+), 7 deletions(-) diff --git a/proto/telemetry.proto b/proto/telemetry.proto index 9890f48250538..c2cb9d9f56c9e 100644 --- a/proto/telemetry.proto +++ b/proto/telemetry.proto @@ -19,6 +19,16 @@ enum TelemetryNodeType { TELEMETRY_NODE_TYPE_COMPACTOR = 4; } +// Coo +enum TelemetryClusterType { + TELEMETRY_CLUSTER_TYPE_UNSPECIFIED = 0; + TELEMETRY_CLUSTER_TYPE_SINGLE_NODE = 1; + TELEMETRY_CLUSTER_TYPE_TEST = 2; + TELEMETRY_CLUSTER_TYPE_DOCKER_COMPOSE = 3; + TELEMETRY_CLUSTER_TYPE_KUBERNETES = 4; + TELEMETRY_CLUSTER_TYPE_HOSTED = 5; +} + message SystemMemory { uint64 used = 1; uint64 total = 2; @@ -88,6 +98,9 @@ message MetaReport { // stream_jobs is the list of running streaming jobs // and is used to collect the table_id, connector_name and table_optimizations repeated StreamJobDesc stream_jobs = 6; + + // How the cluster is deployed + TelemetryClusterType cluster_type = 7; } enum PlanOptimization { diff --git a/src/common/src/telemetry/mod.rs b/src/common/src/telemetry/mod.rs index 0fbd526692da0..a16bd4ee831ac 100644 --- a/src/common/src/telemetry/mod.rs +++ b/src/common/src/telemetry/mod.rs @@ -31,6 +31,47 @@ use crate::RW_VERSION; pub const TELEMETRY_CLUSTER_TYPE: &str = "RW_TELEMETRY_TYPE"; const TELEMETRY_CLUSTER_TYPE_HOSTED: &str = "hosted"; // hosted on RisingWave Cloud const TELEMETRY_CLUSTER_TYPE_TEST: &str = "test"; // test environment, eg. CI & Risedev +const TELEMETRY_CLUSTER_TYPE_KUBERNETES: &str = "kubernetes"; +const TELEMETRY_CLUSTER_TYPE_SINGLE_NODE: &str = "single-node"; +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_TEST => Self::Test, + 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::Test => risingwave_pb::telemetry::PbTelemetryClusterType::Test, + Self::DockerCompose => risingwave_pb::telemetry::PbTelemetryClusterType::DockerCompose, + Self::Kubernetes => risingwave_pb::telemetry::PbTelemetryClusterType::Kubernetes, + Self::SingleNode => risingwave_pb::telemetry::PbTelemetryClusterType::SingleNode, + Self::Unspecified => risingwave_pb::telemetry::PbTelemetryClusterType::Unspecified, + } + } +} /// Url of telemetry backend pub const TELEMETRY_REPORT_URL: &str = "https://telemetry.risingwave.dev/api/v2/report"; @@ -166,12 +207,10 @@ pub fn current_timestamp() -> u64 { } pub fn report_scarf_enabled() -> bool { - env::var(TELEMETRY_CLUSTER_TYPE) - .map(|deploy_type| { - !(deploy_type.eq_ignore_ascii_case(TELEMETRY_CLUSTER_TYPE_HOSTED) - || deploy_type.eq_ignore_ascii_case(TELEMETRY_CLUSTER_TYPE_TEST)) - }) - .unwrap_or(true) + !matches!( + TelemetryClusterType::from_env_var(), + TelemetryClusterType::Hosted | TelemetryClusterType::Test + ) } // impl logic to report to Scarf service, containing RW version and deployment platform diff --git a/src/meta/src/telemetry.rs b/src/meta/src/telemetry.rs index ece7aec5d7a2d..ee1618ecf911e 100644 --- a/src/meta/src/telemetry.rs +++ b/src/meta/src/telemetry.rs @@ -17,7 +17,8 @@ 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, TelemetryNodeType, TelemetryReportBase, TelemetryResult, + current_timestamp, SystemData, TelemetryClusterType, TelemetryNodeType, TelemetryReportBase, + TelemetryResult, }; use risingwave_common::{GIT_SHA, RW_VERSION}; use risingwave_pb::common::WorkerType; @@ -66,6 +67,9 @@ pub struct MetaTelemetryReport { meta_backend: MetaBackend, rw_version: RwVersion, job_desc: Vec, + + // Get the ENV from key `TELEMETRY_CLUSTER_TYPE` + cluster_type: TelemetryClusterType, } impl From for risingwave_pb::telemetry::StreamJobDesc { @@ -108,6 +112,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, }; pb_report.encode_to_vec() } @@ -194,6 +199,7 @@ impl TelemetryReportCreator for MetaReportCreator { streaming_job_count, meta_backend: self.meta_backend, job_desc: stream_job_desc, + cluster_type: TelemetryClusterType::from_env_var(), }) }