feat: enable AFE and gRPC metrics for DP · googleapis/java-spanner@e4957f7 · GitHub | Latest TMZ Celebrity News & Gossip | Watch TMZ Live
Skip to content

Commit e4957f7

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

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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 7 additions & 3 deletions
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

Lines changed: 6 additions & 4 deletions
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)

TMZ Celebrity News – Breaking Stories, Videos & Gossip

Looking for the latest TMZ celebrity news? You've come to the right place. From shocking Hollywood scandals to exclusive videos, TMZ delivers it all in real time.

Whether it’s a red carpet slip-up, a viral paparazzi moment, or a legal drama involving your favorite stars, TMZ news is always first to break the story. Stay in the loop with daily updates, insider tips, and jaw-dropping photos.

🎥 Watch TMZ Live

TMZ Live brings you daily celebrity news and interviews straight from the TMZ newsroom. Don’t miss a beat—watch now and see what’s trending in Hollywood.