Skip to content

Commit

Permalink
eden-client refactoring: move Thrift calls from minitop into Eden ins…
Browse files Browse the repository at this point in the history
…tance

Summary:
## Context
The stack of diffs aims to encapsulate Thrift calls from EdenFS cli commands/subcommands into the eden instance. This is done to improve the overall design and maintainability of the code. The overall purpose of the stack of diffs is to improve the code structure and make it easier to maintain and modify in the future.

## This Diff

Moved thrift calls from minitop subcommand to be Eden instance methods. The API of the methods accept an optional connected thrift client so we can save one async call if the caller already has a client ready.

Reviewed By: jdelliot

Differential Revision: D67403258

fbshipit-source-id: fca1ce1f06b3b49e42acec1a9f0907f883470157
  • Loading branch information
lXXXw authored and facebook-github-bot committed Dec 19, 2024
1 parent 641751d commit 2b562a4
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
27 changes: 27 additions & 0 deletions eden/fs/cli_rs/edenfs-client/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,33 @@ impl EdenFsInstance {
.map_err(|_| EdenFsError::Other(anyhow!("failed to call clearAndCompactLocalStore")))
}

pub async fn flush_stats_now(&self, client: Option<&EdenFsClient>) -> Result<()> {
let client = match client {
Some(client) => client,
None => &self.get_connected_thrift_client(None).await?,
};
client
.flushStatsNow()
.await
.map_err(|_| EdenFsError::Other(anyhow!("failed to call flushstatsNow")))
}

pub async fn get_regex_counters(
&self,
arg_regex: &str,
client: Option<&EdenFsClient>,
) -> Result<BTreeMap<String, i64>> {
let client = match client {
Some(client) => client,
None => &self.get_connected_thrift_client(None).await?,
};

client
.getRegexCounters(arg_regex)
.await
.map_err(|_| EdenFsError::Other(anyhow!("failed to get regex counters")))
}

pub async fn get_connected_thrift_client(
&self,
timeout: Option<Duration>,
Expand Down
16 changes: 12 additions & 4 deletions eden/fs/cli_rs/edenfs-commands/src/minitop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,9 @@ struct ImportStat {
async fn get_pending_import_counts(client: &EdenFsClient) -> Result<BTreeMap<String, ImportStat>> {
let mut imports = BTreeMap::<String, ImportStat>::new();

let counters = client.getRegexCounters(PENDING_COUNTER_REGEX).await?;
let counters = EdenFsInstance::global()
.get_regex_counters(PENDING_COUNTER_REGEX, Some(client))
.await?;
for import_type in IMPORT_OBJECT_TYPES {
let counter_prefix = format!("store.sapling.pending_import.{}", import_type);
let number_requests = counters
Expand All @@ -286,7 +288,9 @@ async fn get_pending_import_counts(client: &EdenFsClient) -> Result<BTreeMap<Str

async fn get_live_import_counts(client: &EdenFsClient) -> Result<BTreeMap<String, ImportStat>> {
let mut imports = BTreeMap::<String, ImportStat>::new();
let counters = client.getRegexCounters(LIVE_COUNTER_REGEX).await?;
let counters = EdenFsInstance::global()
.get_regex_counters(LIVE_COUNTER_REGEX, Some(client))
.await?;
for import_type in IMPORT_OBJECT_TYPES {
let single_prefix = format!("store.sapling.live_import.{}", import_type);
let batched_prefix = format!("store.sapling.live_import.batched_{}", import_type);
Expand Down Expand Up @@ -412,7 +416,9 @@ impl Cursor {
#[async_trait]
impl crate::Subcommand for MinitopCmd {
async fn run(&self) -> Result<ExitCode> {
let client = EdenFsInstance::global().connect(None).await?;
let client = EdenFsInstance::global()
.get_connected_thrift_client(None)
.await?;
let mut tracked_processes = TrackedProcesses::new();

let mut system = System::new();
Expand All @@ -434,7 +440,9 @@ impl crate::Subcommand for MinitopCmd {
if self.interactive {
queue!(stdout, terminal::Clear(terminal::ClearType::All))?;
}
client.flushStatsNow().await?;
EdenFsInstance::global()
.flush_stats_now(Some(&client))
.await?;
system.refresh_processes();
cursor.refresh_terminal_size()?;

Expand Down

0 comments on commit 2b562a4

Please sign in to comment.