risingwave_telemetry_event/
util.rs1use std::time::SystemTime;
16
17use thiserror_ext::AsReport;
18
19use crate::TelemetryError;
20
21type Result<T> = core::result::Result<T, TelemetryError>;
22
23pub fn current_timestamp() -> u64 {
24 SystemTime::now()
25 .duration_since(SystemTime::UNIX_EPOCH)
26 .expect("Clock might go backward")
27 .as_secs()
28}
29
30pub async fn post_telemetry_report_pb(url: &str, report_body: Vec<u8>) -> Result<()> {
32 let client = reqwest::Client::new();
33 let res = client
34 .post(url)
35 .header(reqwest::header::CONTENT_TYPE, "application/x-protobuf")
36 .body(report_body)
37 .send()
38 .await
39 .map_err(|err| format!("failed to send telemetry report, err: {}", err.as_report()))?;
40 if res.status().is_success() {
41 Ok(())
42 } else {
43 Err(format!(
44 "telemetry response is error, url {}, status {}",
45 url,
46 res.status()
47 ))
48 }
49}