@@ -17,6 +17,7 @@ use cxx::UniquePtr;
1717use manifest:: FileMetadata ;
1818use manifest:: FsNodeMetadata ;
1919use manifest:: Manifest ;
20+ use metrics:: Counter ;
2021use once_cell:: sync:: Lazy ;
2122use parking_lot:: Mutex ;
2223use pathmatcher:: DirectoryMatch ;
@@ -29,18 +30,21 @@ use types::HgId;
2930use types:: RepoPath ;
3031use types:: RepoPathBuf ;
3132
32- mod metrics;
33-
3433use crate :: ffi:: set_matcher_error;
3534use crate :: ffi:: set_matcher_promise_error;
3635use crate :: ffi:: set_matcher_promise_result;
3736use crate :: ffi:: set_matcher_result;
3837use crate :: ffi:: MatcherPromise ;
3938use crate :: ffi:: MatcherWrapper ;
40- use crate :: metrics:: FilteredFSMetrics ;
4139
4240static 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
4549struct 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(
223226fn _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}
0 commit comments