diff options
author | Bob van der Linden <bobvanderlinden@gmail.com> | 2024-11-06T22·13+0100 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2024-11-08T20·16+0000 |
commit | cfa4154131719db3ff687261bca95481cba609ab (patch) | |
tree | 7fa2da507295b48d861e76f1c26851fd0a55855f /tvix/castore/src/directoryservice/memory.rs | |
parent | 951d25676b8a61f3068d7d54958695739a71aa68 (diff) |
feat(tvix): add instance_name to instrumentation of *Services r/8896
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 <bobvanderlinden@gmail.com> Reviewed-by: flokli <flokli@flokli.de>
Diffstat (limited to 'tvix/castore/src/directoryservice/memory.rs')
-rw-r--r-- | tvix/castore/src/directoryservice/memory.rs | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/tvix/castore/src/directoryservice/memory.rs b/tvix/castore/src/directoryservice/memory.rs index b039d9bc7d84..a43d7b8d8d31 100644 --- a/tvix/castore/src/directoryservice/memory.rs +++ b/tvix/castore/src/directoryservice/memory.rs @@ -13,12 +13,13 @@ use crate::proto; #[derive(Clone, Default)] pub struct MemoryDirectoryService { + instance_name: String, db: Arc<RwLock<HashMap<B3Digest, proto::Directory>>>, } #[async_trait] impl DirectoryService for MemoryDirectoryService { - #[instrument(skip(self, digest), fields(directory.digest = %digest))] + #[instrument(skip(self, digest), err, fields(directory.digest = %digest, instance_name=%self.instance_name))] async fn get(&self, digest: &B3Digest) -> Result<Option<Directory>, Error> { let db = self.db.read().await; @@ -45,7 +46,7 @@ impl DirectoryService for MemoryDirectoryService { } } - #[instrument(skip(self, directory), fields(directory.digest = %directory.digest()))] + #[instrument(skip(self, directory), err, fields(directory.digest = %directory.digest(), instance_name=%self.instance_name))] async fn put(&self, directory: Directory) -> Result<B3Digest, Error> { let digest = directory.digest(); @@ -56,7 +57,7 @@ impl DirectoryService for MemoryDirectoryService { Ok(digest) } - #[instrument(skip_all, fields(directory.digest = %root_directory_digest))] + #[instrument(skip_all, fields(directory.digest = %root_directory_digest, instance_name=%self.instance_name))] fn get_recursive( &self, root_directory_digest: &B3Digest, @@ -64,7 +65,7 @@ impl DirectoryService for MemoryDirectoryService { traverse_directory(self.clone(), root_directory_digest) } - #[instrument(skip_all)] + #[instrument(skip_all, fields(instance_name=%self.instance_name))] fn put_multiple_start(&self) -> Box<(dyn DirectoryPutter + 'static)> where Self: Clone, @@ -93,9 +94,12 @@ impl ServiceBuilder for MemoryDirectoryServiceConfig { type Output = dyn DirectoryService; async fn build<'a>( &'a self, - _instance_name: &str, + instance_name: &str, _context: &CompositionContext, ) -> Result<Arc<dyn DirectoryService>, Box<dyn std::error::Error + Send + Sync + 'static>> { - Ok(Arc::new(MemoryDirectoryService::default())) + Ok(Arc::new(MemoryDirectoryService { + instance_name: instance_name.to_string(), + db: Default::default(), + })) } } |