From 9c67cb72ebdd140dfdce8b15091b276a5681af6f Mon Sep 17 00:00:00 2001 From: Sydney Munro <97561403+sydney-munro@users.noreply.github.com> Date: Tue, 17 Dec 2024 09:07:28 -0800 Subject: [PATCH] chore: remove unnecessary context propagation --- .../google/cloud/storage/GrpcStorageImpl.java | 24 ++++--------------- ...lelCompositeUploadWritableByteChannel.java | 2 -- .../com/google/cloud/storage/StorageImpl.java | 6 +---- .../google/cloud/storage/StorageInternal.java | 15 ------------ .../cloud/storage/spi/v1/HttpStorageRpc.java | 12 ++++------ 5 files changed, 10 insertions(+), 49 deletions(-) diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/GrpcStorageImpl.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/GrpcStorageImpl.java index d15b53dadf..1747772d42 100644 --- a/google-cloud-storage/src/main/java/com/google/cloud/storage/GrpcStorageImpl.java +++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/GrpcStorageImpl.java @@ -255,11 +255,7 @@ public Blob create( OpenTelemetryTraceUtil.Span otelSpan = openTelemetryTraceUtil.startSpan("create", MODULE_STORAGE); try (OpenTelemetryTraceUtil.Scope ignored = otelSpan.makeCurrent()) { - return internalDirectUpload( - blobInfo, - opts, - ByteBuffer.wrap(content, offset, length), - openTelemetryTraceUtil.currentContext()) + return internalDirectUpload(blobInfo, opts, ByteBuffer.wrap(content, offset, length)) .asBlob(this); } catch (Exception e) { otelSpan.recordException(e); @@ -322,7 +318,7 @@ public Blob createFrom(BlobInfo blobInfo, Path path, int bufferSize, BlobWriteOp openTelemetryTraceUtil.startSpan("createFrom", MODULE_STORAGE); try (OpenTelemetryTraceUtil.Scope ignored = otelSpan.makeCurrent()) { Opts opts = Opts.unwrap(options).resolveFrom(blobInfo).prepend(defaultOpts); - return internalCreateFrom(path, blobInfo, opts, openTelemetryTraceUtil.currentContext()); + return internalCreateFrom(path, blobInfo, opts); } catch (Exception e) { otelSpan.recordException(e); otelSpan.setStatus(io.opentelemetry.api.trace.StatusCode.ERROR, e.getClass().getSimpleName()); @@ -333,11 +329,10 @@ public Blob createFrom(BlobInfo blobInfo, Path path, int bufferSize, BlobWriteOp } @Override - public Blob internalCreateFrom( - Path path, BlobInfo info, Opts opts, OpenTelemetryTraceUtil.Context ctx) + public Blob internalCreateFrom(Path path, BlobInfo info, Opts opts) throws IOException { OpenTelemetryTraceUtil.Span otelSpan = - openTelemetryTraceUtil.startSpan("internalCreateFrom", MODULE_STORAGE, ctx); + openTelemetryTraceUtil.startSpan("internalCreateFrom", MODULE_STORAGE); requireNonNull(path, "path must be non null"); if (Files.isDirectory(path)) { throw new StorageException(0, path + " is a directory"); @@ -897,19 +892,10 @@ public GrpcBlobWriteChannel writer(BlobInfo blobInfo, BlobWriteOption... options @Override public BlobInfo internalDirectUpload( BlobInfo blobInfo, Opts opts, ByteBuffer buf) { - return internalDirectUpload(blobInfo, opts, buf, null); - } - - @Override - public BlobInfo internalDirectUpload( - BlobInfo blobInfo, - Opts opts, - ByteBuffer buf, - OpenTelemetryTraceUtil.Context ctx) { requireNonNull(blobInfo, "blobInfo must be non null"); requireNonNull(buf, "content must be non null"); OpenTelemetryTraceUtil.Span otelSpan = - openTelemetryTraceUtil.startSpan("internalDirectUpload", MODULE_STORAGE, ctx); + openTelemetryTraceUtil.startSpan("internalDirectUpload", MODULE_STORAGE); Opts optsWithDefaults = opts.prepend(defaultOpts); GrpcCallContext grpcCallContext = optsWithDefaults.grpcMetadataMapper().apply(GrpcCallContext.createDefault()); diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/ParallelCompositeUploadWritableByteChannel.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/ParallelCompositeUploadWritableByteChannel.java index 0d08759d1f..db807ce6ce 100644 --- a/google-cloud-storage/src/main/java/com/google/cloud/storage/ParallelCompositeUploadWritableByteChannel.java +++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/ParallelCompositeUploadWritableByteChannel.java @@ -219,7 +219,6 @@ public void close() throws IOException { // We never created any parts // create an empty object try { - // TODO: Add in Otel context when available BlobInfo blobInfo = storage.internalDirectUpload(ultimateObject, opts, Buffers.allocate(0)); finalObject.set(blobInfo); return; @@ -286,7 +285,6 @@ private void internalFlush(ByteBuffer buf) { ApiFutures.immediateFuture(partInfo), info -> { try { - // TODO: Add in Otel context when available return storage.internalDirectUpload(info, partOpts, buf); } catch (StorageException e) { // a precondition failure usually means the part was created, but we didn't get the diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/StorageImpl.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/StorageImpl.java index 053bc45ede..4f7ae06cb1 100644 --- a/google-cloud-storage/src/main/java/com/google/cloud/storage/StorageImpl.java +++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/StorageImpl.java @@ -1796,11 +1796,7 @@ public BlobInfo internalCreateFrom(Path path, BlobInfo info, Opts opts, - ByteBuffer buf, - OpenTelemetryTraceUtil.Context ctx) { + public BlobInfo internalDirectUpload(BlobInfo info, Opts opts, ByteBuffer buf) { BlobInfo.Builder builder = info.toBuilder() diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/StorageInternal.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/StorageInternal.java index 8fd230a19c..fa150d64d8 100644 --- a/google-cloud-storage/src/main/java/com/google/cloud/storage/StorageInternal.java +++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/StorageInternal.java @@ -20,7 +20,6 @@ import com.google.cloud.storage.UnifiedOpts.ObjectSourceOpt; import com.google.cloud.storage.UnifiedOpts.ObjectTargetOpt; import com.google.cloud.storage.UnifiedOpts.Opts; -import com.google.cloud.storage.otel.OpenTelemetryTraceUtil; import java.io.IOException; import java.nio.ByteBuffer; import java.nio.file.Path; @@ -32,25 +31,11 @@ default BlobInfo internalCreateFrom(Path path, BlobInfo info, Opts opts, OpenTelemetryTraceUtil.Context ctx) - throws IOException { - throw new UnsupportedOperationException("not implemented"); - } - default BlobInfo internalDirectUpload( BlobInfo blobInfo, Opts opts, ByteBuffer buf) { throw new UnsupportedOperationException("not implemented"); } - default BlobInfo internalDirectUpload( - BlobInfo info, - Opts opts, - ByteBuffer buf, - OpenTelemetryTraceUtil.Context ctx) { - throw new UnsupportedOperationException("not implemented"); - } - // Void to allow easier mapping/use within streams and other mapping contexts @SuppressWarnings("UnusedReturnValue") default Void internalObjectDelete(BlobId id, Opts opts) { diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/spi/v1/HttpStorageRpc.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/spi/v1/HttpStorageRpc.java index 9f449c36f6..84621063b9 100644 --- a/google-cloud-storage/src/main/java/com/google/cloud/storage/spi/v1/HttpStorageRpc.java +++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/spi/v1/HttpStorageRpc.java @@ -1181,7 +1181,7 @@ public RewriteResponse openRewrite(RewriteRequest rewriteRequest) { Span span = startSpan(HttpStorageRpcSpans.SPAN_NAME_OPEN_REWRITE); Scope scope = tracer.withSpan(span); try (OpenTelemetryTraceUtil.Scope ignored = otelSpan.makeCurrent()) { - return rewrite(rewriteRequest, null, openTelemetryTraceUtil.currentContext()); + return rewrite(rewriteRequest, null); } finally { otelSpan.end(); scope.close(); @@ -1196,10 +1196,7 @@ public RewriteResponse continueRewrite(RewriteResponse previousResponse) { Span span = startSpan(HttpStorageRpcSpans.SPAN_NAME_CONTINUE_REWRITE); Scope scope = tracer.withSpan(span); try (OpenTelemetryTraceUtil.Scope ignored = otelSpan.makeCurrent()) { - return rewrite( - previousResponse.rewriteRequest, - previousResponse.rewriteToken, - openTelemetryTraceUtil.currentContext()); + return rewrite(previousResponse.rewriteRequest, previousResponse.rewriteToken); } finally { otelSpan.end(); scope.close(); @@ -1207,10 +1204,9 @@ public RewriteResponse continueRewrite(RewriteResponse previousResponse) { } } - private RewriteResponse rewrite( - RewriteRequest req, String token, OpenTelemetryTraceUtil.Context ctx) { + private RewriteResponse rewrite(RewriteRequest req, String token) { OpenTelemetryTraceUtil.Span otelSpan = - openTelemetryTraceUtil.startSpan("rewrite", MODULE_STORAGE_RPC, ctx); + openTelemetryTraceUtil.startSpan("rewrite", MODULE_STORAGE_RPC); try (OpenTelemetryTraceUtil.Scope ignored = otelSpan.makeCurrent()) { String userProject = Option.USER_PROJECT.getString(req.sourceOptions); if (userProject == null) {