Skip to content

Commit 0c03b8e

Browse files
committed
feat:enable AFE and gRPC metrics for DP
1 parent 32b2373 commit 0c03b8e

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -1994,7 +1994,8 @@ public ApiTracerFactory getApiTracerFactory() {
19941994
}
19951995

19961996
public void enablegRPCMetrics(InstantiatingGrpcChannelProvider.Builder channelProviderBuilder) {
1997-
if (SpannerOptions.environment.isEnableGRPCBuiltInMetrics()) {
1997+
if (GapicSpannerRpc.isEnableDirectPathXdsEnv()
1998+
|| SpannerOptions.environment.isEnableGRPCBuiltInMetrics()) {
19981999
this.builtInMetricsProvider.enableGrpcMetrics(
19992000
channelProviderBuilder, this.getProjectId(), getCredentials(), this.monitoringHost);
20002001
}

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

+7-3
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,7 @@ public GapicSpannerRpc(final SpannerOptions options) {
367367
.withEncoding(compressorName))
368368
.setHeaderProvider(headerProviderWithUserAgent)
369369
.setAllowNonDefaultServiceAccount(true);
370-
String directPathXdsEnv = System.getenv("GOOGLE_SPANNER_ENABLE_DIRECT_ACCESS");
371-
boolean isAttemptDirectPathXds = Boolean.parseBoolean(directPathXdsEnv);
370+
boolean isAttemptDirectPathXds = isEnableDirectPathXdsEnv();
372371
if (isAttemptDirectPathXds) {
373372
defaultChannelProviderBuilder.setAttemptDirectPath(true);
374373
defaultChannelProviderBuilder.setAttemptDirectPathXds();
@@ -678,7 +677,12 @@ private static boolean isEmulatorEnabled(SpannerOptions options, String emulator
678677
}
679678

680679
public static boolean isEnableAFEServerTiming() {
681-
return "false".equalsIgnoreCase(System.getenv("SPANNER_DISABLE_AFE_SERVER_TIMING"));
680+
return isEnableDirectPathXdsEnv()
681+
|| "false".equalsIgnoreCase(System.getenv("SPANNER_DISABLE_AFE_SERVER_TIMING"));
682+
}
683+
684+
public static boolean isEnableDirectPathXdsEnv() {
685+
return Boolean.parseBoolean(System.getenv("GOOGLE_SPANNER_ENABLE_DIRECT_ACCESS"));
682686
}
683687

684688
private static final RetrySettings ADMIN_REQUESTS_LIMIT_EXCEEDED_RETRY_SETTINGS =

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

+6-4
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ public void onHeaders(Metadata metadata) {
133133
Boolean isDirectPathUsed =
134134
isDirectPathUsed(getAttributes().get(Grpc.TRANSPORT_ATTR_REMOTE_ADDR));
135135
addDirectPathUsedAttribute(compositeTracer, isDirectPathUsed);
136-
processHeader(metadata, tagContext, attributes, span, compositeTracer);
136+
processHeader(
137+
metadata, tagContext, attributes, span, compositeTracer, isDirectPathUsed);
137138
super.onHeaders(metadata);
138139
}
139140
},
@@ -151,7 +152,8 @@ private void processHeader(
151152
TagContext tagContext,
152153
Attributes attributes,
153154
Span span,
154-
CompositeTracer compositeTracer) {
155+
CompositeTracer compositeTracer,
156+
boolean isDirectPathUsed) {
155157
MeasureMap measureMap = STATS_RECORDER.newMeasureMap();
156158
String serverTiming = metadata.get(SERVER_TIMING_HEADER_KEY);
157159
try {
@@ -172,7 +174,7 @@ private void processHeader(
172174

173175
spannerRpcMetrics.recordGfeLatency(gfeLatency, attributes);
174176
spannerRpcMetrics.recordGfeHeaderMissingCount(0L, attributes);
175-
if (compositeTracer != null) {
177+
if (compositeTracer != null && !isDirectPathUsed) {
176178
compositeTracer.recordGFELatency(gfeLatency);
177179
}
178180
if (span != null) {
@@ -181,7 +183,7 @@ private void processHeader(
181183
} else {
182184
measureMap.put(SPANNER_GFE_HEADER_MISSING_COUNT, 1L).record(tagContext);
183185
spannerRpcMetrics.recordGfeHeaderMissingCount(1L, attributes);
184-
if (compositeTracer != null) {
186+
if (compositeTracer != null && !isDirectPathUsed) {
185187
compositeTracer.recordGfeHeaderMissingCount(1L);
186188
}
187189
}

0 commit comments

Comments
 (0)