Remove old CPU/Memory events (#20865)
Release Notes: - Telemetry: stop reporting CPU/RAM on a timer
This commit is contained in:
parent
5c6565a9e0
commit
496dae968b
5 changed files with 25 additions and 97 deletions
18
.github/workflows/ci.yml
vendored
18
.github/workflows/ci.yml
vendored
|
@ -353,7 +353,6 @@ jobs:
|
||||||
files: |
|
files: |
|
||||||
target/zed-remote-server-linux-x86_64.gz
|
target/zed-remote-server-linux-x86_64.gz
|
||||||
target/release/zed-linux-x86_64.tar.gz
|
target/release/zed-linux-x86_64.tar.gz
|
||||||
body: ""
|
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
@ -400,6 +399,21 @@ jobs:
|
||||||
files: |
|
files: |
|
||||||
target/zed-remote-server-linux-aarch64.gz
|
target/zed-remote-server-linux-aarch64.gz
|
||||||
target/release/zed-linux-aarch64.tar.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:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -2456,7 +2456,6 @@ dependencies = [
|
||||||
"settings",
|
"settings",
|
||||||
"sha2",
|
"sha2",
|
||||||
"smol",
|
"smol",
|
||||||
"sysinfo",
|
|
||||||
"telemetry_events",
|
"telemetry_events",
|
||||||
"text",
|
"text",
|
||||||
"thiserror 1.0.69",
|
"thiserror 1.0.69",
|
||||||
|
|
|
@ -42,7 +42,6 @@ serde_json.workspace = true
|
||||||
settings.workspace = true
|
settings.workspace = true
|
||||||
sha2.workspace = true
|
sha2.workspace = true
|
||||||
smol.workspace = true
|
smol.workspace = true
|
||||||
sysinfo.workspace = true
|
|
||||||
telemetry_events.workspace = true
|
telemetry_events.workspace = true
|
||||||
text.workspace = true
|
text.workspace = true
|
||||||
thiserror.workspace = true
|
thiserror.workspace = true
|
||||||
|
|
|
@ -16,11 +16,9 @@ use std::fs::File;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
use std::{env, mem, path::PathBuf, sync::Arc, time::Duration};
|
use std::{env, mem, path::PathBuf, sync::Arc, time::Duration};
|
||||||
use sysinfo::{CpuRefreshKind, Pid, ProcessRefreshKind, RefreshKind, System};
|
|
||||||
use telemetry_events::{
|
use telemetry_events::{
|
||||||
ActionEvent, AppEvent, AssistantEvent, CallEvent, CpuEvent, EditEvent, EditorEvent, Event,
|
ActionEvent, AppEvent, AssistantEvent, CallEvent, EditEvent, EditorEvent, Event,
|
||||||
EventRequestBody, EventWrapper, ExtensionEvent, InlineCompletionEvent, MemoryEvent, ReplEvent,
|
EventRequestBody, EventWrapper, ExtensionEvent, InlineCompletionEvent, ReplEvent, SettingEvent,
|
||||||
SettingEvent,
|
|
||||||
};
|
};
|
||||||
use util::{ResultExt, TryFutureExt};
|
use util::{ResultExt, TryFutureExt};
|
||||||
use worktree::{UpdatedEntriesSet, WorktreeId};
|
use worktree::{UpdatedEntriesSet, WorktreeId};
|
||||||
|
@ -293,48 +291,6 @@ impl Telemetry {
|
||||||
state.session_id = Some(session_id);
|
state.session_id = Some(session_id);
|
||||||
state.app_version = release_channel::AppVersion::global(cx).to_string();
|
state.app_version = release_channel::AppVersion::global(cx).to_string();
|
||||||
state.os_name = os_name();
|
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<Self>) -> bool {
|
pub fn metrics_enabled(self: &Arc<Self>) -> bool {
|
||||||
|
@ -416,28 +372,6 @@ impl Telemetry {
|
||||||
self.report_event(event)
|
self.report_event(event)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn report_cpu_event(self: &Arc<Self>, 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<Self>,
|
|
||||||
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<Self>, operation: String) -> Event {
|
pub fn report_app_event(self: &Arc<Self>, operation: String) -> Event {
|
||||||
let event = Event::App(AppEvent { operation });
|
let event = Event::App(AppEvent { operation });
|
||||||
|
|
||||||
|
|
|
@ -483,20 +483,7 @@ pub async fn post_events(
|
||||||
checksum_matched,
|
checksum_matched,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
Event::Cpu(event) => to_upload.cpu_events.push(CpuEventRow::from_event(
|
Event::Cpu(_) | Event::Memory(_) => continue,
|
||||||
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::App(event) => to_upload.app_events.push(AppEventRow::from_event(
|
Event::App(event) => to_upload.app_events.push(AppEventRow::from_event(
|
||||||
event.clone(),
|
event.clone(),
|
||||||
wrapper,
|
wrapper,
|
||||||
|
@ -947,6 +934,7 @@ pub struct CpuEventRow {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CpuEventRow {
|
impl CpuEventRow {
|
||||||
|
#[allow(unused)]
|
||||||
fn from_event(
|
fn from_event(
|
||||||
event: CpuEvent,
|
event: CpuEvent,
|
||||||
wrapper: &EventWrapper,
|
wrapper: &EventWrapper,
|
||||||
|
@ -1001,6 +989,7 @@ pub struct MemoryEventRow {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MemoryEventRow {
|
impl MemoryEventRow {
|
||||||
|
#[allow(unused)]
|
||||||
fn from_event(
|
fn from_event(
|
||||||
event: MemoryEvent,
|
event: MemoryEvent,
|
||||||
wrapper: &EventWrapper,
|
wrapper: &EventWrapper,
|
||||||
|
@ -1393,7 +1382,7 @@ fn for_snowflake(
|
||||||
body: EventRequestBody,
|
body: EventRequestBody,
|
||||||
first_event_at: chrono::DateTime<chrono::Utc>,
|
first_event_at: chrono::DateTime<chrono::Utc>,
|
||||||
) -> impl Iterator<Item = SnowflakeRow> {
|
) -> impl Iterator<Item = SnowflakeRow> {
|
||||||
body.events.into_iter().map(move |event| {
|
body.events.into_iter().flat_map(move |event| {
|
||||||
let timestamp =
|
let timestamp =
|
||||||
first_event_at + Duration::milliseconds(event.milliseconds_since_first_event);
|
first_event_at + Duration::milliseconds(event.milliseconds_since_first_event);
|
||||||
let (event_type, mut event_properties) = match &event.event {
|
let (event_type, mut event_properties) = match &event.event {
|
||||||
|
@ -1450,14 +1439,7 @@ fn for_snowflake(
|
||||||
},
|
},
|
||||||
serde_json::to_value(e).unwrap(),
|
serde_json::to_value(e).unwrap(),
|
||||||
),
|
),
|
||||||
Event::Cpu(e) => (
|
Event::Cpu(_) | Event::Memory(_) => return None,
|
||||||
"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::App(e) => {
|
Event::App(e) => {
|
||||||
let mut properties = json!({});
|
let mut properties = json!({});
|
||||||
let event_type = match e.operation.trim() {
|
let event_type = match e.operation.trim() {
|
||||||
|
@ -1577,7 +1559,7 @@ fn for_snowflake(
|
||||||
"is_staff": body.is_staff,
|
"is_staff": body.is_staff,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
SnowflakeRow {
|
Some(SnowflakeRow {
|
||||||
time: timestamp,
|
time: timestamp,
|
||||||
user_id: body.metrics_id.clone(),
|
user_id: body.metrics_id.clone(),
|
||||||
device_id: body.system_id.clone(),
|
device_id: body.system_id.clone(),
|
||||||
|
@ -1585,7 +1567,7 @@ fn for_snowflake(
|
||||||
event_properties,
|
event_properties,
|
||||||
user_properties,
|
user_properties,
|
||||||
insert_id: Some(Uuid::new_v4().to_string()),
|
insert_id: Some(Uuid::new_v4().to_string()),
|
||||||
}
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue