Repository navigation
feat(storage): add gcp.storage.client.request.body.size metric for write operations #14746
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: feat/storage-ttfb-metric
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -284,7 +284,10 @@ public Blob create(BlobInfo blobInfo, InputStream content, BlobWriteOption... op | |||||||||||||||||||||
| .build(); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| try (UnbufferedWritableByteChannel c = session.open()) { | ||||||||||||||||||||||
| ByteStreams.copy(Channels.newChannel(inputStreamParam), c); | ||||||||||||||||||||||
| long copied = ByteStreams.copy(Channels.newChannel(inputStreamParam), c); | ||||||||||||||||||||||
| if (metricsContext != null) { | ||||||||||||||||||||||
| metricsContext.setRequestBytes(copied); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| ApiFuture<WriteObjectResponse> responseApiFuture = session.getResult(); | ||||||||||||||||||||||
| return this.getBlob(responseApiFuture); | ||||||||||||||||||||||
|
|
@@ -315,6 +318,9 @@ public Blob internalCreateFrom(Path path, BlobInfo info, Opts<ObjectTargetOpt> o | |||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| StorageMetricsContext multiContext = getOptions().createMultiStepMetricsContext("WriteObject"); | ||||||||||||||||||||||
| if (multiContext != null) { | ||||||||||||||||||||||
| multiContext.setRequestBytes(Files.size(path)); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| Throwable error = null; | ||||||||||||||||||||||
| try { | ||||||||||||||||||||||
|
Comment on lines
+321
to
325
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Calling
Suggested change
|
||||||||||||||||||||||
| GrpcCallContext grpcCallContext = | ||||||||||||||||||||||
|
|
@@ -400,7 +406,10 @@ public Blob createFrom( | |||||||||||||||||||||
| ReadableByteChannel src = | ||||||||||||||||||||||
| Channels.newChannel(firstNonNull(in, new ByteArrayInputStream(ZERO_BYTES))); | ||||||||||||||||||||||
| try (BufferedWritableByteChannel dst = session.open()) { | ||||||||||||||||||||||
| ByteStreams.copy(src, dst); | ||||||||||||||||||||||
| long copied = ByteStreams.copy(src, dst); | ||||||||||||||||||||||
| if (multiContext != null) { | ||||||||||||||||||||||
| multiContext.setRequestBytes(copied); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } catch (Exception e) { | ||||||||||||||||||||||
| throw StorageException.coalesce(e); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
@@ -938,6 +947,10 @@ public BlobInfo internalDirectUpload( | |||||||||||||||||||||
| WriteObjectRequest req = getWriteObjectRequest(blobInfo, optsWithDefaults); | ||||||||||||||||||||||
| Hasher hasher = opts.getHasher(); | ||||||||||||||||||||||
| StorageMetricsContext metricsContext = getOptions().createMetricsContext("WriteObject"); | ||||||||||||||||||||||
| int totalBytes = buf.remaining(); | ||||||||||||||||||||||
| if (metricsContext != null) { | ||||||||||||||||||||||
| metricsContext.setRequestBytes(totalBytes); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| GrpcCallContext merge = Utils.merge(grpcCallContext, Retrying.newCallContext(metricsContext)); | ||||||||||||||||||||||
| RewindableContent content = RewindableContent.of(buf); | ||||||||||||||||||||||
| return retrier.run( | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.