Skip to content

Commit 85c57c2

Browse files
committed
fix spanner test
1 parent 7c286b9 commit 85c57c2

1 file changed

Lines changed: 8 additions & 11 deletions

File tree

sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/tracing/MetricsTracer.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public void operationSucceeded() {
9494
throw new IllegalStateException(OPERATION_FINISHED_STATUS_MESSAGE);
9595
}
9696
attributes.put(STATUS_ATTRIBUTE, StatusCode.Code.OK.toString());
97-
metricsRecorder.recordOperationLatency(elapsedMillis(operationTimer), attributes);
97+
metricsRecorder.recordOperationLatency(operationTimer.elapsed(TimeUnit.NANOSECONDS) / 1_000_000.0, attributes);
9898
metricsRecorder.recordOperationCount(1, attributes);
9999
}
100100

@@ -111,7 +111,7 @@ public void operationCancelled() {
111111
throw new IllegalStateException(OPERATION_FINISHED_STATUS_MESSAGE);
112112
}
113113
attributes.put(STATUS_ATTRIBUTE, StatusCode.Code.CANCELLED.toString());
114-
metricsRecorder.recordOperationLatency(elapsedMillis(operationTimer), attributes);
114+
metricsRecorder.recordOperationLatency(operationTimer.elapsed(TimeUnit.NANOSECONDS) / 1_000_000.0, attributes);
115115
metricsRecorder.recordOperationCount(1, attributes);
116116
}
117117

@@ -129,7 +129,7 @@ public void operationFailed(Throwable error) {
129129
}
130130
// Uses the GRPC status code representation.
131131
attributes.put(STATUS_ATTRIBUTE, ObservabilityUtils.extractStatus(error).toString());
132-
metricsRecorder.recordOperationLatency(elapsedMillis(operationTimer), attributes);
132+
metricsRecorder.recordOperationLatency(operationTimer.elapsed(TimeUnit.NANOSECONDS) / 1_000_000.0, attributes);
133133
metricsRecorder.recordOperationCount(1, attributes);
134134
}
135135

@@ -154,7 +154,7 @@ public void attemptStarted(Object request, int attemptNumber) {
154154
@Override
155155
public void attemptSucceeded() {
156156
attributes.put(STATUS_ATTRIBUTE, StatusCode.Code.OK.toString());
157-
metricsRecorder.recordAttemptLatency(elapsedMillis(attemptTimer), attributes);
157+
metricsRecorder.recordAttemptLatency(attemptTimer.elapsed(TimeUnit.NANOSECONDS) / 1_000_000.0, attributes);
158158
metricsRecorder.recordAttemptCount(1, attributes);
159159
}
160160

@@ -165,7 +165,7 @@ public void attemptSucceeded() {
165165
@Override
166166
public void attemptCancelled() {
167167
attributes.put(STATUS_ATTRIBUTE, StatusCode.Code.CANCELLED.toString());
168-
metricsRecorder.recordAttemptLatency(elapsedMillis(attemptTimer), attributes);
168+
metricsRecorder.recordAttemptLatency(attemptTimer.elapsed(TimeUnit.NANOSECONDS) / 1_000_000.0, attributes);
169169
metricsRecorder.recordAttemptCount(1, attributes);
170170
}
171171

@@ -180,7 +180,7 @@ public void attemptCancelled() {
180180
@Override
181181
public void attemptFailedDuration(Throwable error, java.time.Duration delay) {
182182
attributes.put(STATUS_ATTRIBUTE, ObservabilityUtils.extractStatus(error).toString());
183-
metricsRecorder.recordAttemptLatency(elapsedMillis(attemptTimer), attributes);
183+
metricsRecorder.recordAttemptLatency(attemptTimer.elapsed(TimeUnit.NANOSECONDS) / 1_000_000.0, attributes);
184184
metricsRecorder.recordAttemptCount(1, attributes);
185185
}
186186

@@ -204,7 +204,7 @@ public void attemptFailed(Throwable error, org.threeten.bp.Duration delay) {
204204
@Override
205205
public void attemptFailedRetriesExhausted(Throwable error) {
206206
attributes.put(STATUS_ATTRIBUTE, ObservabilityUtils.extractStatus(error).toString());
207-
metricsRecorder.recordAttemptLatency(elapsedMillis(attemptTimer), attributes);
207+
metricsRecorder.recordAttemptLatency(attemptTimer.elapsed(TimeUnit.NANOSECONDS) / 1_000_000.0, attributes);
208208
metricsRecorder.recordAttemptCount(1, attributes);
209209
}
210210

@@ -218,7 +218,7 @@ public void attemptFailedRetriesExhausted(Throwable error) {
218218
@Override
219219
public void attemptPermanentFailure(Throwable error) {
220220
attributes.put(STATUS_ATTRIBUTE, ObservabilityUtils.extractStatus(error).toString());
221-
metricsRecorder.recordAttemptLatency(elapsedMillis(attemptTimer), attributes);
221+
metricsRecorder.recordAttemptLatency(attemptTimer.elapsed(TimeUnit.NANOSECONDS) / 1_000_000.0, attributes);
222222
metricsRecorder.recordAttemptCount(1, attributes);
223223
}
224224

@@ -242,9 +242,6 @@ public void addAttributes(Map<String, String> attributes) {
242242
}
243243
;
244244

245-
private static double elapsedMillis(Stopwatch stopwatch) {
246-
return stopwatch.elapsed(TimeUnit.NANOSECONDS) / 1_000_000.0;
247-
}
248245

249246
@VisibleForTesting
250247
Map<String, String> getAttributes() {

0 commit comments

Comments
 (0)