Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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 @@ -1994,7 +1994,8 @@ public ApiTracerFactory getApiTracerFactory() {
}

public void enablegRPCMetrics(InstantiatingGrpcChannelProvider.Builder channelProviderBuilder) {
if (SpannerOptions.environment.isEnableGRPCBuiltInMetrics()) {
if (GapicSpannerRpc.isEnableDirectPathXdsEnv()
|| SpannerOptions.environment.isEnableGRPCBuiltInMetrics()) {
this.builtInMetricsProvider.enableGrpcMetrics(
channelProviderBuilder, this.getProjectId(), getCredentials(), this.monitoringHost);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,7 @@ public GapicSpannerRpc(final SpannerOptions options) {
.withEncoding(compressorName))
.setHeaderProvider(headerProviderWithUserAgent)
.setAllowNonDefaultServiceAccount(true);
String directPathXdsEnv = System.getenv("GOOGLE_SPANNER_ENABLE_DIRECT_ACCESS");
boolean isAttemptDirectPathXds = Boolean.parseBoolean(directPathXdsEnv);
boolean isAttemptDirectPathXds = isEnableDirectPathXdsEnv();
if (isAttemptDirectPathXds) {
defaultChannelProviderBuilder.setAttemptDirectPath(true);
defaultChannelProviderBuilder.setAttemptDirectPathXds();
Expand Down Expand Up @@ -678,7 +677,12 @@ private static boolean isEmulatorEnabled(SpannerOptions options, String emulator
}

public static boolean isEnableAFEServerTiming() {
return "false".equalsIgnoreCase(System.getenv("SPANNER_DISABLE_AFE_SERVER_TIMING"));
return isEnableDirectPathXdsEnv()
|| "false".equalsIgnoreCase(System.getenv("SPANNER_DISABLE_AFE_SERVER_TIMING"));
}

public static boolean isEnableDirectPathXdsEnv() {
return Boolean.parseBoolean(System.getenv("GOOGLE_SPANNER_ENABLE_DIRECT_ACCESS"));
}

private static final RetrySettings ADMIN_REQUESTS_LIMIT_EXCEEDED_RETRY_SETTINGS =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ public void onHeaders(Metadata metadata) {
Boolean isDirectPathUsed =
isDirectPathUsed(getAttributes().get(Grpc.TRANSPORT_ATTR_REMOTE_ADDR));
addDirectPathUsedAttribute(compositeTracer, isDirectPathUsed);
processHeader(metadata, tagContext, attributes, span, compositeTracer);
processHeader(
metadata, tagContext, attributes, span, compositeTracer, isDirectPathUsed);
super.onHeaders(metadata);
}
},
Expand All @@ -151,7 +152,8 @@ private void processHeader(
TagContext tagContext,
Attributes attributes,
Span span,
CompositeTracer compositeTracer) {
CompositeTracer compositeTracer,
boolean isDirectPathUsed) {
MeasureMap measureMap = STATS_RECORDER.newMeasureMap();
String serverTiming = metadata.get(SERVER_TIMING_HEADER_KEY);
try {
Expand All @@ -172,7 +174,7 @@ private void processHeader(

spannerRpcMetrics.recordGfeLatency((long) gfeLatency, attributes);
spannerRpcMetrics.recordGfeHeaderMissingCount(0L, attributes);
if (compositeTracer != null) {
if (compositeTracer != null && !isDirectPathUsed) {
compositeTracer.recordGFELatency(gfeLatency);
}
if (span != null) {
Expand All @@ -181,7 +183,7 @@ private void processHeader(
} else {
measureMap.put(SPANNER_GFE_HEADER_MISSING_COUNT, 1L).record(tagContext);
spannerRpcMetrics.recordGfeHeaderMissingCount(1L, attributes);
if (compositeTracer != null) {
if (compositeTracer != null && !isDirectPathUsed) {
compositeTracer.recordGfeHeaderMissingCount(1L);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.google.cloud.spanner.MockSpannerServiceImpl.SimulatedExecutionTime;
import com.google.cloud.spanner.MockSpannerServiceImpl.StatementResult;
import com.google.cloud.spanner.connection.RandomResultSetGenerator;
import com.google.cloud.spanner.spi.v1.GapicSpannerRpc;
import com.google.common.base.Stopwatch;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Range;
Expand Down Expand Up @@ -190,16 +191,23 @@ public void testMetricsSingleUseQuery() {
assertNotNull(attemptCountMetricData);
assertThat(getAggregatedValue(attemptCountMetricData, expectedAttributes)).isEqualTo(1);

MetricData gfeLatencyMetricData =
getMetricData(metricReader, BuiltInMetricsConstant.GFE_LATENCIES_NAME);
double gfeLatencyValue = getAggregatedValue(gfeLatencyMetricData, expectedAttributes);
assertEquals(fakeServerTiming.get(), gfeLatencyValue, 0);

assertFalse(
checkIfMetricExists(metricReader, BuiltInMetricsConstant.GFE_CONNECTIVITY_ERROR_NAME));
assertFalse(checkIfMetricExists(metricReader, BuiltInMetricsConstant.AFE_LATENCIES_NAME));
assertFalse(
checkIfMetricExists(metricReader, BuiltInMetricsConstant.AFE_CONNECTIVITY_ERROR_NAME));
if (GapicSpannerRpc.isEnableDirectPathXdsEnv()) {
// AFE metrics are enabled for DirectPath.
MetricData afeLatencyMetricData =
getMetricData(metricReader, BuiltInMetricsConstant.AFE_LATENCIES_NAME);
double afeLatencyValue = getAggregatedValue(afeLatencyMetricData, expectedAttributes);
assertEquals(fakeAFEServerTiming.get(), afeLatencyValue, 0);
} else {
MetricData gfeLatencyMetricData =
getMetricData(metricReader, BuiltInMetricsConstant.GFE_LATENCIES_NAME);
double gfeLatencyValue = getAggregatedValue(gfeLatencyMetricData, expectedAttributes);
assertEquals(fakeServerTiming.get(), gfeLatencyValue, 0);
assertFalse(checkIfMetricExists(metricReader, BuiltInMetricsConstant.AFE_LATENCIES_NAME));
}
}

private boolean isJava8() {
Expand Down Expand Up @@ -261,20 +269,19 @@ public void testMetricsSingleUseQueryWithAfeEnabled() throws Exception {
assertNotNull(attemptCountMetricData);
assertThat(getAggregatedValue(attemptCountMetricData, expectedAttributes)).isEqualTo(1);

MetricData gfeLatencyMetricData =
getMetricData(metricReader, BuiltInMetricsConstant.GFE_LATENCIES_NAME);
double gfeLatencyValue = getAggregatedValue(gfeLatencyMetricData, expectedAttributes);
assertEquals(fakeServerTiming.get(), gfeLatencyValue, 0);

assertFalse(
checkIfMetricExists(metricReader, BuiltInMetricsConstant.GFE_CONNECTIVITY_ERROR_NAME));

assertFalse(
checkIfMetricExists(metricReader, BuiltInMetricsConstant.AFE_CONNECTIVITY_ERROR_NAME));
MetricData afeLatencyMetricData =
getMetricData(metricReader, BuiltInMetricsConstant.AFE_LATENCIES_NAME);
double afeLatencyValue = getAggregatedValue(afeLatencyMetricData, expectedAttributes);
assertEquals(fakeAFEServerTiming.get(), afeLatencyValue, 0);
assertFalse(
checkIfMetricExists(metricReader, BuiltInMetricsConstant.AFE_CONNECTIVITY_ERROR_NAME));

MetricData gfeLatencyMetricData =
getMetricData(metricReader, BuiltInMetricsConstant.GFE_LATENCIES_NAME);
double gfeLatencyValue = getAggregatedValue(gfeLatencyMetricData, expectedAttributes);
assertEquals(fakeServerTiming.get(), gfeLatencyValue, 0);
} finally {
writeableEnvironmentVariables.remove("GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS");
}
Expand Down Expand Up @@ -445,13 +452,20 @@ public void testNoServerTimingHeader() throws IOException, InterruptedException
.put(BuiltInMetricsConstant.METHOD_KEY, "Spanner.ExecuteSql")
.build();

MetricData gfeConnectivityMetricData =
getMetricData(metricReader, BuiltInMetricsConstant.GFE_CONNECTIVITY_ERROR_NAME);
assertThat(getAggregatedValue(gfeConnectivityMetricData, expectedAttributes)).isEqualTo(1);
assertFalse(checkIfMetricExists(metricReader, BuiltInMetricsConstant.AFE_LATENCIES_NAME));
assertFalse(checkIfMetricExists(metricReader, BuiltInMetricsConstant.GFE_LATENCIES_NAME));
assertFalse(
checkIfMetricExists(metricReader, BuiltInMetricsConstant.AFE_CONNECTIVITY_ERROR_NAME));
if (GapicSpannerRpc.isEnableDirectPathXdsEnv()) {
MetricData afeConnectivityMetricData =
getMetricData(metricReader, BuiltInMetricsConstant.AFE_CONNECTIVITY_ERROR_NAME);
assertThat(getAggregatedValue(afeConnectivityMetricData, expectedAttributes)).isEqualTo(1);
} else {
MetricData gfeConnectivityMetricData =
getMetricData(metricReader, BuiltInMetricsConstant.GFE_CONNECTIVITY_ERROR_NAME);
assertThat(getAggregatedValue(gfeConnectivityMetricData, expectedAttributes)).isEqualTo(1);
assertFalse(
checkIfMetricExists(metricReader, BuiltInMetricsConstant.AFE_CONNECTIVITY_ERROR_NAME));
}

spannerNoHeader.close();
serverNoHeader.shutdown();
serverNoHeader.awaitTermination();
Expand Down
Loading