Repository navigation
feat(storage): add gcp.storage.client.request.body.size metric for write operations - #14746
nidhiii-27 wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces request body size tracking for 'WriteObject' operations in Google Cloud Storage by capturing and recording request bytes in the StorageMetricsContext. However, a critical compilation error was identified in GrpcStorageImpl.java where Files.size(path) is called outside of a try-catch block, throwing an unhandled checked IOException. Moving this call inside the try block will resolve the compilation issue and ensure proper exception handling.
| if (multiContext != null) { | ||
| multiContext.setRequestBytes(Files.size(path)); | ||
| } | ||
| Throwable error = null; | ||
| try { |
There was a problem hiding this comment.
Calling Files.size(path) throws a checked IOException. Since internalCreateFrom does not declare throws IOException, calling it outside of the try block will cause a compilation error. Additionally, if an I/O error occurs, it should be caught within the try-catch block so that the exception is properly translated to a StorageException and the metrics context can record the failure in its finally block. Moving this call inside the try block resolves both issues.
| if (multiContext != null) { | |
| multiContext.setRequestBytes(Files.size(path)); | |
| } | |
| Throwable error = null; | |
| try { | |
| Throwable error = null; | |
| try { | |
| if (multiContext != null) { | |
| multiContext.setRequestBytes(Files.size(path)); | |
| } |
There was a problem hiding this comment.
Code Review
This pull request implements tracking and recording of request body sizes for 'WriteObject' operations across various storage implementation classes, including BaseStorageWriteChannel, GrpcStorageImpl, and StorageImpl, using StorageMetricsContext. It also adds unit tests to verify this behavior. A review comment suggests moving the Files.size(path) call inside the try block in GrpcStorageImpl.java to ensure that any potential IOException is properly caught and handled by the existing error-handling logic.
| if (multiContext != null) { | ||
| multiContext.setRequestBytes(Files.size(path)); | ||
| } | ||
| Throwable error = null; | ||
| try { |
There was a problem hiding this comment.
Calling Files.size(path) outside of the try block can cause issues. Since Files.size(path) throws a checked IOException, calling it outside the try block means any thrown exception will bypass the error handling and metrics recording logic. Moving this call inside the try block ensures that any IOException is properly caught, recorded as an error in the metrics context, and handled consistently.
| if (multiContext != null) { | |
| multiContext.setRequestBytes(Files.size(path)); | |
| } | |
| Throwable error = null; | |
| try { | |
| Throwable error = null; | |
| try { | |
| if (multiContext != null) { | |
| multiContext.setRequestBytes(Files.size(path)); | |
| } |
Instruments write operations across HTTP and gRPC veneers to record
gcp.storage.client.request.body.sizeOpenTelemetry histogram metrics.StorageMetricsContext(addBytesSent,setBytesSent) and recordsgcp.storage.client.request.body.sizeon operation completion.BaseStorageWriteChannel,StorageImpl, andGrpcStorageImplto track uploaded payload bytes across unary and streaming writes.gcp.storage.client.request.body.sizeinStorageClientMetricsand adds unit tests inStorageMetricsContextTest,StorageByteCountingTest, andStorageClientMetricsTest.Stacked on #14745.