Skip to content
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

chore: remove unnecessary context propagation #2853

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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<ObjectTargetOpt> 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());
Expand All @@ -333,11 +329,10 @@ public Blob createFrom(BlobInfo blobInfo, Path path, int bufferSize, BlobWriteOp
}

@Override
public Blob internalCreateFrom(
Path path, BlobInfo info, Opts<ObjectTargetOpt> opts, OpenTelemetryTraceUtil.Context ctx)
public Blob internalCreateFrom(Path path, BlobInfo info, Opts<ObjectTargetOpt> 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");
Expand Down Expand Up @@ -897,19 +892,10 @@ public GrpcBlobWriteChannel writer(BlobInfo blobInfo, BlobWriteOption... options
@Override
public BlobInfo internalDirectUpload(
BlobInfo blobInfo, Opts<ObjectTargetOpt> opts, ByteBuffer buf) {
return internalDirectUpload(blobInfo, opts, buf, null);
}

@Override
public BlobInfo internalDirectUpload(
BlobInfo blobInfo,
Opts<ObjectTargetOpt> 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<ObjectTargetOpt> optsWithDefaults = opts.prepend(defaultOpts);
GrpcCallContext grpcCallContext =
optsWithDefaults.grpcMetadataMapper().apply(GrpcCallContext.createDefault());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1796,11 +1796,7 @@ public BlobInfo internalCreateFrom(Path path, BlobInfo info, Opts<ObjectTargetOp
}

@Override
public BlobInfo internalDirectUpload(
BlobInfo info,
Opts<ObjectTargetOpt> opts,
ByteBuffer buf,
OpenTelemetryTraceUtil.Context ctx) {
public BlobInfo internalDirectUpload(BlobInfo info, Opts<ObjectTargetOpt> opts, ByteBuffer buf) {

BlobInfo.Builder builder =
info.toBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -32,25 +31,11 @@ default BlobInfo internalCreateFrom(Path path, BlobInfo info, Opts<ObjectTargetO
throw new UnsupportedOperationException("not implemented");
}

default BlobInfo internalCreateFrom(
Path path, BlobInfo info, Opts<ObjectTargetOpt> opts, OpenTelemetryTraceUtil.Context ctx)
throws IOException {
throw new UnsupportedOperationException("not implemented");
}

default BlobInfo internalDirectUpload(
BlobInfo blobInfo, Opts<ObjectTargetOpt> opts, ByteBuffer buf) {
throw new UnsupportedOperationException("not implemented");
}

default BlobInfo internalDirectUpload(
BlobInfo info,
Opts<ObjectTargetOpt> 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<ObjectSourceOpt> opts) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -1196,21 +1196,17 @@ 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();
span.end(HttpStorageRpcSpans.END_SPAN_OPTIONS);
}
}

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) {
Expand Down
Loading