Class MetricsRetryListener
java.lang.Object
org.springframework.retry.support.MetricsRetryListener
- All Implemented Interfaces:
RetryListener
The
RetryListener
implementation for Micrometer Timer
s around retry
operations.
The Timer.start()
is called from the open(RetryContext, RetryCallback)
and stopped in the close(RetryContext, RetryCallback, Throwable)
. This
Timer.Sample
is associated with the provided RetryContext
to make this
MetricsRetryListener
instance reusable for many retry operation.
The registered "spring.retry" Timer
has these tags by default:
name
-RetryCallback.getLabel()
retry.count
- the number of attempts - 1; essentially the successful first call means no countsexception
- the thrown back to the caller (after all the retry attempts) exception class name
The setCustomTags(Iterable)
and setCustomTagsProvider(Function)
can
be used to further customize tags on the timers.
- Since:
- 2.0.8
- Author:
- Artem Bilan, Huijin Hong
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionMetricsRetryListener
(io.micrometer.core.instrument.MeterRegistry meterRegistry) Construct an instance based on the providedMeterRegistry
. -
Method Summary
Modifier and TypeMethodDescription<T,
E extends Throwable>
voidclose
(RetryContext context, RetryCallback<T, E> callback, Throwable throwable) Called after the final attempt (successful or not).<T,
E extends Throwable>
booleanopen
(RetryContext context, RetryCallback<T, E> callback) Called before the first attempt in a retry.void
setCustomTags
(Iterable<io.micrometer.core.instrument.Tag> customTags) Supply tags which are going to be used for all the timers managed by this listener.void
setCustomTagsProvider
(Function<RetryContext, Iterable<io.micrometer.core.instrument.Tag>> customTagsProvider) Supply aFunction
to build additional tags for all the timers based on theRetryContext
.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.retry.RetryListener
onError, onSuccess
-
Field Details
-
TIMER_NAME
- See Also:
-
-
Constructor Details
-
MetricsRetryListener
public MetricsRetryListener(io.micrometer.core.instrument.MeterRegistry meterRegistry) Construct an instance based on the providedMeterRegistry
.- Parameters:
meterRegistry
- theMeterRegistry
to use for timers.
-
-
Method Details
-
setCustomTags
Supply tags which are going to be used for all the timers managed by this listener.- Parameters:
customTags
- the list of additional tags for all the timers.
-
setCustomTagsProvider
public void setCustomTagsProvider(Function<RetryContext, Iterable<io.micrometer.core.instrument.Tag>> customTagsProvider) Supply aFunction
to build additional tags for all the timers based on theRetryContext
.- Parameters:
customTagsProvider
- theFunction
for additional tags with aRetryContext
scope.
-
open
Description copied from interface:RetryListener
Called before the first attempt in a retry. For instance, implementers can set up state that is needed by the policies in theRetryOperations
. The whole retry can be vetoed by returning false from this method, in which case aTerminatedRetryException
will be thrown.- Specified by:
open
in interfaceRetryListener
- Type Parameters:
T
- the type of object returned by the callbackE
- the type of exception it declares may be thrown- Parameters:
context
- the currentRetryContext
.callback
- the currentRetryCallback
.- Returns:
- true if the retry should proceed.
-
close
public <T,E extends Throwable> void close(RetryContext context, RetryCallback<T, E> callback, @Nullable Throwable throwable) Description copied from interface:RetryListener
Called after the final attempt (successful or not). Allow the listener to clean up any resource it is holding before control returns to the retry caller.- Specified by:
close
in interfaceRetryListener
- Type Parameters:
T
- the return valueE
- the exception type- Parameters:
context
- the currentRetryContext
.callback
- the currentRetryCallback
.throwable
- the last exception that was thrown by the callback.
-