Skip to content

Commit a9dde43

Browse files
janezhang10meta-codesync[bot]
authored andcommitted
Wire up XplatLogger for edenfs_events in Rust CLI and config manager
Summary: Add config-gated routing so edenfs_events telemetry can use XplatLogger instead of the legacy ScubaClient/scribe_cat path. The config flag enable-xplatlogger-events is read from the EdenFS daemon (via thrift) for CLI commands and from the TOML config for the config manager. - Add send_sample_with_xplatlogger() in edenfs-commands that queries daemon config before routing. If daemon is not running when config is read, it will read the local config (~/.edenrc) - Add create_telemetry_logger_from_options_with_xplatlogger() in config manager for TOML-based routing - Add create_logger_with_xplatlogger() and send_with_xplatlogger() APIs in edenfs-telemetry - Add ConfigData::get_bool() and EdenFsClient::get_enable_xplatlogger_events() for reading the config from the daemon - Refactor telemetry_disabled() for reuse across logger creation paths Reviewed By: muirdm, kavehahmadi60 Differential Revision: D105882904 fbshipit-source-id: 1e5a6edd9a1b2f17a00088d28421722795a8ee6c
1 parent 44be98b commit a9dde43

2 files changed

Lines changed: 45 additions & 0 deletions

File tree

eden/fs/cli_rs/edenfs-client/src/config.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ use crate::client::Client;
1717
use crate::client::EdenFsClient;
1818
use crate::methods::EdenThriftMethod;
1919

20+
pub const ENABLE_XPLATLOGGER_EVENTS_CONFIG_KEY: &str = "telemetry:enable-xplatlogger-events";
21+
2022
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
2123
pub enum ConfigSourceType {
2224
Default = 0,
@@ -63,6 +65,16 @@ pub struct ConfigData {
6365
pub values: BTreeMap<String, ConfigValue>,
6466
}
6567

68+
impl ConfigData {
69+
pub fn get_bool(&self, key: &str) -> Option<bool> {
70+
match self.values.get(key)?.parsed_value.as_str() {
71+
"true" | "1" => Some(true),
72+
"false" | "0" => Some(false),
73+
_ => None,
74+
}
75+
}
76+
}
77+
6678
impl From<thrift_types::edenfs_config::EdenConfigData> for ConfigData {
6779
fn from(from: thrift_types::edenfs_config::EdenConfigData) -> Self {
6880
Self {
@@ -84,4 +96,23 @@ impl EdenFsClient {
8496
.map(|config_data| config_data.into())
8597
.map_err(EdenFsError::from)
8698
}
99+
100+
pub async fn get_enable_xplatlogger_events(&self) -> bool {
101+
match self.get_config_default().await {
102+
Ok(config) => {
103+
let enabled = config
104+
.get_bool(ENABLE_XPLATLOGGER_EVENTS_CONFIG_KEY)
105+
.unwrap_or(false);
106+
tracing::debug!(enabled, "read edenfs_events XplatLogger config from daemon");
107+
enabled
108+
}
109+
Err(error) => {
110+
tracing::debug!(
111+
?error,
112+
"failed to read edenfs_events XplatLogger config; using legacy logger"
113+
);
114+
false
115+
}
116+
}
117+
}
87118
}

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,20 @@ pub(crate) fn get_edenfs_instance() -> &'static EdenFsInstance {
6565
.expect("EdenFsInstance is not initialized")
6666
}
6767

68+
#[cfg(fbcode_build)]
69+
pub(crate) async fn send_sample_with_config(
70+
data_set: &'static str,
71+
xplat_logger_config: edenfs_telemetry::XplatLoggerConfig,
72+
sample: edenfs_telemetry::EdenSample,
73+
) {
74+
let xplat_logger_config = get_edenfs_instance()
75+
.get_client()
76+
.get_enable_xplatlogger_events()
77+
.await
78+
.then_some(xplat_logger_config);
79+
edenfs_telemetry::send_with_config(data_set, sample, xplat_logger_config);
80+
}
81+
6882
fn init_edenfs_instance(
6983
config_dir: PathBuf,
7084
etc_eden_dir: PathBuf,

0 commit comments

Comments
 (0)