24
24
import static org .junit .Assert .assertThrows ;
25
25
import static org .junit .Assert .assertTrue ;
26
26
import static org .junit .Assert .fail ;
27
- import static org .junit .Assume .assumeFalse ;
28
- import static org .junit .Assume .assumeTrue ;
29
27
30
28
import com .google .api .gax .longrunning .OperationTimedPollAlgorithm ;
31
29
import com .google .api .gax .retrying .RetrySettings ;
34
32
import com .google .cloud .spanner .MockSpannerServiceImpl .SimulatedExecutionTime ;
35
33
import com .google .cloud .spanner .MockSpannerServiceImpl .StatementResult ;
36
34
import com .google .cloud .spanner .connection .RandomResultSetGenerator ;
37
- import com .google .cloud .spanner .spi .v1 .GapicSpannerRpc ;
38
35
import com .google .common .base .Stopwatch ;
39
36
import com .google .common .collect .ImmutableList ;
40
37
import com .google .common .collect .Range ;
51
48
import io .opentelemetry .sdk .metrics .data .MetricData ;
52
49
import io .opentelemetry .sdk .testing .exporter .InMemoryMetricReader ;
53
50
import java .io .IOException ;
54
- import java .lang .reflect .Field ;
55
51
import java .net .InetSocketAddress ;
56
52
import java .time .Duration ;
57
53
import java .util .Collection ;
@@ -195,19 +191,11 @@ public void testMetricsSingleUseQuery() {
195
191
checkIfMetricExists (metricReader , BuiltInMetricsConstant .GFE_CONNECTIVITY_ERROR_NAME ));
196
192
assertFalse (
197
193
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
- }
194
+ // AFE metrics are enabled for DirectPath.
195
+ MetricData afeLatencyMetricData =
196
+ getMetricData (metricReader , BuiltInMetricsConstant .AFE_LATENCIES_NAME );
197
+ double afeLatencyValue = getAggregatedValue (afeLatencyMetricData , expectedAttributes );
198
+ assertEquals (fakeAFEServerTiming .get (), afeLatencyValue , 1e-6 );
211
199
}
212
200
213
201
private boolean isJava8 () {
@@ -218,75 +206,6 @@ private boolean isWindows() {
218
206
return System .getProperty ("os.name" ).toLowerCase ().contains ("windows" );
219
207
}
220
208
221
- @ Test
222
- public void testMetricsSingleUseQueryWithAfeEnabled () throws Exception {
223
- assumeTrue (isJava8 () && !isWindows ());
224
- assumeFalse (System .getenv ().containsKey ("SPANNER_DISABLE_AFE_SERVER_TIMING" ));
225
-
226
- Class <?> classOfMap = System .getenv ().getClass ();
227
- Field field = classOfMap .getDeclaredField ("m" );
228
- field .setAccessible (true );
229
- Map <String , String > writeableEnvironmentVariables =
230
- (Map <String , String >) field .get (System .getenv ());
231
-
232
- try {
233
- writeableEnvironmentVariables .put ("SPANNER_DISABLE_AFE_SERVER_TIMING" , "false" );
234
-
235
- Stopwatch stopwatch = Stopwatch .createStarted ();
236
- try (ResultSet resultSet = client .singleUse ().executeQuery (SELECT_RANDOM )) {
237
- assertTrue (resultSet .next ());
238
- assertFalse (resultSet .next ());
239
- }
240
-
241
- double elapsed = stopwatch .elapsed (TimeUnit .MILLISECONDS );
242
- Attributes expectedAttributes =
243
- expectedCommonBaseAttributes .toBuilder ()
244
- .putAll (expectedCommonRequestAttributes )
245
- .put (BuiltInMetricsConstant .STATUS_KEY , "OK" )
246
- .put (BuiltInMetricsConstant .METHOD_KEY , "Spanner.ExecuteStreamingSql" )
247
- .build ();
248
-
249
- MetricData operationLatencyMetricData =
250
- getMetricData (metricReader , BuiltInMetricsConstant .OPERATION_LATENCIES_NAME );
251
- assertNotNull (operationLatencyMetricData );
252
- double operationLatencyValue =
253
- getAggregatedValue (operationLatencyMetricData , expectedAttributes );
254
- assertThat (operationLatencyValue ).isIn (Range .closed (MIN_LATENCY , elapsed ));
255
-
256
- MetricData attemptLatencyMetricData =
257
- getMetricData (metricReader , BuiltInMetricsConstant .ATTEMPT_LATENCIES_NAME );
258
- assertNotNull (attemptLatencyMetricData );
259
- double attemptLatencyValue = getAggregatedValue (attemptLatencyMetricData , expectedAttributes );
260
- assertThat (attemptLatencyValue ).isIn (Range .closed (MIN_LATENCY , elapsed ));
261
-
262
- MetricData operationCountMetricData =
263
- getMetricData (metricReader , BuiltInMetricsConstant .OPERATION_COUNT_NAME );
264
- assertNotNull (operationCountMetricData );
265
- assertThat (getAggregatedValue (operationCountMetricData , expectedAttributes )).isEqualTo (1 );
266
-
267
- MetricData attemptCountMetricData =
268
- getMetricData (metricReader , BuiltInMetricsConstant .ATTEMPT_COUNT_NAME );
269
- assertNotNull (attemptCountMetricData );
270
- assertThat (getAggregatedValue (attemptCountMetricData , expectedAttributes )).isEqualTo (1 );
271
-
272
- assertFalse (
273
- checkIfMetricExists (metricReader , BuiltInMetricsConstant .GFE_CONNECTIVITY_ERROR_NAME ));
274
- assertFalse (
275
- checkIfMetricExists (metricReader , BuiltInMetricsConstant .AFE_CONNECTIVITY_ERROR_NAME ));
276
- MetricData afeLatencyMetricData =
277
- getMetricData (metricReader , BuiltInMetricsConstant .AFE_LATENCIES_NAME );
278
- double afeLatencyValue = getAggregatedValue (afeLatencyMetricData , expectedAttributes );
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 );
285
- } finally {
286
- writeableEnvironmentVariables .remove ("GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS" );
287
- }
288
- }
289
-
290
209
@ Test
291
210
public void testMetricsWithGaxRetryUnaryRpc () {
292
211
Stopwatch stopwatch = Stopwatch .createStarted ();
@@ -454,17 +373,9 @@ public void testNoServerTimingHeader() throws IOException, InterruptedException
454
373
455
374
assertFalse (checkIfMetricExists (metricReader , BuiltInMetricsConstant .AFE_LATENCIES_NAME ));
456
375
assertFalse (checkIfMetricExists (metricReader , BuiltInMetricsConstant .GFE_LATENCIES_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
- }
376
+ MetricData afeConnectivityMetricData =
377
+ getMetricData (metricReader , BuiltInMetricsConstant .AFE_CONNECTIVITY_ERROR_NAME );
378
+ assertThat (getAggregatedValue (afeConnectivityMetricData , expectedAttributes )).isEqualTo (1 );
468
379
469
380
spannerNoHeader .close ();
470
381
serverNoHeader .shutdown ();
0 commit comments