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

feat: Enabling endToEndTracing support in Connection API #3412

Merged
merged 7 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -26,6 +26,7 @@
import static com.google.cloud.spanner.connection.ConnectionProperties.DATA_BOOST_ENABLED;
import static com.google.cloud.spanner.connection.ConnectionProperties.DIALECT;
import static com.google.cloud.spanner.connection.ConnectionProperties.ENABLE_API_TRACING;
import static com.google.cloud.spanner.connection.ConnectionProperties.ENABLE_END_TO_END_TRACING;
import static com.google.cloud.spanner.connection.ConnectionProperties.ENABLE_EXTENDED_TRACING;
import static com.google.cloud.spanner.connection.ConnectionProperties.ENCODED_CREDENTIALS;
import static com.google.cloud.spanner.connection.ConnectionProperties.ENDPOINT;
Expand Down Expand Up @@ -239,6 +240,7 @@ public String[] getValidValues() {
static final boolean DEFAULT_RETURN_COMMIT_STATS = false;
static final boolean DEFAULT_LENIENT = false;
static final boolean DEFAULT_ROUTE_TO_LEADER = true;
static final boolean DEFAULT_ENABLE_END_TO_END_TRACING = false;
ankiaga marked this conversation as resolved.
Show resolved Hide resolved
static final boolean DEFAULT_DELAY_TRANSACTION_START_UNTIL_FIRST_WRITE = false;
static final boolean DEFAULT_KEEP_TRANSACTION_ALIVE = false;
static final boolean DEFAULT_TRACK_SESSION_LEAKS = true;
Expand Down Expand Up @@ -267,6 +269,8 @@ public String[] getValidValues() {
/** Name of the 'routeToLeader' connection property. */
public static final String ROUTE_TO_LEADER_PROPERTY_NAME = "routeToLeader";
/** Name of the 'retry aborts internally' connection property. */
public static final String ENABLE_END_TO_END_TRACING_PROPERTY_NAME = "enableEndToEndTracing";
ankiaga marked this conversation as resolved.
Show resolved Hide resolved

public static final String RETRY_ABORTS_INTERNALLY_PROPERTY_NAME = "retryAbortsInternally";
/** Name of the property to enable/disable virtual threads for the statement executor. */
public static final String USE_VIRTUAL_THREADS_PROPERTY_NAME = "useVirtualThreads";
Expand Down Expand Up @@ -382,6 +386,10 @@ static boolean isEnableTransactionalConnectionStateForPostgreSQL() {
ROUTE_TO_LEADER_PROPERTY_NAME,
"Should read/write transactions and partitioned DML be routed to leader region (true/false)",
DEFAULT_ROUTE_TO_LEADER),
ConnectionProperty.createBooleanProperty(
ankiaga marked this conversation as resolved.
Show resolved Hide resolved
ENABLE_END_TO_END_TRACING_PROPERTY_NAME,
"Should we enable end to end tracing (true/false)",
ankiaga marked this conversation as resolved.
Show resolved Hide resolved
DEFAULT_ENABLE_END_TO_END_TRACING),
ConnectionProperty.createBooleanProperty(
RETRY_ABORTS_INTERNALLY_PROPERTY_NAME,
"Should the connection automatically retry Aborted errors (true/false)",
Expand Down Expand Up @@ -1205,6 +1213,11 @@ public boolean isRouteToLeader() {
return getInitialConnectionPropertyValue(ROUTE_TO_LEADER);
}

/** Whether end-to-end tracing is enabled. */
public boolean enableEndToEndTracing() {
ankiaga marked this conversation as resolved.
Show resolved Hide resolved
return getInitialConnectionPropertyValue(ENABLE_END_TO_END_TRACING);
}

/**
* The initial retryAbortsInternally value for connections created by this {@link
* ConnectionOptions}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import static com.google.cloud.spanner.connection.ConnectionOptions.DEFAULT_DDL_IN_TRANSACTION_MODE;
import static com.google.cloud.spanner.connection.ConnectionOptions.DEFAULT_DELAY_TRANSACTION_START_UNTIL_FIRST_WRITE;
import static com.google.cloud.spanner.connection.ConnectionOptions.DEFAULT_ENABLE_API_TRACING;
import static com.google.cloud.spanner.connection.ConnectionOptions.DEFAULT_ENABLE_END_TO_END_TRACING;
import static com.google.cloud.spanner.connection.ConnectionOptions.DEFAULT_ENABLE_EXTENDED_TRACING;
import static com.google.cloud.spanner.connection.ConnectionOptions.DEFAULT_ENDPOINT;
import static com.google.cloud.spanner.connection.ConnectionOptions.DEFAULT_KEEP_TRANSACTION_ALIVE;
Expand All @@ -65,6 +66,7 @@
import static com.google.cloud.spanner.connection.ConnectionOptions.DELAY_TRANSACTION_START_UNTIL_FIRST_WRITE_NAME;
import static com.google.cloud.spanner.connection.ConnectionOptions.DIALECT_PROPERTY_NAME;
import static com.google.cloud.spanner.connection.ConnectionOptions.ENABLE_API_TRACING_PROPERTY_NAME;
import static com.google.cloud.spanner.connection.ConnectionOptions.ENABLE_END_TO_END_TRACING_PROPERTY_NAME;
import static com.google.cloud.spanner.connection.ConnectionOptions.ENABLE_EXTENDED_TRACING_PROPERTY_NAME;
import static com.google.cloud.spanner.connection.ConnectionOptions.ENCODED_CREDENTIALS_PROPERTY_NAME;
import static com.google.cloud.spanner.connection.ConnectionOptions.ENDPOINT_PROPERTY_NAME;
Expand Down Expand Up @@ -257,6 +259,13 @@ class ConnectionProperties {
DEFAULT_ROUTE_TO_LEADER,
BooleanConverter.INSTANCE,
Context.STARTUP);
static final ConnectionProperty<Boolean> ENABLE_END_TO_END_TRACING =
ankiaga marked this conversation as resolved.
Show resolved Hide resolved
create(
ENABLE_END_TO_END_TRACING_PROPERTY_NAME,
"Should we enable end to end tracing (true/false)",
DEFAULT_ENABLE_END_TO_END_TRACING,
BooleanConverter.INSTANCE,
Context.STARTUP);
static final ConnectionProperty<Boolean> USE_VIRTUAL_THREADS =
create(
USE_VIRTUAL_THREADS_PROPERTY_NAME,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ static class SpannerPoolKey {
private final String userAgent;
private final String databaseRole;
private final boolean routeToLeader;
private final boolean enableEndToEndTracing;
ankiaga marked this conversation as resolved.
Show resolved Hide resolved
private final boolean useVirtualGrpcTransportThreads;
private final OpenTelemetry openTelemetry;
private final Boolean enableExtendedTracing;
Expand Down Expand Up @@ -186,6 +187,7 @@ private SpannerPoolKey(ConnectionOptions options) throws IOException {
this.usePlainText = options.isUsePlainText();
this.userAgent = options.getUserAgent();
this.routeToLeader = options.isRouteToLeader();
this.enableEndToEndTracing = options.enableEndToEndTracing();
ankiaga marked this conversation as resolved.
Show resolved Hide resolved
this.useVirtualGrpcTransportThreads = options.isUseVirtualGrpcTransportThreads();
this.openTelemetry = options.getOpenTelemetry();
this.enableExtendedTracing = options.isEnableExtendedTracing();
Expand All @@ -207,6 +209,7 @@ public boolean equals(Object o) {
&& Objects.equals(this.usePlainText, other.usePlainText)
&& Objects.equals(this.userAgent, other.userAgent)
&& Objects.equals(this.routeToLeader, other.routeToLeader)
&& Objects.equals(this.enableEndToEndTracing, other.enableEndToEndTracing)
&& Objects.equals(
this.useVirtualGrpcTransportThreads, other.useVirtualGrpcTransportThreads)
&& Objects.equals(this.openTelemetry, other.openTelemetry)
Expand All @@ -226,6 +229,7 @@ public int hashCode() {
this.databaseRole,
this.userAgent,
this.routeToLeader,
this.enableEndToEndTracing,
this.useVirtualGrpcTransportThreads,
this.openTelemetry,
this.enableExtendedTracing,
Expand Down Expand Up @@ -380,6 +384,9 @@ Spanner createSpanner(SpannerPoolKey key, ConnectionOptions options) {
if (!options.isRouteToLeader()) {
builder.disableLeaderAwareRouting();
}
if (options.enableEndToEndTracing()) {
builder.setEnableEndToEndTracing(true);
}
if (key.usePlainText) {
// Credentials may not be sent over a plain text channel.
builder.setCredentials(NoCredentials.getInstance());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,27 @@ public void testBuildWithRouteToLeader() {
assertTrue(options.isRouteToLeader());
}

@Test
public void testBuildWithEndToEndTracingEnabled() {
final String BASE_URI =
"cloudspanner:/projects/test-project-123/instances/test-instance-123/databases/test-database-123";
ConnectionOptions.Builder builder = ConnectionOptions.newBuilder();
builder.setUri(BASE_URI + "?enableEndToEndTracing=true");
builder.setCredentialsUrl(FILE_TEST_PATH);
ConnectionOptions options = builder.build();
assertEquals(options.getHost(), DEFAULT_HOST);
assertEquals(options.getProjectId(), TEST_PROJECT);
assertEquals(options.getInstanceId(), TEST_INSTANCE);
assertEquals(options.getDatabaseName(), TEST_DATABASE);
assertTrue(options.enableEndToEndTracing());

// Test for default behavior for enableEndToEndTracing property.
builder = ConnectionOptions.newBuilder().setUri(BASE_URI);
builder.setCredentialsUrl(FILE_TEST_PATH);
options = builder.build();
assertFalse(options.enableEndToEndTracing());
}

@Test
public void testBuildWithAutoConfigEmulatorAndHost() {
ConnectionOptions.Builder builder = ConnectionOptions.newBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,58 @@ public void testEnableApiTracing() {
.build()));
}

@Test
public void testEnableEndToEndTracing() {
SpannerPoolKey keyWithoutApiTracingConfig =
SpannerPoolKey.of(
ConnectionOptions.newBuilder()
.setUri("cloudspanner:/projects/p/instances/i/databases/d")
.setCredentials(NoCredentials.getInstance())
.build());
SpannerPoolKey keyWithApiTracingEnabled =
SpannerPoolKey.of(
ConnectionOptions.newBuilder()
.setUri(
"cloudspanner:/projects/p/instances/i/databases/d?enableEndToEndTracing=true")
.setCredentials(NoCredentials.getInstance())
.build());
SpannerPoolKey keyWithApiTracingDisabled =
SpannerPoolKey.of(
ConnectionOptions.newBuilder()
.setUri(
"cloudspanner:/projects/p/instances/i/databases/d?enableEndToEndTracing=false")
.setCredentials(NoCredentials.getInstance())
.build());

assertNotEquals(keyWithoutApiTracingConfig, keyWithApiTracingEnabled);
assertEquals(keyWithoutApiTracingConfig, keyWithApiTracingDisabled);
assertNotEquals(keyWithApiTracingEnabled, keyWithApiTracingDisabled);

assertEquals(
keyWithApiTracingEnabled,
SpannerPoolKey.of(
ConnectionOptions.newBuilder()
.setUri(
"cloudspanner:/projects/p/instances/i/databases/d?enableEndToEndTracing=true")
.setCredentials(NoCredentials.getInstance())
.build()));
assertEquals(
keyWithApiTracingDisabled,
SpannerPoolKey.of(
ConnectionOptions.newBuilder()
.setUri(
"cloudspanner:/projects/p/instances/i/databases/d?enableEndToEndTracing=false")
.setCredentials(NoCredentials.getInstance())
.build()));
assertEquals(
keyWithoutApiTracingConfig,
SpannerPoolKey.of(
ConnectionOptions.newBuilder()
.setUri("cloudspanner:/projects/p/instances/i/databases/d")
.setCredentials(NoCredentials.getInstance())
.build()));
}

@Test
public void testOpenTelemetry() {
SpannerPool pool = createSubjectAndMocks();
Expand Down
Loading