Skip to content

Commit 2f24f7f

Browse files
muirdmfacebook-github-bot
authored andcommitted
filteredfs: switch to simpler metrics
Summary: See D66848951 for more details. Basically, use static counters from the "metrics" crate (which handle ods export internally). Reviewed By: MichaelCuevas Differential Revision: D67718795 fbshipit-source-id: 2fad3adaa359410491d9a3211f839ca0e95f1f5b
1 parent 8effb9e commit 2f24f7f

File tree

4 files changed

+18
-125
lines changed

4 files changed

+18
-125
lines changed

eden/integration/hg/filteredhg_test.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
filteredhg_test,
1515
FilteredHgTestCase,
1616
)
17-
1817
from eden.integration.lib import hgrepo
1918

2019

@@ -342,10 +341,7 @@ def test_ods_counters_exist(self) -> None:
342341
self.set_active_filter("top_level_filter")
343342
counters = self.get_counters()
344343
expected_counters = [
345-
"edenffi.ffs.invalid_repo",
346-
"edenffi.ffs.lookup_failures",
347344
"edenffi.ffs.lookups",
348-
"edenffi.ffs.repo_cache_hits",
349345
"edenffi.ffs.repo_cache_misses",
350346
]
351347
for ec in expected_counters:
@@ -354,7 +350,7 @@ def test_ods_counters_exist(self) -> None:
354350
def test_lookup_failure_counter(self) -> None:
355351
self.set_active_filter("top_level_filter")
356352
counters = self.get_counters()
357-
self.assertEqual(counters["edenffi.ffs.lookup_failures"], 0)
353+
self.assertNotIn("edenffi.ffs.lookup_failures", counters)
358354
self.set_active_filter("does_not_exist")
359355
counters = self.get_counters()
360356
self.assertGreaterEqual(counters["edenffi.ffs.lookup_failures"], 1)

eden/scm/lib/edenfs_ffi/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,21 @@ crate-type = ["lib", "staticlib"]
1616
[dependencies]
1717
anyhow = "1.0.95"
1818
cxx = "1.0.119"
19-
fbinit = { version = "0.2.0", git = "https://github.com/facebookexperimental/rust-shed.git", branch = "main", optional = true }
2019
once_cell = "1.12"
2120
parking_lot = { version = "0.12.1", features = ["send_guard"] }
2221
sapling-async-runtime = { version = "0.1.0", path = "../async-runtime" }
2322
sapling-identity = { version = "0.1.0", path = "../identity" }
2423
sapling-manifest = { version = "0.1.0", path = "../manifest" }
24+
sapling-metrics = { version = "0.1.0", path = "../metrics" }
2525
sapling-pathmatcher = { version = "0.1.0", path = "../pathmatcher" }
2626
sapling-repo = { version = "0.1.0", path = "../repo" }
2727
sapling-sparse = { version = "0.1.0", path = "../sparse" }
2828
sapling-types = { version = "0.1.0", path = "../types" }
29-
stats = { version = "0.1.0", git = "https://github.com/facebookexperimental/rust-shed.git", branch = "main", optional = true }
3029
tracing = { version = "0.1.41", features = ["attributes", "valuable"] }
3130

3231
[build-dependencies]
3332
cxx-build = "1.0.119"
3433

3534
[features]
36-
ods = ["fbinit", "stats"]
35+
default = []
36+
fb = []

eden/scm/lib/edenfs_ffi/src/lib.rs

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use cxx::UniquePtr;
1717
use manifest::FileMetadata;
1818
use manifest::FsNodeMetadata;
1919
use manifest::Manifest;
20+
use metrics::Counter;
2021
use once_cell::sync::Lazy;
2122
use parking_lot::Mutex;
2223
use pathmatcher::DirectoryMatch;
@@ -29,18 +30,21 @@ use types::HgId;
2930
use types::RepoPath;
3031
use types::RepoPathBuf;
3132

32-
mod metrics;
33-
3433
use crate::ffi::set_matcher_error;
3534
use crate::ffi::set_matcher_promise_error;
3635
use crate::ffi::set_matcher_promise_result;
3736
use crate::ffi::set_matcher_result;
3837
use crate::ffi::MatcherPromise;
3938
use crate::ffi::MatcherWrapper;
40-
use crate::metrics::FilteredFSMetrics;
4139

4240
static REPO_HASHMAP: Lazy<Mutex<HashMap<PathBuf, Repo>>> = Lazy::new(|| Mutex::new(HashMap::new()));
4341

42+
static LOOKUPS: Counter = Counter::new_counter("edenffi.ffs.lookups");
43+
static LOOKUP_FAILURES: Counter = Counter::new_counter("edenffi.ffs.lookup_failures");
44+
static INVALID_REPO: Counter = Counter::new_counter("edenffi.ffs.invalid_repo");
45+
static REPO_CACHE_MISSES: Counter = Counter::new_counter("edenffi.ffs.repo_cache_misses");
46+
static REPO_CACHE_HITS: Counter = Counter::new_counter("edenffi.ffs.repo_cache_hits");
47+
4448
// A helper class to parse/validate FilterIDs that are passed to Mercurial
4549
struct FilterId {
4650
pub repo_path: RepoPathBuf,
@@ -207,9 +211,8 @@ fn profile_contents_from_repo(
207211
id: FilterId,
208212
abs_repo_path: PathBuf,
209213
promise: UniquePtr<MatcherPromise>,
210-
metrics: &mut FilteredFSMetrics,
211214
) {
212-
match _profile_contents_from_repo(id, abs_repo_path, metrics) {
215+
match _profile_contents_from_repo(id, abs_repo_path) {
213216
Ok(res) => {
214217
set_matcher_promise_result(promise, res);
215218
}
@@ -223,18 +226,17 @@ fn profile_contents_from_repo(
223226
fn _profile_contents_from_repo(
224227
id: FilterId,
225228
abs_repo_path: PathBuf,
226-
metrics: &mut FilteredFSMetrics,
227229
) -> Result<Box<MercurialMatcher>, anyhow::Error> {
228230
let mut repo_map = REPO_HASHMAP.lock();
229231
if !repo_map.contains_key(&abs_repo_path) {
230232
// Load the repo and store it for later use
231-
metrics.repo_miss();
233+
REPO_CACHE_MISSES.increment();
232234
let repo = Repo::load(&abs_repo_path, &[]).with_context(|| {
233235
anyhow!("failed to load Repo object for {}", abs_repo_path.display())
234236
})?;
235237
repo_map.insert(abs_repo_path.clone(), repo);
236238
} else {
237-
metrics.repo_hit();
239+
REPO_CACHE_HITS.increment();
238240
}
239241
let repo = repo_map.get_mut(&abs_repo_path).context("loading repo")?;
240242

@@ -291,7 +293,7 @@ fn _profile_contents_from_repo(
291293
// invalid. Return an always matcher instead of erroring out.
292294
let sparse_matcher = matcher.unwrap_or_else(|e| {
293295
tracing::warn!("Failed to get sparse matcher for active filter: {:?}", e);
294-
metrics.failure();
296+
LOOKUP_FAILURES.increment();
295297
Matcher::new(
296298
vec![TreeMatcher::always()],
297299
vec![vec!["always_matcher".to_string()]],
@@ -310,8 +312,7 @@ pub fn profile_from_filter_id(
310312
checkout_path: &str,
311313
promise: UniquePtr<MatcherPromise>,
312314
) -> Result<(), anyhow::Error> {
313-
let mut metrics = FilteredFSMetrics::default();
314-
metrics.lookup();
315+
LOOKUPS.increment();
315316

316317
// Parse the FilterID
317318
let filter_id = FilterId::from_str(id)?;
@@ -320,7 +321,7 @@ pub fn profile_from_filter_id(
320321
// should correspond to a valid hg/sl repo that Mercurial is aware of.
321322
let abs_repo_path = PathBuf::from(checkout_path);
322323
if identity::sniff_dir(&abs_repo_path).is_err() {
323-
metrics.invalid_repo();
324+
INVALID_REPO.increment();
324325
return Err(anyhow!(
325326
"{} is not a valid hg repo",
326327
abs_repo_path.display()
@@ -330,12 +331,7 @@ pub fn profile_from_filter_id(
330331
// If we've already loaded a filter from this repo before, we can skip Repo
331332
// object creation. Otherwise, we need to pay the 1 time cost of creating
332333
// the Repo object.
333-
profile_contents_from_repo(filter_id, abs_repo_path, promise, &mut metrics);
334-
335-
// Update ODS counters with information about the filter we just loaded
336-
if let Err(err) = metrics.update_ods() {
337-
tracing::error!(?err, "error updating edenffi ods counters");
338-
}
334+
profile_contents_from_repo(filter_id, abs_repo_path, promise);
339335

340336
Ok(())
341337
}

eden/scm/lib/edenfs_ffi/src/metrics.rs

Lines changed: 0 additions & 99 deletions
This file was deleted.

0 commit comments

Comments
 (0)