Do not rely on user's system time for telemetry events

This commit is contained in:
Joseph Lyons 2023-06-09 18:02:20 -04:00
parent d8c1ab9c68
commit 0b3b732310

View File

@ -4,14 +4,7 @@ use gpui::{executor::Background, serde_json, AppContext, Task};
use lazy_static::lazy_static; use lazy_static::lazy_static;
use parking_lot::Mutex; use parking_lot::Mutex;
use serde::Serialize; use serde::Serialize;
use std::{ use std::{env, io::Write, mem, path::PathBuf, sync::Arc, time::Duration};
env,
io::Write,
mem,
path::PathBuf,
sync::Arc,
time::{Duration, SystemTime, UNIX_EPOCH},
};
use tempfile::NamedTempFile; use tempfile::NamedTempFile;
use util::http::HttpClient; use util::http::HttpClient;
use util::{channel::ReleaseChannel, TryFutureExt}; use util::{channel::ReleaseChannel, TryFutureExt};
@ -59,7 +52,6 @@ struct ClickhouseEventRequestBody {
#[derive(Serialize, Debug)] #[derive(Serialize, Debug)]
struct ClickhouseEventWrapper { struct ClickhouseEventWrapper {
time: u128,
signed_in: bool, signed_in: bool,
#[serde(flatten)] #[serde(flatten)]
event: ClickhouseEvent, event: ClickhouseEvent,
@ -193,14 +185,9 @@ impl Telemetry {
let mut state = self.state.lock(); let mut state = self.state.lock();
let signed_in = state.metrics_id.is_some(); let signed_in = state.metrics_id.is_some();
state.clickhouse_events_queue.push(ClickhouseEventWrapper { state
time: SystemTime::now() .clickhouse_events_queue
.duration_since(UNIX_EPOCH) .push(ClickhouseEventWrapper { signed_in, event });
.unwrap()
.as_millis(),
signed_in,
event,
});
if state.installation_id.is_some() { if state.installation_id.is_some() {
if state.clickhouse_events_queue.len() >= MAX_QUEUE_LEN { if state.clickhouse_events_queue.len() >= MAX_QUEUE_LEN {