Class MetricsRetryListener
java.lang.Object
org.springframework.retry.support.MetricsRetryListener
- All Implemented Interfaces:
RetryListener
The
RetryListener implementation for Micrometer Timers 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.voidsetCustomTags(Iterable<io.micrometer.core.instrument.Tag> customTags) Supply tags which are going to be used for all the timers managed by this listener.voidsetCustomTagsProvider(Function<RetryContext, Iterable<io.micrometer.core.instrument.Tag>> customTagsProvider) Supply aFunctionto 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, waitMethods 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- theMeterRegistryto 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 aFunctionto build additional tags for all the timers based on theRetryContext.- Parameters:
customTagsProvider- theFunctionfor additional tags with aRetryContextscope.
-
open
Description copied from interface:RetryListenerCalled 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 aTerminatedRetryExceptionwill be thrown.- Specified by:
openin 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:RetryListenerCalled 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:
closein 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.
-