Skip to content

Commit

Permalink
collect deploy mode in telemetry
Browse files Browse the repository at this point in the history
  • Loading branch information
tabVersion committed Jun 21, 2024
1 parent 3736982 commit dd07f62
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 7 deletions.
13 changes: 13 additions & 0 deletions proto/telemetry.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
51 changes: 45 additions & 6 deletions src/common/src/telemetry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion src/meta/src/telemetry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -66,6 +67,9 @@ pub struct MetaTelemetryReport {
meta_backend: MetaBackend,
rw_version: RwVersion,
job_desc: Vec<MetaTelemetryJobDesc>,

// Get the ENV from key `TELEMETRY_CLUSTER_TYPE`
cluster_type: TelemetryClusterType,
}

impl From<MetaTelemetryJobDesc> for risingwave_pb::telemetry::StreamJobDesc {
Expand Down Expand Up @@ -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()
}
Expand Down Expand Up @@ -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(),
})
}

Expand Down

0 comments on commit dd07f62

Please sign in to comment.