Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
tabVersion committed Feb 2, 2024
1 parent 84c494f commit db43b0a
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
75 changes: 75 additions & 0 deletions src/common/src/telemetry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ pub mod report;

use std::time::SystemTime;

use risingwave_pb::telemetry::{
ReportBase as PbTelemetryReportBase, SystemCpu as PbSystemCpu, SystemData as PbSystemData,
SystemMemory as PbSystemMemory, SystemOs as PbSystemOs,
TelemetryNodeType as PbTelemetryNodeType,
};
use serde::{Deserialize, Serialize};
use sysinfo::System;
use thiserror_ext::AsReport;
Expand Down Expand Up @@ -65,6 +70,19 @@ pub struct TelemetryReportBase {
pub node_type: TelemetryNodeType,
}

impl Into<PbTelemetryReportBase> for TelemetryReportBase {
fn into(self) -> PbTelemetryReportBase {
PbTelemetryReportBase {
tracking_id: self.tracking_id,
session_id: self.session_id,
system_data: Some(self.system_data.into()),
up_time: self.up_time,
report_time: self.time_stamp,
node_type: from_telemetry_node_type(self.node_type) as i32,
}
}
}

pub trait TelemetryReport: Serialize {}

#[derive(Debug, Serialize, Deserialize)]
Expand Down Expand Up @@ -155,6 +173,63 @@ pub fn current_timestamp() -> u64 {
.as_secs()
}

fn from_telemetry_node_type(t: TelemetryNodeType) -> PbTelemetryNodeType {
match t {
TelemetryNodeType::Meta => PbTelemetryNodeType::Meta,
TelemetryNodeType::Compute => PbTelemetryNodeType::Compute,
TelemetryNodeType::Frontend => PbTelemetryNodeType::Frontend,
TelemetryNodeType::Compactor => PbTelemetryNodeType::Compactor,
}
}

impl Into<PbTelemetryNodeType> for TelemetryNodeType {
fn into(self) -> PbTelemetryNodeType {
match self {
TelemetryNodeType::Meta => PbTelemetryNodeType::Meta,
TelemetryNodeType::Compute => PbTelemetryNodeType::Compute,
TelemetryNodeType::Frontend => PbTelemetryNodeType::Frontend,
TelemetryNodeType::Compactor => PbTelemetryNodeType::Compactor,
}
}
}

impl Into<PbSystemCpu> for Cpu {
fn into(self) -> PbSystemCpu {
PbSystemCpu {
available: self.available,
}
}
}

impl Into<PbSystemMemory> for Memory {
fn into(self) -> PbSystemMemory {
PbSystemMemory {
used: self.used as u64,
total: self.total as u64,
}
}
}

impl Into<PbSystemOs> for Os {
fn into(self) -> PbSystemOs {
PbSystemOs {
name: self.name,
kernel_version: self.kernel_version,
version: self.version,
}
}
}

impl Into<PbSystemData> for SystemData {
fn into(self) -> PbSystemData {
PbSystemData {
memory: Some(self.memory.into()),
os: Some(self.os.into()),
cpu: Some(self.cpu.into()),
}
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
6 changes: 6 additions & 0 deletions src/prost/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ pub mod java_binding;
#[cfg_attr(madsim, path = "sim/health.rs")]
pub mod health;
#[rustfmt::skip]
#[path = "sim/telemetry.rs"]
pub mod telemetry;
#[rustfmt::skip]
#[path = "connector_service.serde.rs"]
pub mod connector_service_serde;
#[rustfmt::skip]
Expand Down Expand Up @@ -151,6 +154,9 @@ pub mod backup_service_serde;
#[rustfmt::skip]
#[path = "java_binding.serde.rs"]
pub mod java_binding_serde;
#[rustfmt::skip]
#[path = "telemetry.serde.rs"]
pub mod telemetry_serde;

#[derive(Clone, PartialEq, Eq, Debug, Error)]
#[error("field `{0}` not found")]
Expand Down

0 comments on commit db43b0a

Please sign in to comment.