Skip to content

Commit

Permalink
feat(telemetry): record cloud hosted UUID (#18019)
Browse files Browse the repository at this point in the history
Signed-off-by: tabVersion <[email protected]>
  • Loading branch information
tabVersion authored Sep 25, 2024
1 parent 1993bae commit 2c89c24
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
2 changes: 2 additions & 0 deletions src/common/src/telemetry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ 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";

pub use risingwave_telemetry_event::get_telemetry_risingwave_cloud_uuid;

pub fn telemetry_cluster_type_from_env_var() -> PbTelemetryClusterType {
let cluster_type = match env::var(TELEMETRY_CLUSTER_TYPE) {
Ok(cluster_type) => cluster_type,
Expand Down
25 changes: 16 additions & 9 deletions src/common/src/telemetry/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

use std::sync::Arc;

use risingwave_telemetry_event::get_telemetry_risingwave_cloud_uuid;
pub use risingwave_telemetry_event::{
current_timestamp, post_telemetry_report_pb, TELEMETRY_REPORT_URL, TELEMETRY_TRACKING_ID,
};
Expand Down Expand Up @@ -65,15 +66,21 @@ where
// fetch telemetry tracking_id from the meta node only at the beginning
// There is only one case tracking_id updated at the runtime ---- etcd data has been
// cleaned. There is no way that etcd has been cleaned but nodes are still running
let tracking_id = match info_fetcher.fetch_telemetry_info().await {
Ok(Some(id)) => id,
Ok(None) => {
tracing::info!("Telemetry is disabled");
return;
}
Err(err) => {
tracing::error!("Telemetry failed to get tracking_id, err {}", err);
return;
let tracking_id = {
if let Some(cloud_uuid) = get_telemetry_risingwave_cloud_uuid() {
cloud_uuid
} else {
match info_fetcher.fetch_telemetry_info().await {
Ok(Some(id)) => id,
Ok(None) => {
tracing::info!("Telemetry is disabled");
return;
}
Err(err) => {
tracing::error!("Telemetry failed to get tracking_id, err {}", err);
return;
}
}
}
};
TELEMETRY_TRACKING_ID
Expand Down
8 changes: 8 additions & 0 deletions src/common/telemetry_event/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
/// Keep the stats report module in the common/ module
mod util;

use std::env;
use std::sync::OnceLock;

use prost::Message;
Expand All @@ -34,6 +35,13 @@ pub static TELEMETRY_TRACKING_ID: OnceLock<String> = OnceLock::new();

pub const TELEMETRY_REPORT_URL: &str = "https://telemetry.risingwave.dev/api/v2/report";

// the UUID of the RisingWave Cloud (if the cluster is hosted on RisingWave Cloud)
pub const TELEMETRY_RISINGWAVE_CLOUD_UUID: &str = "RISINGWAVE_CLOUD_UUID";

pub fn get_telemetry_risingwave_cloud_uuid() -> Option<String> {
env::var(TELEMETRY_RISINGWAVE_CLOUD_UUID).ok()
}

pub fn report_event_common(
event_stage: PbTelemetryEventStage,
event_name: &str,
Expand Down

0 comments on commit 2c89c24

Please sign in to comment.