risingwave_common/telemetry/
pb_compatible.rs1use risingwave_pb::telemetry::{
16 ReportBase as PbTelemetryReportBase, SystemCpu as PbSystemCpu, SystemData as PbSystemData,
17 SystemMemory as PbSystemMemory, SystemOs as PbSystemOs,
18 TelemetryNodeType as PbTelemetryNodeType,
19};
20
21use crate::telemetry::{Cpu, Memory, Os, SystemData, TelemetryNodeType, TelemetryReportBase};
22
23pub trait TelemetryToProtobuf {
24 fn to_pb_bytes(self) -> Vec<u8>;
25}
26
27impl From<TelemetryReportBase> for PbTelemetryReportBase {
28 fn from(val: TelemetryReportBase) -> Self {
29 PbTelemetryReportBase {
30 tracking_id: val.tracking_id,
31 session_id: val.session_id,
32 system_data: Some(val.system_data.into()),
33 up_time: val.up_time,
34 report_time: val.time_stamp,
35 node_type: from_telemetry_node_type(val.node_type) as i32,
36 is_test: val.is_test,
37 }
38 }
39}
40
41fn from_telemetry_node_type(t: TelemetryNodeType) -> PbTelemetryNodeType {
42 match t {
43 TelemetryNodeType::Meta => PbTelemetryNodeType::Meta,
44 TelemetryNodeType::Compute => PbTelemetryNodeType::Compute,
45 TelemetryNodeType::Frontend => PbTelemetryNodeType::Frontend,
46 TelemetryNodeType::Compactor => PbTelemetryNodeType::Compactor,
47 }
48}
49
50impl From<TelemetryNodeType> for PbTelemetryNodeType {
51 fn from(val: TelemetryNodeType) -> Self {
52 match val {
53 TelemetryNodeType::Meta => PbTelemetryNodeType::Meta,
54 TelemetryNodeType::Compute => PbTelemetryNodeType::Compute,
55 TelemetryNodeType::Frontend => PbTelemetryNodeType::Frontend,
56 TelemetryNodeType::Compactor => PbTelemetryNodeType::Compactor,
57 }
58 }
59}
60
61impl From<Cpu> for PbSystemCpu {
62 fn from(val: Cpu) -> Self {
63 PbSystemCpu {
64 available: val.available,
65 }
66 }
67}
68
69impl From<Memory> for PbSystemMemory {
70 fn from(val: Memory) -> Self {
71 PbSystemMemory {
72 used: val.used as u64,
73 total: val.total as u64,
74 }
75 }
76}
77
78impl From<Os> for PbSystemOs {
79 fn from(val: Os) -> Self {
80 PbSystemOs {
81 name: val.name,
82 kernel_version: val.kernel_version,
83 version: val.version,
84 }
85 }
86}
87
88impl From<SystemData> for PbSystemData {
89 fn from(val: SystemData) -> Self {
90 PbSystemData {
91 memory: Some(val.memory.into()),
92 os: Some(val.os.into()),
93 cpu: Some(val.cpu.into()),
94 }
95 }
96}