From 8bf2003d14695d8e21760d01ee9abcbcc23b61e4 Mon Sep 17 00:00:00 2001 From: tabVersion Date: Tue, 13 Aug 2024 14:49:08 +0800 Subject: [PATCH] add new field in telemetry Signed-off-by: tabVersion --- proto/telemetry.proto | 4 ++++ src/common/src/telemetry/mod.rs | 7 +++++++ src/common/src/telemetry/pb_compatible.rs | 3 ++- src/common/src/telemetry/report.rs | 6 +++++- 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/proto/telemetry.proto b/proto/telemetry.proto index e9d5b75147e5e..5dc430023d5bf 100644 --- a/proto/telemetry.proto +++ b/proto/telemetry.proto @@ -80,6 +80,8 @@ message ReportBase { // mark the report is a test message // if so, the backend do validations but not store it bool is_test = 7; + // cloud_uuid is the unique identifier of the cloud instance + optional string cloud_uuid = 8; } message MetaReport { @@ -165,4 +167,6 @@ message EventMessage { string node = 9; // mark the event is a test message bool is_test = 11; + // cloud_uuid is the unique identifier of the cloud instance + optional string cloud_uuid = 12; } diff --git a/src/common/src/telemetry/mod.rs b/src/common/src/telemetry/mod.rs index 9cf469af9cd8d..e9614ddbd5c0c 100644 --- a/src/common/src/telemetry/mod.rs +++ b/src/common/src/telemetry/mod.rs @@ -35,6 +35,13 @@ 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"; +// 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 { + env::var(TELEMETRY_RISINGWAVE_CLOUD_UUID).ok() +} + pub fn telemetry_cluster_type_from_env_var() -> PbTelemetryClusterType { let cluster_type = match env::var(TELEMETRY_CLUSTER_TYPE) { Ok(cluster_type) => cluster_type, diff --git a/src/common/src/telemetry/pb_compatible.rs b/src/common/src/telemetry/pb_compatible.rs index 36772872a186e..8deeded0f9dd4 100644 --- a/src/common/src/telemetry/pb_compatible.rs +++ b/src/common/src/telemetry/pb_compatible.rs @@ -11,7 +11,7 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. - +use risingwave_common::telemetry::get_telemetry_risingwave_cloud_uuid; use risingwave_pb::telemetry::{ ReportBase as PbTelemetryReportBase, SystemCpu as PbSystemCpu, SystemData as PbSystemData, SystemMemory as PbSystemMemory, SystemOs as PbSystemOs, @@ -27,6 +27,7 @@ pub trait TelemetryToProtobuf { impl From for PbTelemetryReportBase { fn from(val: TelemetryReportBase) -> Self { PbTelemetryReportBase { + cloud_uuid: get_telemetry_risingwave_cloud_uuid(), tracking_id: val.tracking_id, session_id: val.session_id, system_data: Some(val.system_data.into()), diff --git a/src/common/src/telemetry/report.rs b/src/common/src/telemetry/report.rs index 38d1c48065635..c764e15bd6b4a 100644 --- a/src/common/src/telemetry/report.rs +++ b/src/common/src/telemetry/report.rs @@ -24,7 +24,10 @@ use tokio::task::JoinHandle; use tokio::time::{interval, Duration}; use uuid::Uuid; -use super::{current_timestamp, Result, TELEMETRY_REPORT_INTERVAL, TELEMETRY_REPORT_URL}; +use super::{ + current_timestamp, get_telemetry_risingwave_cloud_uuid, Result, TELEMETRY_REPORT_INTERVAL, + TELEMETRY_REPORT_URL, +}; use crate::telemetry::pb_compatible::TelemetryToProtobuf; use crate::telemetry::post_telemetry_report_pb; @@ -179,6 +182,7 @@ fn request_to_telemetry_event( attributes: attributes.map(|a| a.to_string()), node, is_test, + cloud_uuid: get_telemetry_risingwave_cloud_uuid(), }; let report_bytes = event.encode_to_vec();