Skip to content

Commit

Permalink
fix: re-instante public constructor for ProxyServer (#1216)
Browse files Browse the repository at this point in the history
The signature of the public constructor for ProxyServer was accidentally
changed in version 0.27.0. This re-instantes the constructor with the
same signature.
  • Loading branch information
olavloite authored Nov 23, 2023
1 parent 1a7a7f5 commit a8ce633
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,13 @@ public class ProxyServer extends AbstractApiService {
private final ConcurrentLinkedQueue<WireMessage> debugMessages = new ConcurrentLinkedQueue<>();
private final AtomicInteger debugMessageCount = new AtomicInteger();

ProxyServer(OptionsMetadata optionsMetadata) {
this(optionsMetadata, OpenTelemetry.noop());
/**
* Instantiates the ProxyServer from CLI-gathered metadata.
*
* @param optionsMetadata Resulting metadata from CLI.
*/
public ProxyServer(OptionsMetadata optionsMetadata) {
this(optionsMetadata, Server.setupOpenTelemetry(optionsMetadata));
}

/**
Expand Down
69 changes: 37 additions & 32 deletions src/main/java/com/google/cloud/spanner/pgadapter/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public static void main(String[] args) {
}
}

static OpenTelemetry setupOpenTelemetry(OptionsMetadata optionsMetadata) throws IOException {
/** Creates an {@link OpenTelemetry} object from the given options. */
static OpenTelemetry setupOpenTelemetry(OptionsMetadata optionsMetadata) {
if (!optionsMetadata.isEnableOpenTelemetry()) {
return OpenTelemetry.noop();
}
Expand All @@ -77,38 +78,42 @@ static OpenTelemetry setupOpenTelemetry(OptionsMetadata optionsMetadata) throws
if (projectId != null) {
builder.setProjectId(projectId);
}
Credentials credentials = optionsMetadata.getTelemetryCredentials();
if (credentials != null) {
builder.setCredentials(credentials);
}
builder.setFixedAttributes(
ImmutableMap.of(
"service.name",
AttributeValue.newBuilder()
.setStringValue(
TruncatableString.newBuilder()
.setValue(
Objects.requireNonNull(getOpenTelemetrySetting("otel.service.name")))
.build())
.build()));
TraceConfiguration configuration = builder.build();
TraceExporter traceExporter = TraceExporter.createWithConfiguration(configuration);
Sampler sampler;
if (optionsMetadata.getOpenTelemetryTraceRatio() == null) {
sampler = Sampler.parentBased(Sampler.traceIdRatioBased(0.05d));
} else {
sampler =
Sampler.parentBased(
Sampler.traceIdRatioBased(optionsMetadata.getOpenTelemetryTraceRatio()));
try {
Credentials credentials = optionsMetadata.getTelemetryCredentials();
if (credentials != null) {
builder.setCredentials(credentials);
}
builder.setFixedAttributes(
ImmutableMap.of(
"service.name",
AttributeValue.newBuilder()
.setStringValue(
TruncatableString.newBuilder()
.setValue(
Objects.requireNonNull(getOpenTelemetrySetting("otel.service.name")))
.build())
.build()));
TraceConfiguration configuration = builder.build();
TraceExporter traceExporter = TraceExporter.createWithConfiguration(configuration);
Sampler sampler;
if (optionsMetadata.getOpenTelemetryTraceRatio() == null) {
sampler = Sampler.parentBased(Sampler.traceIdRatioBased(0.05d));
} else {
sampler =
Sampler.parentBased(
Sampler.traceIdRatioBased(optionsMetadata.getOpenTelemetryTraceRatio()));
}
return AutoConfiguredOpenTelemetrySdk.builder()
.addTracerProviderCustomizer(
(sdkTracerProviderBuilder, configProperties) ->
sdkTracerProviderBuilder
.setSampler(sampler)
.addSpanProcessor(BatchSpanProcessor.builder(traceExporter).build()))
.build()
.getOpenTelemetrySdk();
} catch (IOException exception) {
throw new RuntimeException(exception);
}
return AutoConfiguredOpenTelemetrySdk.builder()
.addTracerProviderCustomizer(
(sdkTracerProviderBuilder, configProperties) ->
sdkTracerProviderBuilder
.setSampler(sampler)
.addSpanProcessor(BatchSpanProcessor.builder(traceExporter).build()))
.build()
.getOpenTelemetrySdk();
}

static String getOpenTelemetrySetting(String systemProperty) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
import io.grpc.StatusRuntimeException;
import io.grpc.netty.shaded.io.grpc.netty.NettyServerBuilder;
import io.grpc.stub.StreamObserver;
import io.opentelemetry.api.OpenTelemetry;
import java.net.InetSocketAddress;
import java.nio.charset.StandardCharsets;
import java.sql.SQLException;
Expand Down Expand Up @@ -1036,7 +1037,7 @@ public <ReqT, RespT> Listener<ReqT> interceptCall(
.setEndpoint(String.format("localhost:%d", spannerServer.getPort()))
.setCredentials(NoCredentials.getInstance());
optionsConfigurator.accept(builder);
pgServer = new ProxyServer(builder.build());
pgServer = new ProxyServer(builder.build(), OpenTelemetry.noop());
pgServer.startServer();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import com.google.common.primitives.Bytes;
import com.google.spanner.admin.database.v1.CreateDatabaseMetadata;
import com.google.spanner.admin.database.v1.UpdateDatabaseDdlMetadata;
import io.opentelemetry.api.OpenTelemetry;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FileInputStream;
Expand Down Expand Up @@ -209,7 +210,7 @@ private void startPGAdapterServer(
}
argsListBuilder.addAll(additionalPGAdapterOptions);
String[] args = argsListBuilder.build().toArray(new String[0]);
server = new ProxyServer(new OptionsMetadata(args));
server = new ProxyServer(new OptionsMetadata(args), OpenTelemetry.noop());
server.startServer();
}
}
Expand Down

0 comments on commit a8ce633

Please sign in to comment.