Skip to content

Commit

Permalink
remove enum and test type
Browse files Browse the repository at this point in the history
Signed-off-by: tabVersion <[email protected]>
  • Loading branch information
tabVersion committed Jun 24, 2024
1 parent 3d552ca commit ad150ba
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 46 deletions.
2 changes: 1 addition & 1 deletion proto/telemetry.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
51 changes: 14 additions & 37 deletions src/common/src/telemetry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
}
}

Expand Down Expand Up @@ -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
)
}

Expand Down
18 changes: 10 additions & 8 deletions src/meta/src/telemetry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -69,7 +70,7 @@ pub struct MetaTelemetryReport {
job_desc: Vec<MetaTelemetryJobDesc>,

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

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

Expand All @@ -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};

Expand All @@ -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(),
Expand All @@ -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();
Expand Down

0 comments on commit ad150ba

Please sign in to comment.