Skip to content

Commit 93c5a73

Browse files
committed
Make outliers fail gradually and restore test coverage
1 parent d093a45 commit 93c5a73

2 files changed

Lines changed: 16 additions & 6 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -834,8 +834,8 @@ public void ejectOutliers(EndpointTrackerMap trackerMap, long ejectionTimeNanos)
834834
return;
835835
}
836836

837-
// If success rate is zero or below the threshold, eject the address.
838-
if (tracker.inactiveSuccessCount() == 0L || tracker.successRate() < requiredSuccessRate) {
837+
// If success rate is below the threshold or is zero, eject the address.
838+
if (tracker.successRate() < requiredSuccessRate || tracker.inactiveSuccessCount() == 0L) {
839839
logger.log(ChannelLogLevel.DEBUG,
840840
"SuccessRate algorithm detected outlier: {0}. "
841841
+ "Parameters: successRate={1}, mean={2}, stdev={3}, "

util/src/test/java/io/grpc/util/OutlierDetectionLoadBalancerTest.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -725,10 +725,10 @@ public void successRateTwoOutliers() {
725725
}
726726

727727
/**
728-
* Two outliers get ejected with default stdevFactor.
728+
* One then two outliers get ejected with default stdevFactor.
729729
*/
730730
@Test
731-
public void successRateTwoOutliersWithDefaultStdevFactor() {
731+
public void successRateOneThenTwoOutliersWithDefaultStdevFactor() {
732732
OutlierDetectionLoadBalancerConfig config = new OutlierDetectionLoadBalancerConfig.Builder()
733733
.setMaxEjectionPercent(50)
734734
.setSuccessRateEjection(
@@ -741,14 +741,24 @@ public void successRateTwoOutliersWithDefaultStdevFactor() {
741741

742742
loadBalancer.acceptResolvedAddresses(buildResolvedAddress(config, servers));
743743

744+
// One endpoint is failing
745+
generateLoad(ImmutableMap.of(subchannel1, Status.DEADLINE_EXCEEDED), 7);
746+
747+
// Move forward in time to a point where the detection timer has fired.
748+
forwardTime(config);
749+
750+
// The one subchannel that was returning errors should be ejected.
751+
assertEjectedSubchannels(ImmutableSet.of(ImmutableSet.of(servers.get(0).getAddresses().get(0))));
752+
753+
// Two endpoints are failing
744754
generateLoad(ImmutableMap.of(
745755
subchannel1, Status.DEADLINE_EXCEEDED,
746-
subchannel2, Status.DEADLINE_EXCEEDED), 7);
756+
subchannel2, Status.DEADLINE_EXCEEDED), 12);
747757

748758
// Move forward in time to a point where the detection timer has fired.
749759
forwardTime(config);
750760

751-
// The one subchannel that was returning errors should be ejected.
761+
// Both subchannels that were returning errors should be ejected.
752762
assertEjectedSubchannels(ImmutableSet.of(ImmutableSet.of(servers.get(0).getAddresses().get(0)),
753763
ImmutableSet.of(servers.get(1).getAddresses().get(0))));
754764
}

0 commit comments

Comments
 (0)