Skip to content

Commit 4a324b1

Browse files
committed
check afe metrics when DP is enabled
1 parent 29a4f7c commit 4a324b1

File tree

1 file changed

+34
-20
lines changed

1 file changed

+34
-20
lines changed

google-cloud-spanner/src/test/java/com/google/cloud/spanner/OpenTelemetryBuiltInMetricsTracerTest.java

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import com.google.cloud.spanner.MockSpannerServiceImpl.SimulatedExecutionTime;
3535
import com.google.cloud.spanner.MockSpannerServiceImpl.StatementResult;
3636
import com.google.cloud.spanner.connection.RandomResultSetGenerator;
37+
import com.google.cloud.spanner.spi.v1.GapicSpannerRpc;
3738
import com.google.common.base.Stopwatch;
3839
import com.google.common.collect.ImmutableList;
3940
import com.google.common.collect.Range;
@@ -190,16 +191,23 @@ public void testMetricsSingleUseQuery() {
190191
assertNotNull(attemptCountMetricData);
191192
assertThat(getAggregatedValue(attemptCountMetricData, expectedAttributes)).isEqualTo(1);
192193

193-
MetricData gfeLatencyMetricData =
194-
getMetricData(metricReader, BuiltInMetricsConstant.GFE_LATENCIES_NAME);
195-
double gfeLatencyValue = getAggregatedValue(gfeLatencyMetricData, expectedAttributes);
196-
assertEquals(fakeServerTiming.get(), gfeLatencyValue, 0);
197-
198-
assertFalse(
194+
assertFalse(
199195
checkIfMetricExists(metricReader, BuiltInMetricsConstant.GFE_CONNECTIVITY_ERROR_NAME));
200-
assertFalse(checkIfMetricExists(metricReader, BuiltInMetricsConstant.AFE_LATENCIES_NAME));
201196
assertFalse(
202197
checkIfMetricExists(metricReader, BuiltInMetricsConstant.AFE_CONNECTIVITY_ERROR_NAME));
198+
if (GapicSpannerRpc.isEnableDirectPathXdsEnv()) {
199+
// AFE metrics are enabled for DirectPath.
200+
MetricData afeLatencyMetricData =
201+
getMetricData(metricReader, BuiltInMetricsConstant.AFE_LATENCIES_NAME);
202+
double afeLatencyValue = getAggregatedValue(afeLatencyMetricData, expectedAttributes);
203+
assertEquals(fakeAFEServerTiming.get(), afeLatencyValue, 0);
204+
} else {
205+
MetricData gfeLatencyMetricData =
206+
getMetricData(metricReader, BuiltInMetricsConstant.GFE_LATENCIES_NAME);
207+
double gfeLatencyValue = getAggregatedValue(gfeLatencyMetricData, expectedAttributes);
208+
assertEquals(fakeServerTiming.get(), gfeLatencyValue, 0);
209+
assertFalse(checkIfMetricExists(metricReader, BuiltInMetricsConstant.AFE_LATENCIES_NAME));
210+
}
203211
}
204212

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

264-
MetricData gfeLatencyMetricData =
265-
getMetricData(metricReader, BuiltInMetricsConstant.GFE_LATENCIES_NAME);
266-
double gfeLatencyValue = getAggregatedValue(gfeLatencyMetricData, expectedAttributes);
267-
assertEquals(fakeServerTiming.get(), gfeLatencyValue, 0);
268-
269272
assertFalse(
270273
checkIfMetricExists(metricReader, BuiltInMetricsConstant.GFE_CONNECTIVITY_ERROR_NAME));
271-
274+
assertFalse(
275+
checkIfMetricExists(metricReader, BuiltInMetricsConstant.AFE_CONNECTIVITY_ERROR_NAME));
272276
MetricData afeLatencyMetricData =
273277
getMetricData(metricReader, BuiltInMetricsConstant.AFE_LATENCIES_NAME);
274278
double afeLatencyValue = getAggregatedValue(afeLatencyMetricData, expectedAttributes);
275279
assertEquals(fakeAFEServerTiming.get(), afeLatencyValue, 0);
276-
assertFalse(
277-
checkIfMetricExists(metricReader, BuiltInMetricsConstant.AFE_CONNECTIVITY_ERROR_NAME));
280+
281+
MetricData gfeLatencyMetricData =
282+
getMetricData(metricReader, BuiltInMetricsConstant.GFE_LATENCIES_NAME);
283+
double gfeLatencyValue = getAggregatedValue(gfeLatencyMetricData, expectedAttributes);
284+
assertEquals(fakeServerTiming.get(), gfeLatencyValue, 0);
278285
} finally {
279286
writeableEnvironmentVariables.remove("GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS");
280287
}
@@ -445,13 +452,20 @@ public void testNoServerTimingHeader() throws IOException, InterruptedException
445452
.put(BuiltInMetricsConstant.METHOD_KEY, "Spanner.ExecuteSql")
446453
.build();
447454

448-
MetricData gfeConnectivityMetricData =
449-
getMetricData(metricReader, BuiltInMetricsConstant.GFE_CONNECTIVITY_ERROR_NAME);
450-
assertThat(getAggregatedValue(gfeConnectivityMetricData, expectedAttributes)).isEqualTo(1);
451455
assertFalse(checkIfMetricExists(metricReader, BuiltInMetricsConstant.AFE_LATENCIES_NAME));
452456
assertFalse(checkIfMetricExists(metricReader, BuiltInMetricsConstant.GFE_LATENCIES_NAME));
453-
assertFalse(
454-
checkIfMetricExists(metricReader, BuiltInMetricsConstant.AFE_CONNECTIVITY_ERROR_NAME));
457+
if (GapicSpannerRpc.isEnableDirectPathXdsEnv()) {
458+
MetricData afeConnectivityMetricData =
459+
getMetricData(metricReader, BuiltInMetricsConstant.AFE_CONNECTIVITY_ERROR_NAME);
460+
assertThat(getAggregatedValue(afeConnectivityMetricData, expectedAttributes)).isEqualTo(1);
461+
} else {
462+
MetricData gfeConnectivityMetricData =
463+
getMetricData(metricReader, BuiltInMetricsConstant.GFE_CONNECTIVITY_ERROR_NAME);
464+
assertThat(getAggregatedValue(gfeConnectivityMetricData, expectedAttributes)).isEqualTo(1);
465+
assertFalse(
466+
checkIfMetricExists(metricReader, BuiltInMetricsConstant.AFE_CONNECTIVITY_ERROR_NAME));
467+
}
468+
455469
spannerNoHeader.close();
456470
serverNoHeader.shutdown();
457471
serverNoHeader.awaitTermination();

0 commit comments

Comments
 (0)