Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pr comments
Browse files Browse the repository at this point in the history
sydney-munro committed Dec 18, 2024
1 parent 7c19e78 commit 92989f5
Showing 7 changed files with 55 additions and 69 deletions.
Original file line number Diff line number Diff line change
@@ -120,7 +120,7 @@ public final class GrpcStorageOptions extends StorageOptions
private final boolean grpcClientMetricsManuallyEnabled;
private final GrpcInterceptorProvider grpcInterceptorProvider;
private final BlobWriteSessionConfig blobWriteSessionConfig;
private OpenTelemetrySdk openTelemetrySdk;
private final OpenTelemetrySdk openTelemetrySdk;

private GrpcStorageOptions(Builder builder, GrpcStorageDefaults serviceDefaults) {
super(builder, serviceDefaults);
@@ -634,7 +634,9 @@ public GrpcStorageOptions.Builder setBlobWriteSessionConfig(
* Enable OpenTelemetry Tracing and provide an instance for the client to use.
*
* @param openTelemetrySdk User defined instance of OpenTelemetry SDK to be used by the library
* @since 2.46.1 This new api is in preview and is subject to breaking changes.
*/
@BetaApi
public GrpcStorageOptions.Builder setOpenTelemetrySdk(OpenTelemetrySdk openTelemetrySdk) {
requireNonNull(openTelemetrySdk, "openTelemetry must be non null");
this.openTelemetrySdk = openTelemetrySdk;
Original file line number Diff line number Diff line change
@@ -60,7 +60,7 @@ public class HttpStorageOptions extends StorageOptions {
private transient RetryDependenciesAdapter retryDepsAdapter;
private final BlobWriteSessionConfig blobWriteSessionConfig;

private OpenTelemetrySdk openTelemetrySdk;
private final OpenTelemetrySdk openTelemetrySdk;

private HttpStorageOptions(Builder builder, StorageDefaults serviceDefaults) {
super(builder, serviceDefaults);
@@ -139,10 +139,6 @@ RetryingDependencies asRetryDependencies() {
return retryDepsAdapter;
}

public void setOpenTelemetrySdk(OpenTelemetrySdk openTelemetrySdk) {
this.openTelemetrySdk = openTelemetrySdk;
}

public static class Builder extends StorageOptions.Builder {

private StorageRetryStrategy storageRetryStrategy;
@@ -288,7 +284,9 @@ public HttpStorageOptions build() {
* Enable OpenTelemetry Tracing and provide an instance for the client to use.
*
* @param openTelemetrySdk
* @since 2.34.0 This new api is in preview and is subject to breaking changes.
*/
@BetaApi
public HttpStorageOptions.Builder setOpenTelemetrySdk(OpenTelemetrySdk openTelemetrySdk) {
requireNonNull(openTelemetrySdk, "openTelemetry must be non null");
this.openTelemetrySdk = openTelemetrySdk;
Original file line number Diff line number Diff line change
@@ -30,6 +30,7 @@
import com.google.cloud.storage.it.runner.annotations.SingleBackend;
import com.google.cloud.storage.it.runner.registry.Generator;
import com.google.cloud.storage.it.runner.registry.TestBench;
import com.google.cloud.storage.otel.TestExporter;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.sdk.OpenTelemetrySdk;
import io.opentelemetry.sdk.trace.SdkTracerProvider;
Original file line number Diff line number Diff line change
@@ -30,6 +30,7 @@
import com.google.cloud.storage.it.runner.annotations.SingleBackend;
import com.google.cloud.storage.it.runner.registry.Generator;
import com.google.cloud.storage.it.runner.registry.TestBench;
import com.google.cloud.storage.otel.TestExporter;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.sdk.OpenTelemetrySdk;
import io.opentelemetry.sdk.trace.SdkTracerProvider;
Original file line number Diff line number Diff line change
@@ -16,18 +16,14 @@

package com.google.cloud.storage;

import com.google.cloud.storage.otel.TestExporter;
import com.google.cloud.storage.testing.RemoteStorageHelper;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.sdk.OpenTelemetrySdk;
import io.opentelemetry.sdk.common.CompletableResultCode;
import io.opentelemetry.sdk.trace.SdkTracerProvider;
import io.opentelemetry.sdk.trace.data.SpanData;
import io.opentelemetry.sdk.trace.export.SimpleSpanProcessor;
import io.opentelemetry.sdk.trace.export.SpanExporter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
import org.junit.Assert;
import org.junit.Test;
@@ -49,18 +45,21 @@ public void checkInstrumentation() {
StorageOptions.http().setOpenTelemetrySdk(openTelemetrySdk).build();
Storage storage = storageOptions.getService();
String bucket = randomBucketName();
storage.create(BucketInfo.of(bucket));
TestExporter testExported = (TestExporter) exporter;
SpanData spanData = testExported.getExportedSpans().get(0);
Assert.assertEquals("Storage", getAttributeValue(spanData, "gcp.client.service"));
Assert.assertEquals("googleapis/java-storage", getAttributeValue(spanData, "gcp.client.repo"));
Assert.assertEquals(
"com.google.cloud:google-cloud-storage",
getAttributeValue(spanData, "gcp.client.artifact"));
Assert.assertEquals("http", getAttributeValue(spanData, "rpc.system"));

// Cleanup
RemoteStorageHelper.forceDelete(storage, bucket);
try {
storage.create(BucketInfo.of(bucket));
TestExporter testExported = (TestExporter) exporter;
SpanData spanData = testExported.getExportedSpans().get(0);
Assert.assertEquals("Storage", getAttributeValue(spanData, "gcp.client.service"));
Assert.assertEquals(
"googleapis/java-storage", getAttributeValue(spanData, "gcp.client.repo"));
Assert.assertEquals(
"com.google.cloud:google-cloud-storage",
getAttributeValue(spanData, "gcp.client.artifact"));
Assert.assertEquals("http", getAttributeValue(spanData, "rpc.system"));
} finally {
// Cleanup
RemoteStorageHelper.forceDelete(storage, bucket);
}
}

@Test
@@ -79,36 +78,45 @@ public void checkInstrumentationGrpc() {
Storage storage = storageOptions.getService();
String bucket = randomBucketName();
storage.create(BucketInfo.of(bucket));
TestExporter testExported = (TestExporter) exporter;
SpanData spanData = testExported.getExportedSpans().get(0);
Assert.assertEquals("Storage", getAttributeValue(spanData, "gcp.client.service"));
Assert.assertEquals("googleapis/java-storage", getAttributeValue(spanData, "gcp.client.repo"));
Assert.assertEquals(
"com.google.cloud:google-cloud-storage",
getAttributeValue(spanData, "gcp.client.artifact"));
Assert.assertEquals("grpc", getAttributeValue(spanData, "rpc.system"));

// Cleanup
RemoteStorageHelper.forceDelete(storage, bucket);
try {
storage.create(BucketInfo.of(bucket));
TestExporter testExported = (TestExporter) exporter;
SpanData spanData = testExported.getExportedSpans().get(0);
Assert.assertEquals("Storage", getAttributeValue(spanData, "gcp.client.service"));
Assert.assertEquals(
"googleapis/java-storage", getAttributeValue(spanData, "gcp.client.repo"));
Assert.assertEquals(
"com.google.cloud:google-cloud-storage",
getAttributeValue(spanData, "gcp.client.artifact"));
Assert.assertEquals("grpc", getAttributeValue(spanData, "rpc.system"));
} finally {
// Cleanup
RemoteStorageHelper.forceDelete(storage, bucket);
}
}

@Test
public void noOpDoesNothing() {
String httpBucket = randomBucketName();
String grpcBucket = randomBucketName();
// NoOp for HTTP
StorageOptions storageOptionsHttp = StorageOptions.http().build();
Storage storageHttp = storageOptionsHttp.getService();
storageHttp.create(BucketInfo.of(httpBucket));

// NoOp for Grpc
StorageOptions storageOptionsGrpc = StorageOptions.grpc().build();
Storage storageGrpc = storageOptionsGrpc.getService();
storageGrpc.create(BucketInfo.of(grpcBucket));

// cleanup
RemoteStorageHelper.forceDelete(storageHttp, httpBucket);
RemoteStorageHelper.forceDelete(storageGrpc, grpcBucket);
try {
// NoOp for HTTP
storageHttp.create(BucketInfo.of(httpBucket));

// NoOp for Grpc
storageGrpc.create(BucketInfo.of(grpcBucket));

Assert.assertNull(storageOptionsGrpc.getOpenTelemetrySdk());
Assert.assertNull(storageOptionsHttp.getOpenTelemetrySdk());
} finally {
// cleanup
RemoteStorageHelper.forceDelete(storageHttp, httpBucket);
RemoteStorageHelper.forceDelete(storageGrpc, grpcBucket);
}
}

private String getAttributeValue(SpanData spanData, String key) {
@@ -119,28 +127,3 @@ public String randomBucketName() {
return "java-storage-grpc-rand-" + UUID.randomUUID();
}
}

class TestExporter implements SpanExporter {

public final List<SpanData> exportedSpans = Collections.synchronizedList(new ArrayList<>());

@Override
public CompletableResultCode export(Collection<SpanData> spans) {
exportedSpans.addAll(spans);
return CompletableResultCode.ofSuccess();
}

@Override
public CompletableResultCode flush() {
return null;
}

@Override
public CompletableResultCode shutdown() {
return null;
}

public List<SpanData> getExportedSpans() {
return exportedSpans;
}
}
Original file line number Diff line number Diff line change
@@ -201,6 +201,7 @@ public void start() {
tempDirectory = Files.createTempDirectory(containerName);
outPath = tempDirectory.resolve("stdout");
errPath = tempDirectory.resolve("stderr");

File outFile = outPath.toFile();
File errFile = errPath.toFile();
LOGGER.info("Redirecting server stdout to: " + outFile.getAbsolutePath());
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@
import java.util.Collections;
import java.util.List;

class TestExporter implements SpanExporter {
public class TestExporter implements SpanExporter {

public final List<SpanData> exportedSpans = Collections.synchronizedList(new ArrayList<>());

0 comments on commit 92989f5

Please sign in to comment.