Package com.shri.restinpeace.interceptor
Class MetricsInterceptor
java.lang.Object
com.shri.restinpeace.interceptor.MetricsInterceptor
- All Implemented Interfaces:
RequestInterceptor
Pre-built interceptor that times every request and reports it, once its
response comes back, to a
MetricsSink - the metrics counterpart of
LoggingInterceptor, following the exact same "bring your own sink"
shape so RIP doesn't have to depend on Micrometer or any other metrics
library to support one.
Register this first, before any other interceptor, if it should measure the
total time a call takes including every other interceptor's own work;
register it last if it should measure only the network call itself - the
same registration-order tradeoff RequestInterceptor's own javadoc
describes.
Only a call that actually receives a response is reported - a transport
failure (no response at all) never reaches afterResponse, so it
produces no sample through this interceptor. A @Retry'd call
reports one sample per attempt, since every attempt gets its own
afterResponse notification.
-
Constructor Summary
ConstructorsConstructorDescriptionReports each call's metrics to the given sink. -
Method Summary
Modifier and TypeMethodDescriptionvoidafterResponse(RequestContext context, int status, Object body) Called once the response is back.voidbeforeRequest(RequestContext context) Called before the request is sent.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.shri.restinpeace.interceptor.RequestInterceptor
shortCircuit
-
Constructor Details
-
MetricsInterceptor
Reports each call's metrics to the given sink.- Parameters:
sink- receives one call's metrics per completed response
-
-
Method Details
-
beforeRequest
Description copied from interface:RequestInterceptorCalled before the request is sent. Can add headers viaRequestContext.addHeader(java.lang.String, java.lang.String), or abort the call by throwing.- Specified by:
beforeRequestin interfaceRequestInterceptor- Parameters:
context- the request being made
-
afterResponse
Description copied from interface:RequestInterceptorCalled once the response is back.- Specified by:
afterResponsein interfaceRequestInterceptor- Parameters:
context- the request that was madestatus- the HTTP response status codebody- the response body - aString, a deserialized object, ornullfor avoid-returning method
-