alamb commented on code in PR #18016:
URL: https://github.com/apache/datafusion/pull/18016#discussion_r2422748604


##########
datafusion-cli/src/object_storage/instrumented.rs:
##########
@@ -129,6 +167,12 @@ impl ObjectStore for InstrumentedObjectStore {
     }
 
     async fn get_opts(&self, location: &Path, options: GetOptions) -> 
Result<GetResult> {
+        if self.instrument_mode.load(Ordering::Relaxed)

Review Comment:
   It might make the code cleaner to move the load ordering into its own method 
-- like
   
   Something like this maybe
   
   ```rust
   impl InstrumentedObjectStore {
     /// return the current mode of this instrumented store
     fn enabled(&self) -> bool {
       self.instrument_mode.load(Ordering::Relaxed) != 
InstrumentedObjectStoreMode::Disabled
     }
   }
   ```



##########
datafusion-cli/src/object_storage/instrumented.rs:
##########
@@ -275,4 +368,48 @@ mod tests {
         assert!(fetched.is_ok());
         assert_eq!(reg.stores().len(), 1);
     }
+
+    #[tokio::test]
+    async fn instrumented_store() {
+        let store = Arc::new(object_store::memory::InMemory::new());
+        let mode = AtomicU8::new(InstrumentedObjectStoreMode::default() as u8);
+        let instrumented = InstrumentedObjectStore::new(store, mode);
+
+        // Load the test store with some data we can read
+        let path = Path::from("test/data");
+        let payload = PutPayload::from_static(b"test_data");
+        instrumented.put(&path, payload).await.unwrap();
+
+        // By default no requests should be instrumented/stored
+        assert!(instrumented.requests.lock().is_empty());
+        let _ = instrumented.get(&path).await.unwrap();
+        assert!(instrumented.requests.lock().is_empty());
+
+        instrumented.set_instrument_mode(InstrumentedObjectStoreMode::Enabled);
+        assert!(instrumented.requests.lock().is_empty());
+        let _ = instrumented.get(&path).await.unwrap();
+        assert_eq!(instrumented.requests.lock().len(), 1);
+
+        let requests = instrumented.take_requests();
+        assert_eq!(requests.len(), 1);
+        assert!(instrumented.requests.lock().is_empty());

Review Comment:
   I think it would be good here to assert on the contents of the request too 
-- to make sure that all fields got captured
   
   For example:
   ```rust
   assert_eq!(requests[0].op, Operation::Get);
   // check other fields, etc
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to