Skip to content

Commit bf90eb5

Browse files
committed
util: exclude client cancellations and deadline exceeded from outlier detection call counter
1 parent 20682d9 commit bf90eb5

3 files changed

Lines changed: 124 additions & 60 deletions

File tree

core/src/main/java/io/grpc/internal/AbstractClientStream.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,11 @@ public final void halfClose() {
197197
@Override
198198
public final void cancel(Status reason) {
199199
Preconditions.checkArgument(!reason.isOk(), "Should not cancel with OK status");
200+
if (cancelled || transportState().isListenerClosed()) {
201+
return;
202+
}
200203
cancelled = true;
204+
transportState().getStatsTraceContext().clientCancelled(reason);
201205
abstractClientStreamSink().cancel(reason);
202206
}
203207

@@ -251,6 +255,10 @@ protected TransportState(
251255
}
252256
}
253257

258+
protected final boolean isListenerClosed() {
259+
return listenerClosed;
260+
}
261+
254262
private void setFullStreamDecompression(boolean fullStreamDecompression) {
255263
this.fullStreamDecompression = fullStreamDecompression;
256264
}
@@ -457,9 +465,6 @@ private void closeListener(
457465
Status status, RpcProgress rpcProgress, Metadata trailers) {
458466
if (!listenerClosed) {
459467
listenerClosed = true;
460-
if (status.getCode() == Status.Code.CANCELLED) {
461-
statsTraceCtx.clientCancelled(status);
462-
}
463468
statsTraceCtx.streamClosed(status);
464469
if (getTransportTracer() != null) {
465470
getTransportTracer().reportStreamClosed(status.isOk());

util/src/main/java/io/grpc/util/OutlierDetectionLoadBalancer.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ public void cancelled(Status status) {
493493
@Override
494494
public void streamClosed(Status status) {
495495
if (!cancelled) {
496-
tracker.incrementCallCount(status.isOk());
496+
tracker.incrementCallCount(status);
497497
}
498498
delegate().streamClosed(status);
499499
}
@@ -510,7 +510,7 @@ public void cancelled(Status status) {
510510
@Override
511511
public void streamClosed(Status status) {
512512
if (!cancelled) {
513-
tracker.incrementCallCount(status.isOk());
513+
tracker.incrementCallCount(status);
514514
}
515515
}
516516
};
@@ -571,13 +571,13 @@ Set<OutlierDetectionSubchannel> getSubchannels() {
571571
return ImmutableSet.copyOf(subchannels);
572572
}
573573

574-
void incrementCallCount(boolean success) {
574+
void incrementCallCount(Status status) {
575575
// If neither algorithm is configured, no point in incrementing counters.
576576
if (config.successRateEjection == null && config.failurePercentageEjection == null) {
577577
return;
578578
}
579579

580-
if (success) {
580+
if (status.isOk()) {
581581
activeCallCounter.successCount.getAndIncrement();
582582
} else {
583583
activeCallCounter.failureCount.getAndIncrement();

0 commit comments

Comments
 (0)