Skip to content

Commit

Permalink
loadbalancer-experimental: include reason DefaultHost is unhealthy (#…
Browse files Browse the repository at this point in the history
…3143)

Motivation:

We store the reason that a host enters the unhealthy/healthchecking
state but we never use it.

Modifications:

- Include that info when we're creating the DefaultHost.toString().
- Add a useful .toString() for XdsHealthIndicator
  • Loading branch information
bryce-anderson authored Dec 18, 2024
1 parent ad2bbbb commit d9f375a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -456,10 +456,13 @@ public int score() {
@Override
public String toString() {
final ConnState connState = this.connState;
return "Host{" +
String stateString = connState.isUnhealthy() ? State.UNHEALTHY + "(" + connState.healthCheck + ")" :
connState.state.toString();
return "DefaultHost{" +
"lbDescription=" + lbDescription +
", address=" + address +
", state=" + connState.state +
", state=" + stateString +
", healthIndicator=" + healthIndicator +
", #connections=" + connState.connections.size() +
'}';
}
Expand Down Expand Up @@ -514,7 +517,7 @@ public void schedule(final Throwable originalCause) {

@Override
public String toString() {
return "UNHEALTHY(" + lastError + ')';
return "HealthCheck(" + lastError + ')';
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,16 @@ public final void cancel() {
sequentialExecutor.execute(this::sequentialCancel);
}

@Override
public String toString() {
return "XdsHealthIndicator{" +
", consecutive5xx=" + consecutive5xx.get() +
", successes=" + successes.get() +
", failures=" + failures.get() +
", evictedUntilNanos=" + evictedUntilNanos +
'}';
}

void sequentialCancel() {
assert sequentialExecutor.isCurrentThreadDraining();
if (cancelled) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import static io.servicetalk.loadbalancer.HealthCheckConfig.DEFAULT_HEALTH_CHECK_FAILED_CONNECTIONS_THRESHOLD;
import static io.servicetalk.loadbalancer.UnhealthyHostConnectionFactory.UNHEALTHY_HOST_EXCEPTION;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
Expand Down Expand Up @@ -182,6 +183,9 @@ void hostStatus() throws Exception {
assertThrows(ExecutionException.class,
() -> host.newConnection(any(), false, null).toFuture().get());
}
assertThat(host.toString(), containsString("UNHEALTHY"));
assertThat(host.toString(), containsString("DeliberateException"));

verify(mockHostObserver, times(1)).onHostMarkedUnhealthy(UNHEALTHY_HOST_EXCEPTION);
assertThat(host.isHealthy(), is(false));
assertThat(host.canMakeNewConnections(), is(true));
Expand Down

0 comments on commit d9f375a

Please sign in to comment.