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/combinators.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/combinators.rs')
-rw-r--r-- | tvix/castore/src/directoryservice/combinators.rs | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/tvix/castore/src/directoryservice/combinators.rs b/tvix/castore/src/directoryservice/combinators.rs index 4dfc19540c47..450c642715ac 100644 --- a/tvix/castore/src/directoryservice/combinators.rs +++ b/tvix/castore/src/directoryservice/combinators.rs @@ -22,13 +22,18 @@ use crate::Error; /// Inserts and listings are not implemented for now. #[derive(Clone)] pub struct Cache<DS1, DS2> { + instance_name: String, near: DS1, far: DS2, } impl<DS1, DS2> Cache<DS1, DS2> { - pub fn new(near: DS1, far: DS2) -> Self { - Self { near, far } + pub fn new(instance_name: String, near: DS1, far: DS2) -> Self { + Self { + instance_name, + near, + far, + } } } @@ -38,7 +43,7 @@ where DS1: DirectoryService + Clone + 'static, DS2: DirectoryService + Clone + 'static, { - #[instrument(skip(self, digest), fields(directory.digest = %digest))] + #[instrument(skip(self, digest), fields(directory.digest = %digest, instance_name = %self.instance_name))] async fn get(&self, digest: &B3Digest) -> Result<Option<Directory>, Error> { match self.near.get(digest).await? { Some(directory) => { @@ -80,12 +85,12 @@ where } } - #[instrument(skip_all)] + #[instrument(skip_all, fields(instance_name = %self.instance_name))] async fn put(&self, _directory: Directory) -> Result<B3Digest, Error> { Err(Error::StorageError("unimplemented".to_string())) } - #[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, @@ -166,7 +171,7 @@ impl ServiceBuilder for CacheConfig { 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>> { let (near, far) = futures::join!( @@ -174,6 +179,7 @@ impl ServiceBuilder for CacheConfig { context.resolve::<Self::Output>(self.far.clone()) ); Ok(Arc::new(Cache { + instance_name: instance_name.to_string(), near: near?, far: far?, })) |