quickwit_telemetry/
payload.rs1use std::env;
21use std::time::UNIX_EPOCH;
22
23use serde::{Deserialize, Serialize};
24use uuid::Uuid;
25
26#[derive(Debug, Serialize, Deserialize)]
28pub struct TelemetryPayload {
29 pub client_information: ClientInformation,
31 pub events: Vec<EventWithTimestamp>,
32 pub num_dropped_events: usize,
35}
36
37#[derive(Debug, Serialize, Deserialize)]
38pub struct EventWithTimestamp {
39 pub unixtime: u64,
41 pub event: TelemetryEvent,
43}
44
45fn unixtime() -> u64 {
49 match UNIX_EPOCH.elapsed() {
50 Ok(duration) => duration.as_secs(),
51 Err(_) => 0u64,
52 }
53}
54
55impl From<TelemetryEvent> for EventWithTimestamp {
56 fn from(event: TelemetryEvent) -> Self {
57 EventWithTimestamp {
58 unixtime: unixtime(),
59 event,
60 }
61 }
62}
63
64#[derive(Debug, Serialize, Deserialize)]
66pub enum TelemetryEvent {
67 Create,
69 Ingest,
71 Delete,
73 GarbageCollect,
75 RunService(String),
77 EndCommand { return_code: i32 },
79}
80
81#[derive(Clone, Debug, Serialize, Deserialize)]
82pub struct ClientInformation {
83 session_uuid: uuid::Uuid,
84 quickwit_version: String,
85 os: String,
86 arch: String,
87 hashed_host_username: String,
88 kubernetes: bool,
89}
90
91fn hashed_host_username() -> String {
92 let hostname = hostname::get()
93 .map(|hostname| hostname.to_string_lossy().to_string())
94 .unwrap_or_else(|_| "".to_string());
95 let username = username::get_user_name().unwrap_or_else(|_| "".to_string());
96 let hashed_value = format!("{}:{}", hostname, username);
97 let digest = md5::compute(hashed_value.as_bytes());
98 format!("{:x}", digest)
99}
100
101impl Default for ClientInformation {
102 fn default() -> ClientInformation {
103 ClientInformation {
104 session_uuid: Uuid::new_v4(),
105 quickwit_version: env!("CARGO_PKG_VERSION").to_string(),
106 os: env::consts::OS.to_string(),
107 arch: env::consts::ARCH.to_string(),
108 hashed_host_username: hashed_host_username(),
109 kubernetes: std::env::var_os("KUBERNETES_SERVICE_HOST").is_some(),
110 }
111 }
112}