From cfa4154131719db3ff687261bca95481cba609ab Mon Sep 17 00:00:00 2001 From: Bob van der Linden Date: Wed, 6 Nov 2024 23:13:33 +0100 Subject: feat(tvix): add instance_name to instrumentation of *Services Currently it is not possible to distinguish between tracing of the same *Service type whenever there are multiple of them. Now the instance_name of ServiceBuilder is passed into the *Service and used in the existing instrument as the `instance_name` field. Places that did not already have a instance_name in its context use `"default"`. In tests I used `"test"`. Change-Id: Ia20bf2a7bb849a781e370d087ba7ddb3be79f654 Reviewed-on: https://cl.tvl.fyi/c/depot/+/12739 Tested-by: BuildkiteCI Autosubmit: Bob van der Linden Reviewed-by: flokli --- tvix/store/src/pathinfoservice/lru.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'tvix/store/src/pathinfoservice/lru.rs') diff --git a/tvix/store/src/pathinfoservice/lru.rs b/tvix/store/src/pathinfoservice/lru.rs index 3055d73c22f9..0b55441860fe 100644 --- a/tvix/store/src/pathinfoservice/lru.rs +++ b/tvix/store/src/pathinfoservice/lru.rs @@ -14,12 +14,14 @@ use tvix_castore::Error; use super::{PathInfo, PathInfoService}; pub struct LruPathInfoService { + instance_name: String, lru: Arc>>, } impl LruPathInfoService { - pub fn with_capacity(capacity: NonZeroUsize) -> Self { + pub fn with_capacity(instance_name: String, capacity: NonZeroUsize) -> Self { Self { + instance_name, lru: Arc::new(RwLock::new(LruCache::new(capacity))), } } @@ -27,12 +29,12 @@ impl LruPathInfoService { #[async_trait] impl PathInfoService for LruPathInfoService { - #[instrument(level = "trace", skip_all, fields(path_info.digest = nixbase32::encode(&digest)))] + #[instrument(level = "trace", skip_all, fields(path_info.digest = nixbase32::encode(&digest), instance_name = %self.instance_name))] async fn get(&self, digest: [u8; 20]) -> Result, Error> { Ok(self.lru.write().await.get(&digest).cloned()) } - #[instrument(level = "trace", skip_all, fields(path_info.root_node = ?path_info.node))] + #[instrument(level = "trace", skip_all, fields(path_info.root_node = ?path_info.node, instance_name = %self.instance_name))] async fn put(&self, path_info: PathInfo) -> Result { self.lru .write() @@ -76,10 +78,13 @@ impl ServiceBuilder for LruPathInfoServiceConfig { type Output = dyn PathInfoService; async fn build<'a>( &'a self, - _instance_name: &str, + instance_name: &str, _context: &CompositionContext, ) -> Result, Box> { - Ok(Arc::new(LruPathInfoService::with_capacity(self.capacity))) + Ok(Arc::new(LruPathInfoService::with_capacity( + instance_name.to_string(), + self.capacity, + ))) } } @@ -103,7 +108,7 @@ mod test { #[tokio::test] async fn evict() { - let svc = LruPathInfoService::with_capacity(NonZeroUsize::new(1).unwrap()); + let svc = LruPathInfoService::with_capacity("test".into(), NonZeroUsize::new(1).unwrap()); // pathinfo_1 should not be there assert!(svc -- cgit 1.4.1