Skip to content

Commit 29cbe93

Browse files
committed
chore: add directpath_enabled attribute
1 parent f910f70 commit 29cbe93

File tree

4 files changed

+23
-13
lines changed

4 files changed

+23
-13
lines changed

google-cloud-spanner/src/main/java/com/google/cloud/spanner/BuiltInMetricsConstant.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ public class BuiltInMetricsConstant {
101101
DIRECT_PATH_ENABLED_KEY,
102102
DIRECT_PATH_USED_KEY);
103103

104+
public static boolean DIRECT_PATH_ENABLED;
104105
static Aggregation AGGREGATION_WITH_MILLIS_HISTOGRAM =
105106
Aggregation.explicitBucketHistogram(
106107
ImmutableList.of(

google-cloud-spanner/src/main/java/com/google/cloud/spanner/CompositeTracer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public void addAttributes(Map<String, String> attributes) {
184184
for (ApiTracer child : children) {
185185
if (child instanceof MetricsTracer) {
186186
MetricsTracer metricsTracer = (MetricsTracer) child;
187-
attributes.forEach((key, value) -> metricsTracer.addAttributes(key, value));
187+
metricsTracer.addAttributes(attributes);
188188
}
189189
}
190190
}

google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/GapicSpannerRpc.java

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import com.google.api.gax.grpc.GrpcCallContext;
3030
import com.google.api.gax.grpc.GrpcCallSettings;
3131
import com.google.api.gax.grpc.GrpcStubCallableFactory;
32+
import com.google.api.gax.grpc.GrpcTransportChannel;
3233
import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider;
3334
import com.google.api.gax.longrunning.OperationFuture;
3435
import com.google.api.gax.retrying.ResultRetryAlgorithm;
@@ -63,6 +64,7 @@
6364
import com.google.cloud.grpc.GrpcTransportOptions;
6465
import com.google.cloud.spanner.AdminRequestsPerMinuteExceededException;
6566
import com.google.cloud.spanner.BackupId;
67+
import com.google.cloud.spanner.BuiltInMetricsConstant;
6668
import com.google.cloud.spanner.ErrorCode;
6769
import com.google.cloud.spanner.Restore;
6870
import com.google.cloud.spanner.SpannerException;
@@ -396,18 +398,22 @@ public GapicSpannerRpc(final SpannerOptions options) {
396398
final String emulatorHost = System.getenv("SPANNER_EMULATOR_HOST");
397399

398400
try {
399-
this.spannerStub =
400-
GrpcSpannerStub.create(
401-
options
402-
.getSpannerStubSettings()
403-
.toBuilder()
404-
.setTransportChannelProvider(channelProvider)
405-
.setCredentialsProvider(credentialsProvider)
406-
.setStreamWatchdogProvider(watchdogProvider)
407-
.setTracerFactory(
408-
options.getApiTracerFactory(
409-
/* isAdminClient = */ false, isEmulatorEnabled(options, emulatorHost)))
410-
.build());
401+
SpannerStubSettings spannerStubSettings =
402+
options
403+
.getSpannerStubSettings()
404+
.toBuilder()
405+
.setTransportChannelProvider(channelProvider)
406+
.setCredentialsProvider(credentialsProvider)
407+
.setStreamWatchdogProvider(watchdogProvider)
408+
.setTracerFactory(
409+
options.getApiTracerFactory(
410+
/* isAdminClient = */ false, isEmulatorEnabled(options, emulatorHost)))
411+
.build();
412+
ClientContext clientContext = ClientContext.create(spannerStubSettings);
413+
this.spannerStub = GrpcSpannerStub.create((clientContext));
414+
BuiltInMetricsConstant.DIRECT_PATH_ENABLED =
415+
((GrpcTransportChannel) clientContext.getTransportChannel()).isDirectPath()
416+
&& isAttemptDirectPathXds;
411417
this.readRetrySettings =
412418
options.getSpannerStubSettings().streamingReadSettings().getRetrySettings();
413419
this.readRetryableCodes =

google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/HeaderInterceptor.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,9 @@ private Map<String, String> getBuiltInMetricAttributes(String key, DatabaseName
228228
attributes.put(BuiltInMetricsConstant.DATABASE_KEY.getKey(), databaseName.getDatabase());
229229
attributes.put(
230230
BuiltInMetricsConstant.INSTANCE_ID_KEY.getKey(), databaseName.getInstance());
231+
attributes.put(
232+
BuiltInMetricsConstant.DIRECT_PATH_ENABLED_KEY.getKey(),
233+
String.valueOf(BuiltInMetricsConstant.DIRECT_PATH_ENABLED));
231234
return attributes;
232235
});
233236
}

0 commit comments

Comments
 (0)