Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not transition servers into the healthy state until at least one healthy probe is detected. #2415

Merged
merged 1 commit into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/ReverseProxy/Health/ConsecutiveFailuresHealthPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ public void ProbingCompleted(ClusterState cluster, IReadOnlyList<DestinationProb
for (var i = 0; i < probingResults.Count; i++)
{
var destination = probingResults[i].Destination;
var previousState = destination.Health.Active;

var count = _failureCounters.GetOrCreateValue(destination);
var newHealth = EvaluateHealthState(threshold, probingResults[i].Response, count);
var newHealth = EvaluateHealthState(threshold, probingResults[i].Response, count, previousState);
newHealthStates[i] = new NewActiveDestinationHealth(destination, newHealth);
}

Expand All @@ -55,7 +56,7 @@ private double GetFailureThreshold(ClusterState cluster)
return thresholdEntry.GetParsedOrDefault(_options.DefaultThreshold);
}

private static DestinationHealth EvaluateHealthState(double threshold, HttpResponseMessage? response, AtomicCounter count)
private static DestinationHealth EvaluateHealthState(double threshold, HttpResponseMessage? response, AtomicCounter count, DestinationHealth previousState)
{
DestinationHealth newHealth;
if (response is not null && response.IsSuccessStatusCode)
Expand All @@ -68,7 +69,7 @@ private static DestinationHealth EvaluateHealthState(double threshold, HttpRespo
{
// Failure
var currentFailureCount = count.Increment();
newHealth = currentFailureCount < threshold ? DestinationHealth.Healthy : DestinationHealth.Unhealthy;
newHealth = currentFailureCount < threshold ? previousState : DestinationHealth.Unhealthy;
}

return newHealth;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public void ProbingCompleted_FailureThresholdExceeded_MarkDestinationUnhealthy()
var options = Options.Create(new ConsecutiveFailuresHealthPolicyOptions { DefaultThreshold = 2 });
var policy = new ConsecutiveFailuresHealthPolicy(options, new DestinationHealthUpdaterStub());
var cluster0 = GetClusterInfo("cluster0", destinationCount: 2);
var cluster1 = GetClusterInfo("cluster0", destinationCount: 2, failureThreshold: 3);
var cluster1 = GetClusterInfo("cluster1", destinationCount: 2, failureThreshold: 3);

var probingResults0 = new[] {
new DestinationProbingResult(cluster0.Destinations.Values.First(), new HttpResponseMessage(HttpStatusCode.InternalServerError), null),
Expand All @@ -40,16 +40,19 @@ public void ProbingCompleted_FailureThresholdExceeded_MarkDestinationUnhealthy()

// First probing attempt
policy.ProbingCompleted(cluster0, probingResults0);
Assert.All(cluster0.Destinations.Values, d => Assert.Equal(DestinationHealth.Healthy, d.Health.Active));
Assert.Equal(DestinationHealth.Unknown, cluster0.Destinations.Values.First().Health.Active);
Assert.Equal(DestinationHealth.Healthy, cluster0.Destinations.Values.Skip(1).First().Health.Active);
policy.ProbingCompleted(cluster1, probingResults1);
Assert.All(cluster1.Destinations.Values, d => Assert.Equal(DestinationHealth.Healthy, d.Health.Active));
Assert.Equal(DestinationHealth.Healthy, cluster1.Destinations.Values.First().Health.Active);
Assert.Equal(DestinationHealth.Unknown, cluster1.Destinations.Values.Skip(1).First().Health.Active);

// Second probing attempt
policy.ProbingCompleted(cluster0, probingResults0);
Assert.Equal(DestinationHealth.Unhealthy, cluster0.Destinations.Values.First().Health.Active);
Assert.Equal(DestinationHealth.Healthy, cluster0.Destinations.Values.Skip(1).First().Health.Active);
policy.ProbingCompleted(cluster1, probingResults1);
Assert.All(cluster1.Destinations.Values, d => Assert.Equal(DestinationHealth.Healthy, d.Health.Active));
Assert.Equal(DestinationHealth.Healthy, cluster1.Destinations.Values.First().Health.Active);
Assert.Equal(DestinationHealth.Unknown, cluster1.Destinations.Values.Skip(1).First().Health.Active);

// Third probing attempt
policy.ProbingCompleted(cluster0, probingResults0);
Expand Down
Loading