Class TrafficResilienceHttpClientFilter
java.lang.Object
io.servicetalk.traffic.resilience.http.TrafficResilienceHttpClientFilter
- All Implemented Interfaces:
HttpExecutionStrategyInfluencer
,StreamingHttpClientFilterFactory
,ExecutionStrategyInfluencer<HttpExecutionStrategy>
public final class TrafficResilienceHttpClientFilter
extends Object
implements StreamingHttpClientFilterFactory
A
StreamingHttpClientFilterFactory
to enforce capacity and circuit-breaking control for a client.
Requests that are not able to acquire a capacity ticket or a circuit permit,
will fail with a RequestDroppedException
.
Ordering of filters
Ordering of thecapacity-filter
is important for various reasons:
- The traffic control filter should be as early as possible in the execution chain to offer a fast-fail reaction and ideally trigger a natural back-pressure mechanism with the transport.
- The traffic control filter should not be offloaded if possible to avoid situations where continuous traffic overflows the offloading subsystem.
- The traffic control filter should be ordered after a
io.servicetalk.http.netty.RetryingHttpRequesterFilter
if one is used, to avail the benefit of retrying requests that failed due to (local or remote) capacity issues.RetryableRequestDroppedException
are safely retry-able errors, since they occur on the outgoing side before they even touch the network.DelayedRetryRequestDroppedException
errors on the other side, are remote rejections, and its up to the application logic to opt-in for them to be retryable, by configuring the relevant predicate of theio.servicetalk.http.netty.RetryingHttpRequesterFilter
- The traffic control filter should be ordered after a
io.servicetalk.http.netty.RetryingHttpRequesterFilter
to allow an already acquiredpermit
to be released in case of other errors/timeouts of the operation, before retrying to re-acquire apermit
. Otherwise, apermit
may be held idle for as long as the operation is awaiting to be re-tried, thus, mis-utilising available resources for other requests through the sameclient
. - If the traffic control filter is ordered after a
timeout-filter
then a potential timeout will be delivered to it in the form of a cancellation. The default terminal callback for the ticket in that case, is set todropped
to avail for local throttling, since a timeout is a good indicator that a sub-process in the pipeline is not completing fast enough. - If the traffic control filter is ordered before a
timeout-filter
then a potential timeout will be delivered to it in the form of aTimeoutException
, which is in turn triggers thedrop-event of the ticket
by default. Behavior can be overridden through thisTrafficResilienceHttpClientFilter.Builder.onErrorTicketTerminal(BiConsumer)
.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
ATrafficResilienceHttpServiceFilter
instance builder. -
Field Summary
Modifier and TypeFieldDescriptionprotected static final Single<StreamingHttpResponse>
static final Predicate<HttpResponseMetaData>
Default rejection observer for dropped requests from an external sourced due to service unavailability.protected static final Single<StreamingHttpResponse>
-
Method Summary
Modifier and TypeMethodDescriptioncreate
(FilterableStreamingHttpClient client) Creates aStreamingHttpClientFilter
using the providedStreamingHttpClientFilter
.Return anExecutionStrategy
that describes the offloads required by the influencer.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.servicetalk.http.api.HttpExecutionStrategyInfluencer
influenceStrategy, requiredOffloads
-
Field Details
-
DEFAULT_BREAKER_REJECTION_PREDICATE
Default rejection observer for dropped requests from an external sourced due to service unavailability. see.peerBreakerRejection(HttpResponseMetaData, CircuitBreaker, Function)
.The default predicate matches the following HTTP response codes:
-
DEFAULT_CAPACITY_REJECTION
-
DEFAULT_BREAKER_REJECTION
-
-
Method Details
-
create
Description copied from interface:StreamingHttpClientFilterFactory
Creates aStreamingHttpClientFilter
using the providedStreamingHttpClientFilter
.- Specified by:
create
in interfaceStreamingHttpClientFilterFactory
- Parameters:
client
-FilterableStreamingHttpClient
to filter- Returns:
StreamingHttpClientFilter
using the providedStreamingHttpClientFilter
.
-
requiredOffloads
Description copied from interface:HttpExecutionStrategyInfluencer
Return anExecutionStrategy
that describes the offloads required by the influencer.The provided default implementation requests offloading of all operations. Implementations that require no offloading should be careful to return
HttpExecutionStrategies.offloadNone()
rather thanHttpExecutionStrategies.offloadNever()
. Implementations should avoid returningHttpExecutionStrategies.defaultStrategy()
, instead returning the strategy they require orHttpExecutionStrategies.offloadAll()
if offloading for all paths is required (safe default).- Specified by:
requiredOffloads
in interfaceExecutionStrategyInfluencer<HttpExecutionStrategy>
- Specified by:
requiredOffloads
in interfaceHttpExecutionStrategyInfluencer
- Returns:
- the
ExecutionStrategy
required by the influencer.
-