about summary refs log tree commit diff
path: root/tvix/store/src/pathinfoservice/combinators.rs
diff options
context:
space:
mode:
authorBob van der Linden <bobvanderlinden@gmail.com>2024-11-06T22·13+0100
committerclbot <clbot@tvl.fyi>2024-11-08T20·16+0000
commitcfa4154131719db3ff687261bca95481cba609ab (patch)
tree7fa2da507295b48d861e76f1c26851fd0a55855f /tvix/store/src/pathinfoservice/combinators.rs
parent951d25676b8a61f3068d7d54958695739a71aa68 (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/store/src/pathinfoservice/combinators.rs')
-rw-r--r--tvix/store/src/pathinfoservice/combinators.rs18
1 files changed, 12 insertions, 6 deletions
diff --git a/tvix/store/src/pathinfoservice/combinators.rs b/tvix/store/src/pathinfoservice/combinators.rs
index f386fd52dc3c..df0046875057 100644
--- a/tvix/store/src/pathinfoservice/combinators.rs
+++ b/tvix/store/src/pathinfoservice/combinators.rs
@@ -15,13 +15,18 @@ use super::{PathInfo, PathInfoService};
 /// There is no negative cache.
 /// Inserts and listings are not implemented for now.
 pub struct Cache<PS1, PS2> {
+    instance_name: String,
     near: PS1,
     far: PS2,
 }
 
 impl<PS1, PS2> Cache<PS1, PS2> {
-    pub fn new(near: PS1, far: PS2) -> Self {
-        Self { near, far }
+    pub fn new(instance_name: String, near: PS1, far: PS2) -> Self {
+        Self {
+            instance_name,
+            near,
+            far,
+        }
     }
 }
 
@@ -31,7 +36,7 @@ where
     PS1: PathInfoService,
     PS2: PathInfoService,
 {
-    #[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<Option<PathInfo>, Error> {
         match self.near.get(digest).await? {
             Some(path_info) => {
@@ -84,7 +89,7 @@ impl ServiceBuilder for CacheConfig {
     type Output = dyn PathInfoService;
     async fn build<'a>(
         &'a self,
-        _instance_name: &str,
+        instance_name: &str,
         context: &CompositionContext,
     ) -> Result<Arc<dyn PathInfoService>, Box<dyn std::error::Error + Send + Sync + 'static>> {
         let (near, far) = futures::join!(
@@ -92,6 +97,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?,
         }))
@@ -114,10 +120,10 @@ mod test {
         let far = MemoryPathInfoService::default();
 
         // … and an instance of a "near" PathInfoService.
-        let near = LruPathInfoService::with_capacity(NonZeroUsize::new(1).unwrap());
+        let near = LruPathInfoService::with_capacity("test".into(), NonZeroUsize::new(1).unwrap());
 
         // create a Pathinfoservice combining the two and return it.
-        super::Cache::new(near, far)
+        super::Cache::new("test".into(), near, far)
     }
 
     /// Getting from the far backend is gonna insert it into the near one.