Skip to content

Commit

Permalink
AbstractTrafficManagementHttpFilter: rename and defer breaker prtns (
Browse files Browse the repository at this point in the history
…#2920)

Motivation:

1. Align naming with `TrafficResilienceHttpClientFilter` and
`TrafficResilienceHttpServiceFilter`.
2. Don't call to `circuitBreakerPartitions` function if
`CapacityLimiter` drops the request.
  • Loading branch information
idelpivnitskiy authored May 11, 2024
1 parent fd65334 commit b757ba2
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@
import static java.util.concurrent.TimeUnit.NANOSECONDS;
import static java.util.concurrent.atomic.AtomicIntegerFieldUpdater.newUpdater;

abstract class AbstractTrafficManagementHttpFilter implements HttpExecutionStrategyInfluencer {
abstract class AbstractTrafficResilienceHttpFilter implements HttpExecutionStrategyInfluencer {
private static final RequestDroppedException CAPACITY_REJECTION = unknownStackTrace(
new RequestDroppedException("Service under heavy load", null, false, true),
AbstractTrafficManagementHttpFilter.class, "remoteRejection");
AbstractTrafficResilienceHttpFilter.class, "remoteRejection");
private static final RequestDroppedException BREAKER_REJECTION = unknownStackTrace(
new RequestDroppedException("Service Unavailable", null, false, true),
AbstractTrafficManagementHttpFilter.class, "breakerRejection");
AbstractTrafficResilienceHttpFilter.class, "breakerRejection");

protected static final Single<StreamingHttpResponse> DEFAULT_CAPACITY_REJECTION =
Single.failed(CAPACITY_REJECTION);
Expand Down Expand Up @@ -88,7 +88,7 @@ abstract class AbstractTrafficManagementHttpFilter implements HttpExecutionStrat

private final TrafficResiliencyObserver observer;

AbstractTrafficManagementHttpFilter(
AbstractTrafficResilienceHttpFilter(
final Supplier<Function<HttpRequestMetaData, CapacityLimiter>> capacityPartitionsSupplier,
final boolean rejectWhenNotMatchedCapacityPartition,
final Function<HttpRequestMetaData, Classification> classifier,
Expand Down Expand Up @@ -146,11 +146,9 @@ Single<StreamingHttpResponse> applyCapacityControl(
.shareContextOnSubscribe();
}

final CircuitBreaker breaker = circuitBreakerPartitions.apply(request);
final ContextMap meta = request.context();
final Classification classification = classifier.apply(request);
Ticket ticket = partition.tryAcquire(classification, meta);

if (ticket != null) {
ticket = new TrackingDelegatingTicket(ticket, request.hashCode());
}
Expand All @@ -159,7 +157,9 @@ Single<StreamingHttpResponse> applyCapacityControl(
observer.onRejectedLimit(request, partition.name(), meta, classification);
return handleLocalCapacityRejection(serverListenContext, request, responseFactory)
.shareContextOnSubscribe();
} else if (breaker != null && !breaker.tryAcquirePermit()) {
}
final CircuitBreaker breaker = circuitBreakerPartitions.apply(request);
if (breaker != null && !breaker.tryAcquirePermit()) {
observer.onRejectedOpenCircuit(request, breaker.name(), meta, classification);
// Ignore the acquired ticket if breaker was open.
ticket.ignored();
Expand Down Expand Up @@ -250,7 +250,7 @@ public void onComplete() {

@Override
public void onError(final Throwable throwable) {
AbstractTrafficManagementHttpFilter.this.onError(throwable, breaker, startTimeNs, ticket);
AbstractTrafficResilienceHttpFilter.this.onError(throwable, breaker, startTimeNs, ticket);
ticketObserver.onError(throwable);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
/**
* A filter that tracks number of pending requests.
* We would like to check the hypothesis if we somehow loose the {@link Ticket} inside
* {@link AbstractTrafficManagementHttpFilter} or if the counter is misaligned for a different reason, like incorrect
* {@link AbstractTrafficResilienceHttpFilter} or if the counter is misaligned for a different reason, like incorrect
* handling of terminal events by {@link BeforeFinallyHttpOperator}.
*/
final class TrackPendingRequestsHttpFilter implements StreamingHttpClientFilterFactory,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
* </ul>
*
*/
public final class TrafficResilienceHttpClientFilter extends AbstractTrafficManagementHttpFilter
public final class TrafficResilienceHttpClientFilter extends AbstractTrafficResilienceHttpFilter
implements StreamingHttpClientFilterFactory {

private static final RequestDroppedException LOCAL_REJECTION_RETRYABLE_EXCEPTION = unknownStackTrace(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
* </ul>
*
*/
public final class TrafficResilienceHttpServiceFilter extends AbstractTrafficManagementHttpFilter
public final class TrafficResilienceHttpServiceFilter extends AbstractTrafficResilienceHttpFilter
implements StreamingHttpServiceFilterFactory {

private final ServiceRejectionPolicy serviceRejectionPolicy;
Expand Down

0 comments on commit b757ba2

Please sign in to comment.