Skip to content

feat(storage): add gcp.storage.client.request.body.size metric for write operations - #14746

Draft
nidhiii-27 wants to merge 1 commit into
feat/storage-ttfb-metricfrom
feat/storage-request-body-size
Draft

nidhiii-27 wants to merge 1 commit into
feat/storage-ttfb-metricfrom
feat/storage-request-body-size

Conversation

@nidhiii-27

Copy link
Copy Markdown
Contributor

Instruments write operations across HTTP and gRPC veneers to record gcp.storage.client.request.body.size OpenTelemetry histogram metrics.

  • Adds byte counting tracking in StorageMetricsContext (addBytesSent, setBytesSent) and records gcp.storage.client.request.body.size on operation completion.
  • Instruments BaseStorageWriteChannel, StorageImpl, and GrpcStorageImpl to track uploaded payload bytes across unary and streaming writes.
  • Initializes gcp.storage.client.request.body.size in StorageClientMetrics and adds unit tests in StorageMetricsContextTest, StorageByteCountingTest, and StorageClientMetricsTest.

Stacked on #14745.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +321 to 325
if (multiContext != null) {
multiContext.setRequestBytes(Files.size(path));
}
Throwable error = null;
try {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

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.

Suggested change
if (multiContext != null) {
multiContext.setRequestBytes(Files.size(path));
}
Throwable error = null;
try {
Throwable error = null;
try {
if (multiContext != null) {
multiContext.setRequestBytes(Files.size(path));
}

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +321 to 325
if (multiContext != null) {
multiContext.setRequestBytes(Files.size(path));
}
Throwable error = null;
try {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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.

Suggested change
if (multiContext != null) {
multiContext.setRequestBytes(Files.size(path));
}
Throwable error = null;
try {
Throwable error = null;
try {
if (multiContext != null) {
multiContext.setRequestBytes(Files.size(path));
}

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant