Skip to content

Commit dfa958a

Browse files
alanzmeta-codesync[bot]
authored andcommitted
9/n: buck targets: report ELP restarts too in telemetry
Summary: We can now specifiy a `buck_quick_start` config item and have ELP in server mode start up using a 2-step process, first doing a quick `buck targets` query and then the full `elp.bxl` one that includes generating some files, and is slower. In order to understand the impact of these, we update the existing telemetry that reports the time from the server main loop starting to going operational (able to process client requests). We now report as follows - `buck_quick_start` not enabled Normal operational telemetry using title "ELP operational" - `buck_quick_start` enabled "ELP operational (quick start)" for the first load "ELP operational (full)" for the second Both of these report the time from the initial main loop startup. Reviewed By: robertoaloi Differential Revision: D84343885 fbshipit-source-id: 1883fcdeabf1ba0cccb248d81a0b10fc6b6befb8
1 parent 93317ca commit dfa958a

File tree

2 files changed

+50
-27
lines changed

2 files changed

+50
-27
lines changed

crates/elp/src/server.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -991,7 +991,8 @@ impl Server {
991991
self.show_message(params);
992992
}
993993
self.transition(Status::Running);
994-
self.telemetry_manager.operational();
994+
self.telemetry_manager
995+
.operational(self.config.buck_quick_start());
995996
self.initial_load_status = InitialLoading::DoneButVfsChanges;
996997
self.schedule_compile_deps();
997998
self.schedule_cache();

crates/elp/src/server/telemetry_manager.rs

Lines changed: 48 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,23 @@ use crate::memory_usage::MemoryUsage;
2626

2727
const PERIODIC_INTERVAL_MS: Duration = Duration::from_millis(60_000);
2828

29+
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
30+
enum OperationalState {
31+
NotStarted,
32+
Started,
33+
Restarted,
34+
}
2935
pub(crate) struct TelemetryManager {
3036
last_periodic_processed: Instant,
3137
server_started_at: SystemTime,
32-
already_operational: bool,
38+
operational_state: OperationalState,
3339
}
3440
impl TelemetryManager {
3541
pub(crate) fn new() -> Self {
3642
Self {
3743
last_periodic_processed: Instant::now(),
3844
server_started_at: SystemTime::now(),
39-
already_operational: false,
45+
operational_state: OperationalState::NotStarted,
4046
}
4147
}
4248

@@ -70,32 +76,48 @@ impl TelemetryManager {
7076
}
7177
}
7278

73-
pub(crate) fn operational(&mut self) {
74-
if !self.already_operational {
75-
let duration = self
76-
.server_started_at
77-
.elapsed()
78-
.map(|e| e.as_millis())
79-
.unwrap_or(0) as u32;
80-
81-
#[derive(Serialize)]
82-
struct Operational {
83-
title: String,
79+
pub(crate) fn operational(&mut self, buck_quick_start: bool) {
80+
let title = if buck_quick_start {
81+
match self.operational_state {
82+
OperationalState::NotStarted => "ELP operational (quick start)",
83+
OperationalState::Started => "ELP operational (fully)",
84+
OperationalState::Restarted => return,
8485
}
85-
let data = Operational {
86-
title: "ELP operational".to_string(),
87-
};
88-
let data = serde_json::to_value(data).unwrap_or_else(|err| {
89-
serde_json::Value::String(format!("JSON serialization failed: {err}"))
90-
});
91-
telemetry::send_with_duration(
92-
String::from("telemetry"),
93-
data,
94-
duration,
95-
self.server_started_at,
96-
);
97-
self.already_operational = true;
86+
} else {
87+
match self.operational_state {
88+
OperationalState::NotStarted => "ELP operational",
89+
OperationalState::Started => return,
90+
OperationalState::Restarted => return,
91+
}
92+
};
93+
94+
let duration = self
95+
.server_started_at
96+
.elapsed()
97+
.map(|e| e.as_millis())
98+
.unwrap_or(0) as u32;
99+
100+
#[derive(Serialize)]
101+
struct Operational {
102+
title: String,
98103
}
104+
let data = Operational {
105+
title: title.to_string(),
106+
};
107+
let data = serde_json::to_value(data).unwrap_or_else(|err| {
108+
serde_json::Value::String(format!("JSON serialization failed: {err}"))
109+
});
110+
telemetry::send_with_duration(
111+
String::from("telemetry"),
112+
data,
113+
duration,
114+
self.server_started_at,
115+
);
116+
self.operational_state = if self.operational_state == OperationalState::NotStarted {
117+
OperationalState::Started
118+
} else {
119+
OperationalState::Restarted
120+
};
99121
}
100122
}
101123

0 commit comments

Comments
 (0)