|
34 | 34 | import com.google.cloud.spanner.MockSpannerServiceImpl.SimulatedExecutionTime; |
35 | 35 | import com.google.cloud.spanner.MockSpannerServiceImpl.StatementResult; |
36 | 36 | import com.google.cloud.spanner.connection.RandomResultSetGenerator; |
| 37 | +import com.google.cloud.spanner.spi.v1.GapicSpannerRpc; |
37 | 38 | import com.google.common.base.Stopwatch; |
38 | 39 | import com.google.common.collect.ImmutableList; |
39 | 40 | import com.google.common.collect.Range; |
@@ -190,16 +191,23 @@ public void testMetricsSingleUseQuery() { |
190 | 191 | assertNotNull(attemptCountMetricData); |
191 | 192 | assertThat(getAggregatedValue(attemptCountMetricData, expectedAttributes)).isEqualTo(1); |
192 | 193 |
|
193 | | - MetricData gfeLatencyMetricData = |
194 | | - getMetricData(metricReader, BuiltInMetricsConstant.GFE_LATENCIES_NAME); |
195 | | - double gfeLatencyValue = getAggregatedValue(gfeLatencyMetricData, expectedAttributes); |
196 | | - assertEquals(fakeServerTiming.get(), gfeLatencyValue, 0); |
197 | | - |
198 | 194 | assertFalse( |
199 | 195 | checkIfMetricExists(metricReader, BuiltInMetricsConstant.GFE_CONNECTIVITY_ERROR_NAME)); |
200 | | - assertFalse(checkIfMetricExists(metricReader, BuiltInMetricsConstant.AFE_LATENCIES_NAME)); |
201 | 196 | assertFalse( |
202 | 197 | 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, 1e-6); |
| 204 | + } else { |
| 205 | + MetricData gfeLatencyMetricData = |
| 206 | + getMetricData(metricReader, BuiltInMetricsConstant.GFE_LATENCIES_NAME); |
| 207 | + double gfeLatencyValue = getAggregatedValue(gfeLatencyMetricData, expectedAttributes); |
| 208 | + assertEquals(fakeServerTiming.get(), gfeLatencyValue, 1e-6); |
| 209 | + assertFalse(checkIfMetricExists(metricReader, BuiltInMetricsConstant.AFE_LATENCIES_NAME)); |
| 210 | + } |
203 | 211 | } |
204 | 212 |
|
205 | 213 | private boolean isJava8() { |
@@ -261,20 +269,19 @@ public void testMetricsSingleUseQueryWithAfeEnabled() throws Exception { |
261 | 269 | assertNotNull(attemptCountMetricData); |
262 | 270 | assertThat(getAggregatedValue(attemptCountMetricData, expectedAttributes)).isEqualTo(1); |
263 | 271 |
|
264 | | - MetricData gfeLatencyMetricData = |
265 | | - getMetricData(metricReader, BuiltInMetricsConstant.GFE_LATENCIES_NAME); |
266 | | - double gfeLatencyValue = getAggregatedValue(gfeLatencyMetricData, expectedAttributes); |
267 | | - assertEquals(fakeServerTiming.get(), gfeLatencyValue, 0); |
268 | | - |
269 | 272 | assertFalse( |
270 | 273 | checkIfMetricExists(metricReader, BuiltInMetricsConstant.GFE_CONNECTIVITY_ERROR_NAME)); |
271 | | - |
| 274 | + assertFalse( |
| 275 | + checkIfMetricExists(metricReader, BuiltInMetricsConstant.AFE_CONNECTIVITY_ERROR_NAME)); |
272 | 276 | MetricData afeLatencyMetricData = |
273 | 277 | getMetricData(metricReader, BuiltInMetricsConstant.AFE_LATENCIES_NAME); |
274 | 278 | double afeLatencyValue = getAggregatedValue(afeLatencyMetricData, expectedAttributes); |
275 | | - assertEquals(fakeAFEServerTiming.get(), afeLatencyValue, 0); |
276 | | - assertFalse( |
277 | | - checkIfMetricExists(metricReader, BuiltInMetricsConstant.AFE_CONNECTIVITY_ERROR_NAME)); |
| 279 | + assertEquals(fakeAFEServerTiming.get(), afeLatencyValue, 1e-6); |
| 280 | + |
| 281 | + MetricData gfeLatencyMetricData = |
| 282 | + getMetricData(metricReader, BuiltInMetricsConstant.GFE_LATENCIES_NAME); |
| 283 | + double gfeLatencyValue = getAggregatedValue(gfeLatencyMetricData, expectedAttributes); |
| 284 | + assertEquals(fakeServerTiming.get(), gfeLatencyValue, 1e-6); |
278 | 285 | } finally { |
279 | 286 | writeableEnvironmentVariables.remove("GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS"); |
280 | 287 | } |
@@ -445,13 +452,20 @@ public void testNoServerTimingHeader() throws IOException, InterruptedException |
445 | 452 | .put(BuiltInMetricsConstant.METHOD_KEY, "Spanner.ExecuteSql") |
446 | 453 | .build(); |
447 | 454 |
|
448 | | - MetricData gfeConnectivityMetricData = |
449 | | - getMetricData(metricReader, BuiltInMetricsConstant.GFE_CONNECTIVITY_ERROR_NAME); |
450 | | - assertThat(getAggregatedValue(gfeConnectivityMetricData, expectedAttributes)).isEqualTo(1); |
451 | 455 | assertFalse(checkIfMetricExists(metricReader, BuiltInMetricsConstant.AFE_LATENCIES_NAME)); |
452 | 456 | 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 | + |
455 | 469 | spannerNoHeader.close(); |
456 | 470 | serverNoHeader.shutdown(); |
457 | 471 | serverNoHeader.awaitTermination(); |
|
0 commit comments