From 496dae968b8fc09118bd60ae7299ab9d44936f16 Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Tue, 19 Nov 2024 12:25:16 -0700 Subject: [PATCH] Remove old CPU/Memory events (#20865) Release Notes: - Telemetry: stop reporting CPU/RAM on a timer --- .github/workflows/ci.yml | 18 ++++++++- Cargo.lock | 1 - crates/client/Cargo.toml | 1 - crates/client/src/telemetry.rs | 70 +-------------------------------- crates/collab/src/api/events.rs | 32 ++++----------- 5 files changed, 25 insertions(+), 97 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bed52955ad..ee6f81dd84 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -353,7 +353,6 @@ jobs: files: | target/zed-remote-server-linux-x86_64.gz target/release/zed-linux-x86_64.tar.gz - body: "" env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -400,6 +399,21 @@ jobs: files: | target/zed-remote-server-linux-aarch64.gz target/release/zed-linux-aarch64.tar.gz - body: "" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + auto-publish-release: + timeout-minutes: 60 + name: Create a Linux bundle + runs-on: + - self-hosted + if: ${{ startsWith(github.ref, 'refs/tags/v') && endsWith(github.ref, '-pre') && !endsWith(github.ref, '.0-pre') }} + needs: [bundle-mac, bundle-linux-aarch64, bundle-linux] + steps: + - name: Upload app bundle to release + uses: softprops/action-gh-release@de2c0eb89ae2a093876385947365aca7b0e5f844 # v1 + with: + draft: false + prerelease: ${{ env.RELEASE_CHANNEL == 'preview' }} env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/Cargo.lock b/Cargo.lock index 38de2f5c00..527190baca 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2456,7 +2456,6 @@ dependencies = [ "settings", "sha2", "smol", - "sysinfo", "telemetry_events", "text", "thiserror 1.0.69", diff --git a/crates/client/Cargo.toml b/crates/client/Cargo.toml index 9892011297..23716f0c69 100644 --- a/crates/client/Cargo.toml +++ b/crates/client/Cargo.toml @@ -42,7 +42,6 @@ serde_json.workspace = true settings.workspace = true sha2.workspace = true smol.workspace = true -sysinfo.workspace = true telemetry_events.workspace = true text.workspace = true thiserror.workspace = true diff --git a/crates/client/src/telemetry.rs b/crates/client/src/telemetry.rs index b472cf768e..fcb9ced4e5 100644 --- a/crates/client/src/telemetry.rs +++ b/crates/client/src/telemetry.rs @@ -16,11 +16,9 @@ use std::fs::File; use std::io::Write; use std::time::Instant; use std::{env, mem, path::PathBuf, sync::Arc, time::Duration}; -use sysinfo::{CpuRefreshKind, Pid, ProcessRefreshKind, RefreshKind, System}; use telemetry_events::{ - ActionEvent, AppEvent, AssistantEvent, CallEvent, CpuEvent, EditEvent, EditorEvent, Event, - EventRequestBody, EventWrapper, ExtensionEvent, InlineCompletionEvent, MemoryEvent, ReplEvent, - SettingEvent, + ActionEvent, AppEvent, AssistantEvent, CallEvent, EditEvent, EditorEvent, Event, + EventRequestBody, EventWrapper, ExtensionEvent, InlineCompletionEvent, ReplEvent, SettingEvent, }; use util::{ResultExt, TryFutureExt}; use worktree::{UpdatedEntriesSet, WorktreeId}; @@ -293,48 +291,6 @@ impl Telemetry { state.session_id = Some(session_id); state.app_version = release_channel::AppVersion::global(cx).to_string(); state.os_name = os_name(); - - drop(state); - - let this = self.clone(); - cx.background_executor() - .spawn(async move { - let mut system = System::new_with_specifics( - RefreshKind::new().with_cpu(CpuRefreshKind::everything()), - ); - - let refresh_kind = ProcessRefreshKind::new().with_cpu().with_memory(); - let current_process = Pid::from_u32(std::process::id()); - system.refresh_processes_specifics( - sysinfo::ProcessesToUpdate::Some(&[current_process]), - refresh_kind, - ); - - // Waiting some amount of time before the first query is important to get a reasonable value - // https://docs.rs/sysinfo/0.29.10/sysinfo/trait.ProcessExt.html#tymethod.cpu_usage - const DURATION_BETWEEN_SYSTEM_EVENTS: Duration = Duration::from_secs(4 * 60); - - loop { - smol::Timer::after(DURATION_BETWEEN_SYSTEM_EVENTS).await; - - let current_process = Pid::from_u32(std::process::id()); - system.refresh_processes_specifics( - sysinfo::ProcessesToUpdate::Some(&[current_process]), - refresh_kind, - ); - let Some(process) = system.process(current_process) else { - log::error!( - "Failed to find own process {current_process:?} in system process table" - ); - // TODO: Fire an error telemetry event - return; - }; - - this.report_memory_event(process.memory(), process.virtual_memory()); - this.report_cpu_event(process.cpu_usage(), system.cpus().len() as u32); - } - }) - .detach(); } pub fn metrics_enabled(self: &Arc) -> bool { @@ -416,28 +372,6 @@ impl Telemetry { self.report_event(event) } - pub fn report_cpu_event(self: &Arc, usage_as_percentage: f32, core_count: u32) { - let event = Event::Cpu(CpuEvent { - usage_as_percentage, - core_count, - }); - - self.report_event(event) - } - - pub fn report_memory_event( - self: &Arc, - memory_in_bytes: u64, - virtual_memory_in_bytes: u64, - ) { - let event = Event::Memory(MemoryEvent { - memory_in_bytes, - virtual_memory_in_bytes, - }); - - self.report_event(event) - } - pub fn report_app_event(self: &Arc, operation: String) -> Event { let event = Event::App(AppEvent { operation }); diff --git a/crates/collab/src/api/events.rs b/crates/collab/src/api/events.rs index 053657a8d1..80f477df30 100644 --- a/crates/collab/src/api/events.rs +++ b/crates/collab/src/api/events.rs @@ -483,20 +483,7 @@ pub async fn post_events( checksum_matched, )) } - Event::Cpu(event) => to_upload.cpu_events.push(CpuEventRow::from_event( - event.clone(), - wrapper, - &request_body, - first_event_at, - checksum_matched, - )), - Event::Memory(event) => to_upload.memory_events.push(MemoryEventRow::from_event( - event.clone(), - wrapper, - &request_body, - first_event_at, - checksum_matched, - )), + Event::Cpu(_) | Event::Memory(_) => continue, Event::App(event) => to_upload.app_events.push(AppEventRow::from_event( event.clone(), wrapper, @@ -947,6 +934,7 @@ pub struct CpuEventRow { } impl CpuEventRow { + #[allow(unused)] fn from_event( event: CpuEvent, wrapper: &EventWrapper, @@ -1001,6 +989,7 @@ pub struct MemoryEventRow { } impl MemoryEventRow { + #[allow(unused)] fn from_event( event: MemoryEvent, wrapper: &EventWrapper, @@ -1393,7 +1382,7 @@ fn for_snowflake( body: EventRequestBody, first_event_at: chrono::DateTime, ) -> impl Iterator { - body.events.into_iter().map(move |event| { + body.events.into_iter().flat_map(move |event| { let timestamp = first_event_at + Duration::milliseconds(event.milliseconds_since_first_event); let (event_type, mut event_properties) = match &event.event { @@ -1450,14 +1439,7 @@ fn for_snowflake( }, serde_json::to_value(e).unwrap(), ), - Event::Cpu(e) => ( - "System CPU Sampled".to_string(), - serde_json::to_value(e).unwrap(), - ), - Event::Memory(e) => ( - "System Memory Sampled".to_string(), - serde_json::to_value(e).unwrap(), - ), + Event::Cpu(_) | Event::Memory(_) => return None, Event::App(e) => { let mut properties = json!({}); let event_type = match e.operation.trim() { @@ -1577,7 +1559,7 @@ fn for_snowflake( "is_staff": body.is_staff, })); - SnowflakeRow { + Some(SnowflakeRow { time: timestamp, user_id: body.metrics_id.clone(), device_id: body.system_id.clone(), @@ -1585,7 +1567,7 @@ fn for_snowflake( event_properties, user_properties, insert_id: Some(Uuid::new_v4().to_string()), - } + }) }) }