Skip to content

Commit 5f3a66e

Browse files
MichaelCuevasfacebook-github-bot
authored andcommitted
log when we fall back to Rust
Summary: # Context Our last attempt at removing the Python version of `eden redirect` failed (see the SEV attached to D55426809). Our next attempt should be done in a phased manner to avoid similar breakages. # Solution We will slowly remove all possible fallbacks to Python so that we can be sure no commands are running the Python version of `eden redirect` prior to deleting the code. New rollout plan is as follows: 1) Remove the Chef recipe that writes `/etc/eden/edenfsctl_rollout.json` (Done) 2) Remove "redirect" from the default list of experimental commands in the Rust code. 3) Add a fallback to Rust if Python parsing fails for experimental commands 4) Add an EdenFS event that's logged every time we fallback to the Python `eden redirect` codepath 5) Monitor Scuba data to ensure the Python codepath isn't being hit 6) Delete Python `eden redirect` altogether # This diff Adds scuba logging if we hit the fallback added in #3 Reviewed By: kmancini Differential Revision: D56334269 fbshipit-source-id: 4360a7a3b976927465af619735a726d86196482b
1 parent d26a8f9 commit 5f3a66e

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

eden/fs/cli_rs/edenfs-commands/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ impl TopLevelSubcommand {
139139
}
140140
}
141141

142-
fn name(&self) -> &'static str {
142+
pub fn name(&self) -> &'static str {
143143
// TODO: Is there a way to extract the subcommand's name from clap?
144144
// Otherwise, there is a risk of divergence with clap's own attributes.
145145
match self {

eden/fs/cli_rs/edenfsctl/src/main.rs

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ use edenfs_utils::strip_unc_prefix;
2626
use fbinit::FacebookInit;
2727
use tracing_subscriber::filter::EnvFilter;
2828

29+
#[cfg(not(fbcode_build))]
30+
// For non-fbcode builds, CliUsageSample is not defined. Let's give it a dummy
31+
// value so we can pass CliUsageSample through wrapper_main() and fallback().
32+
struct CliUsageSample;
33+
2934
/// Value used in Python to indicate a command failed to parse
3035
pub const PYTHON_EDENFSCTL_EX_USAGE: i32 = 64;
3136

@@ -102,6 +107,7 @@ fn fallback(reason: Option<clap::Error>) -> Result<i32> {
102107
let status = cmd
103108
.status()
104109
.with_context(|| format!("failed to execute: {:?}", cmd))?;
110+
105111
Ok(status.code().unwrap_or(1))
106112
}
107113

@@ -131,7 +137,7 @@ fn rust_main(cmd: edenfs_commands::MainCommand) -> Result<i32> {
131137

132138
/// This function takes care of the fallback logic, hijack supported subcommand
133139
/// to Rust implementation and forward the rest to Python.
134-
fn wrapper_main() -> Result<i32> {
140+
fn wrapper_main(telemetry_sample: &mut CliUsageSample) -> Result<i32> {
135141
if std::env::var("EDENFSCTL_ONLY_RUST").is_ok() {
136142
let cmd = edenfs_commands::MainCommand::parse();
137143
rust_main(cmd)
@@ -150,8 +156,25 @@ fn wrapper_main() -> Result<i32> {
150156
// parse error, we should see if the Rust version
151157
// exists. This helps prevent cases where rollouts
152158
// are not working correctly.
153-
Ok(PYTHON_EDENFSCTL_EX_USAGE) => rust_main(cmd),
154-
res => res,
159+
Ok(PYTHON_EDENFSCTL_EX_USAGE) => {
160+
#[cfg(fbcode_build)]
161+
{
162+
// We expected to use Python but we were forced
163+
// to fall back to Rust. Something is wrong.
164+
telemetry_sample.set_rust_fallback(true);
165+
}
166+
eprintln!(
167+
"Failed to find Python implementation; falling back to Rust."
168+
);
169+
rust_main(cmd)
170+
}
171+
res => {
172+
#[cfg(fbcode_build)]
173+
{
174+
telemetry_sample.set_rust_fallback(false);
175+
}
176+
res
177+
}
155178
}
156179
}
157180
}
@@ -208,7 +231,7 @@ fn main(_fb: FacebookInit) -> Result<()> {
208231
#[cfg(fbcode_build)]
209232
let mut sample = CliUsageSample::build();
210233

211-
let code = match wrapper_main() {
234+
let code = match wrapper_main(&mut sample) {
212235
Ok(code) => Ok(code),
213236
Err(e) => {
214237
#[cfg(fbcode_build)]

0 commit comments

Comments
 (0)