Skip to content

Commit 2a4949b

Browse files
committed
modify overloads in ApiTracer
1 parent 9f51822 commit 2a4949b

File tree

8 files changed

+23
-22
lines changed

8 files changed

+23
-22
lines changed

gax-java/gax/src/main/java/com/google/api/gax/retrying/BasicRetryingFuture.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ void handleAttempt(Throwable throwable, ResponseT response) {
187187
"retriableException: " + throwable
188188
});
189189
}
190-
tracer.attemptFailed(throwable, nextAttemptSettings.getRandomizedRetryDelayDuration());
190+
tracer.attemptFailedDuration(throwable, nextAttemptSettings.getRandomizedRetryDelayDuration());
191191
attemptSettings = nextAttemptSettings;
192192
setAttemptResult(throwable, response, true);
193193
// a new attempt will be (must be) scheduled by an external executor

gax-java/gax/src/main/java/com/google/api/gax/tracing/ApiTracer.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,10 @@ default Scope inScope() {
110110
/** Add an annotation that the attempt was cancelled by the user. */
111111
default void attemptCancelled() {};
112112

113-
/** Backport of {@link #attemptFailed(Throwable, java.time.Duration)} */
114-
@ObsoleteApi("Use attemptFailed(Throwable, java.time.Duration) instead")
113+
/** Backport of {@link #attemptFailedDuration(Throwable, java.time.Duration)} */
114+
@ObsoleteApi("Use attemptFailedDuration(Throwable, java.time.Duration) instead")
115115
default void attemptFailed(Throwable error, org.threeten.bp.Duration delay) {
116-
attemptFailed(error, toJavaTimeDuration(delay));
116+
attemptFailedDuration(error, toJavaTimeDuration(delay));
117117
};
118118

119119
/**
@@ -122,7 +122,7 @@ default void attemptFailed(Throwable error, org.threeten.bp.Duration delay) {
122122
* @param error the transient error that caused the attempt to fail.
123123
* @param delay the amount of time to wait before the next attempt will start.
124124
*/
125-
default void attemptFailed(Throwable error, java.time.Duration delay) {};
125+
default void attemptFailedDuration(Throwable error, java.time.Duration delay) {};
126126

127127
/**
128128
* Adds an annotation that the attempt failed and that no further attempts will be made because

gax-java/gax/src/main/java/com/google/api/gax/tracing/BaseApiTracer.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,15 @@ public void attemptCancelled() {
106106
}
107107

108108
@Override
109-
public void attemptFailed(Throwable error, java.time.Duration delay) {
109+
public void attemptFailedDuration(Throwable error, java.time.Duration delay) {
110110
// noop
111111
}
112112

113-
/** Backport of {@link #attemptFailed(Throwable, java.time.Duration)} */
113+
/** Backport of {@link #attemptFailedDuration(Throwable, java.time.Duration)} */
114114
@Override
115115
@ObsoleteApi("Use attemptFailed(Throwable, java.time.Duration) instead")
116116
public void attemptFailed(Throwable error, org.threeten.bp.Duration delay) {
117-
attemptFailed(error, toJavaTimeDuration(delay));
117+
attemptFailedDuration(error, toJavaTimeDuration(delay));
118118
}
119119

120120
@Override

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -173,17 +173,17 @@ public void attemptCancelled() {
173173
* key.
174174
*/
175175
@Override
176-
public void attemptFailed(Throwable error, java.time.Duration delay) {
176+
public void attemptFailedDuration(Throwable error, java.time.Duration delay) {
177177
attributes.put(STATUS_ATTRIBUTE, extractStatus(error));
178178
metricsRecorder.recordAttemptLatency(attemptTimer.elapsed(TimeUnit.MILLISECONDS), attributes);
179179
metricsRecorder.recordAttemptCount(1, attributes);
180180
}
181181

182-
/** Backport of {@link #attemptFailed(Throwable, java.time.Duration)} */
182+
/** Backport of {@link #attemptFailedDuration(Throwable, java.time.Duration)} */
183183
@Override
184-
@ObsoleteApi("Use attemptFailed(Throwable, java.time.Duration) instead")
184+
@ObsoleteApi("Use attemptFailedDuration(Throwable, java.time.Duration) instead")
185185
public void attemptFailed(Throwable error, org.threeten.bp.Duration delay) {
186-
attemptFailed(error, toJavaTimeDuration(delay));
186+
attemptFailedDuration(error, toJavaTimeDuration(delay));
187187
}
188188

189189
/**

gax-java/gax/src/main/java/com/google/api/gax/tracing/OpencensusTracer.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ public void attemptCancelled() {
344344

345345
/** {@inheritDoc} */
346346
@Override
347-
public void attemptFailed(Throwable error, java.time.Duration delay) {
347+
public void attemptFailedDuration(Throwable error, java.time.Duration delay) {
348348
Map<String, AttributeValue> attributes = baseAttemptAttributes();
349349
attributes.put("delay ms", AttributeValue.longAttributeValue(delay.toMillis()));
350350
populateError(attributes, error);
@@ -359,11 +359,11 @@ public void attemptFailed(Throwable error, java.time.Duration delay) {
359359
lastConnectionId = null;
360360
}
361361

362-
/** Backport of {@link #attemptFailed(Throwable, java.time.Duration)} */
362+
/** Backport of {@link #attemptFailedDuration(Throwable, java.time.Duration)} */
363363
@Override
364-
@ObsoleteApi("Use attemptFailed(Throwable, java.time.Duration) instead")
364+
@ObsoleteApi("Use attemptFailedDuration(Throwable, java.time.Duration) instead")
365365
public void attemptFailed(Throwable error, org.threeten.bp.Duration delay) {
366-
attemptFailed(error, toJavaTimeDuration(delay));
366+
attemptFailedDuration(error, toJavaTimeDuration(delay));
367367
}
368368

369369
/** {@inheritDoc} */

gax-java/gax/src/test/java/com/google/api/gax/retrying/AbstractRetryingExecutorTest.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public void testSuccessWithFailures() throws Exception {
143143
assertEquals(5, future.getAttemptSettings().getAttemptCount());
144144

145145
verify(tracer, times(6)).attemptStarted(eq("request"), anyInt());
146-
verify(tracer, times(5)).attemptFailed(any(Throwable.class), any(java.time.Duration.class));
146+
verify(tracer, times(5)).attemptFailedDuration(any(Throwable.class), any(java.time.Duration.class));
147147
verify(tracer, times(1)).attemptSucceeded();
148148
verifyNoMoreInteractions(tracer);
149149
}
@@ -188,7 +188,7 @@ public void testMaxRetriesExceeded() throws Exception {
188188
assertEquals(5, future.getAttemptSettings().getAttemptCount());
189189

190190
verify(tracer, times(6)).attemptStarted(eq("request"), anyInt());
191-
verify(tracer, times(5)).attemptFailed(any(Throwable.class), any(java.time.Duration.class));
191+
verify(tracer, times(5)).attemptFailedDuration(any(Throwable.class), any(java.time.Duration.class));
192192
verify(tracer, times(1)).attemptFailedRetriesExhausted(any(Throwable.class));
193193
verifyNoMoreInteractions(tracer);
194194
}
@@ -266,7 +266,7 @@ public void testCancelByRetryingAlgorithm() throws Exception {
266266

267267
verify(tracer, times(5)).attemptStarted(eq("request"), anyInt());
268268
// Pre-apocalypse failures
269-
verify(tracer, times(4)).attemptFailed(any(Throwable.class), any(java.time.Duration.class));
269+
verify(tracer, times(4)).attemptFailedDuration(any(Throwable.class), any(java.time.Duration.class));
270270
// Apocalypse failure
271271
verify(tracer, times(1)).attemptFailedRetriesExhausted(any(CancellationException.class));
272272
verifyNoMoreInteractions(tracer);
@@ -286,7 +286,7 @@ public void testUnexpectedExceptionFromRetryAlgorithm() throws Exception {
286286

287287
verify(tracer, times(5)).attemptStarted(eq("request"), anyInt());
288288
// Pre-apocalypse failures
289-
verify(tracer, times(4)).attemptFailed(any(Throwable.class), any(java.time.Duration.class));
289+
verify(tracer, times(4)).attemptFailedDuration(any(Throwable.class), any(java.time.Duration.class));
290290
// Apocalypse failure
291291
verify(tracer, times(1)).attemptPermanentFailure(any(RuntimeException.class));
292292
verifyNoMoreInteractions(tracer);

gax-java/gax/src/test/java/com/google/api/gax/retrying/BasicRetryingFutureTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public void testHandleAttemptDoesNotThrowNPEWhenLogLevelLowerThanFiner() throws
9595
future.handleAttempt(null, null);
9696

9797
Mockito.verify(tracer)
98-
.attemptFailed(
98+
.attemptFailedDuration(
9999
ArgumentMatchers.<Throwable>any(), ArgumentMatchers.<java.time.Duration>any());
100100
Mockito.verifyNoMoreInteractions(tracer);
101101
}

gax-java/gax/src/test/java/com/google/api/gax/tracing/MetricsTestUtils.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,11 @@
3636
public class MetricsTestUtils {
3737
public static void reportFailedAttempt(ApiTracer tracer, Exception ex, Object delayValue) {
3838
try {
39+
final String methodName = delayValue.getClass().getName().startsWith("java.time") ? "attemptFailedDuration" : "attemptFailed";
3940
Method attemptFailed =
4041
tracer
4142
.getClass()
42-
.getDeclaredMethod("attemptFailed", Throwable.class, delayValue.getClass());
43+
.getDeclaredMethod(methodName, Throwable.class, delayValue.getClass());
4344
attemptFailed.invoke(tracer, ex, delayValue);
4445
} catch (Exception e) {
4546
fail();

0 commit comments

Comments
 (0)