@@ -85,7 +85,7 @@ public class OpenTelemetryBuiltInMetricsTracerTest extends AbstractNettyMockServ
85
85
Attributes .builder ().put (BuiltInMetricsConstant .DIRECT_PATH_USED_KEY , "false" ).build ();
86
86
;
87
87
88
- private static final long MIN_LATENCY = 0 ;
88
+ private static final double MIN_LATENCY = 0 ;
89
89
90
90
private DatabaseClient client ;
91
91
@@ -160,7 +160,7 @@ public void testMetricsSingleUseQuery() {
160
160
assertFalse (resultSet .next ());
161
161
}
162
162
163
- long elapsed = stopwatch .elapsed (TimeUnit .MILLISECONDS );
163
+ double elapsed = stopwatch .elapsed (TimeUnit .MILLISECONDS );
164
164
Attributes expectedAttributes =
165
165
expectedCommonBaseAttributes .toBuilder ()
166
166
.putAll (expectedCommonRequestAttributes )
@@ -171,13 +171,14 @@ public void testMetricsSingleUseQuery() {
171
171
MetricData operationLatencyMetricData =
172
172
getMetricData (metricReader , BuiltInMetricsConstant .OPERATION_LATENCIES_NAME );
173
173
assertNotNull (operationLatencyMetricData );
174
- long operationLatencyValue = getAggregatedValue (operationLatencyMetricData , expectedAttributes );
174
+ double operationLatencyValue =
175
+ getAggregatedValue (operationLatencyMetricData , expectedAttributes );
175
176
assertThat (operationLatencyValue ).isIn (Range .closed (MIN_LATENCY , elapsed ));
176
177
177
178
MetricData attemptLatencyMetricData =
178
179
getMetricData (metricReader , BuiltInMetricsConstant .ATTEMPT_LATENCIES_NAME );
179
180
assertNotNull (attemptLatencyMetricData );
180
- long attemptLatencyValue = getAggregatedValue (attemptLatencyMetricData , expectedAttributes );
181
+ double attemptLatencyValue = getAggregatedValue (attemptLatencyMetricData , expectedAttributes );
181
182
assertThat (attemptLatencyValue ).isIn (Range .closed (MIN_LATENCY , elapsed ));
182
183
183
184
MetricData operationCountMetricData =
@@ -198,12 +199,12 @@ public void testMetricsSingleUseQuery() {
198
199
// AFE metrics are enabled for DirectPath.
199
200
MetricData afeLatencyMetricData =
200
201
getMetricData (metricReader , BuiltInMetricsConstant .AFE_LATENCIES_NAME );
201
- long afeLatencyValue = getAggregatedValue (afeLatencyMetricData , expectedAttributes );
202
+ double afeLatencyValue = getAggregatedValue (afeLatencyMetricData , expectedAttributes );
202
203
assertEquals (fakeAFEServerTiming .get (), afeLatencyValue , 0 );
203
204
} else {
204
205
MetricData gfeLatencyMetricData =
205
206
getMetricData (metricReader , BuiltInMetricsConstant .GFE_LATENCIES_NAME );
206
- long gfeLatencyValue = getAggregatedValue (gfeLatencyMetricData , expectedAttributes );
207
+ double gfeLatencyValue = getAggregatedValue (gfeLatencyMetricData , expectedAttributes );
207
208
assertEquals (fakeServerTiming .get (), gfeLatencyValue , 0 );
208
209
assertFalse (checkIfMetricExists (metricReader , BuiltInMetricsConstant .AFE_LATENCIES_NAME ));
209
210
}
@@ -237,7 +238,7 @@ public void testMetricsSingleUseQueryWithAfeEnabled() throws Exception {
237
238
assertFalse (resultSet .next ());
238
239
}
239
240
240
- long elapsed = stopwatch .elapsed (TimeUnit .MILLISECONDS );
241
+ double elapsed = stopwatch .elapsed (TimeUnit .MILLISECONDS );
241
242
Attributes expectedAttributes =
242
243
expectedCommonBaseAttributes .toBuilder ()
243
244
.putAll (expectedCommonRequestAttributes )
@@ -248,14 +249,14 @@ public void testMetricsSingleUseQueryWithAfeEnabled() throws Exception {
248
249
MetricData operationLatencyMetricData =
249
250
getMetricData (metricReader , BuiltInMetricsConstant .OPERATION_LATENCIES_NAME );
250
251
assertNotNull (operationLatencyMetricData );
251
- long operationLatencyValue =
252
+ double operationLatencyValue =
252
253
getAggregatedValue (operationLatencyMetricData , expectedAttributes );
253
254
assertThat (operationLatencyValue ).isIn (Range .closed (MIN_LATENCY , elapsed ));
254
255
255
256
MetricData attemptLatencyMetricData =
256
257
getMetricData (metricReader , BuiltInMetricsConstant .ATTEMPT_LATENCIES_NAME );
257
258
assertNotNull (attemptLatencyMetricData );
258
- long attemptLatencyValue = getAggregatedValue (attemptLatencyMetricData , expectedAttributes );
259
+ double attemptLatencyValue = getAggregatedValue (attemptLatencyMetricData , expectedAttributes );
259
260
assertThat (attemptLatencyValue ).isIn (Range .closed (MIN_LATENCY , elapsed ));
260
261
261
262
MetricData operationCountMetricData =
@@ -274,12 +275,12 @@ public void testMetricsSingleUseQueryWithAfeEnabled() throws Exception {
274
275
checkIfMetricExists (metricReader , BuiltInMetricsConstant .AFE_CONNECTIVITY_ERROR_NAME ));
275
276
MetricData afeLatencyMetricData =
276
277
getMetricData (metricReader , BuiltInMetricsConstant .AFE_LATENCIES_NAME );
277
- long afeLatencyValue = getAggregatedValue (afeLatencyMetricData , expectedAttributes );
278
+ double afeLatencyValue = getAggregatedValue (afeLatencyMetricData , expectedAttributes );
278
279
assertEquals (fakeAFEServerTiming .get (), afeLatencyValue , 0 );
279
280
280
281
MetricData gfeLatencyMetricData =
281
282
getMetricData (metricReader , BuiltInMetricsConstant .GFE_LATENCIES_NAME );
282
- long gfeLatencyValue = getAggregatedValue (gfeLatencyMetricData , expectedAttributes );
283
+ double gfeLatencyValue = getAggregatedValue (gfeLatencyMetricData , expectedAttributes );
283
284
assertEquals (fakeServerTiming .get (), gfeLatencyValue , 0 );
284
285
} finally {
285
286
writeableEnvironmentVariables .remove ("GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS" );
@@ -409,7 +410,7 @@ public void testNoNetworkConnection() {
409
410
410
411
// Attempt count should have a failed metric point for CreateSession.
411
412
assertEquals (
412
- 1 , getAggregatedValue (attemptCountMetricData , expectedAttributesCreateSessionFailed ));
413
+ 1 , getAggregatedValue (attemptCountMetricData , expectedAttributesCreateSessionFailed ), 0 );
413
414
}
414
415
415
416
@ Test
@@ -523,14 +524,14 @@ private boolean checkIfMetricExists(InMemoryMetricReader reader, String metricNa
523
524
return false ;
524
525
}
525
526
526
- private long getAggregatedValue (MetricData metricData , Attributes attributes ) {
527
+ private float getAggregatedValue (MetricData metricData , Attributes attributes ) {
527
528
switch (metricData .getType ()) {
528
529
case HISTOGRAM :
529
530
return metricData .getHistogramData ().getPoints ().stream ()
530
531
.filter (pd -> pd .getAttributes ().equals (attributes ))
531
- .map (data -> (long ) data .getSum () / data .getCount ())
532
+ .map (data -> (float ) data .getSum () / data .getCount ())
532
533
.findFirst ()
533
- .orElse (0L );
534
+ .orElse (0F );
534
535
case LONG_SUM :
535
536
return metricData .getLongSumData ().getPoints ().stream ()
536
537
.filter (pd -> pd .getAttributes ().equals (attributes ))
0 commit comments