mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(elbv2): pass TCP health checks on an open connection (#9032)
A target group with a TCP health check was probed with an HTTP GET and judged on the response code, so a target that accepts connections but does not answer HTTP stayed unhealthy. A TCP check now opens a connection to the target and passes once it is accepted, without consulting the path or matcher, which AWS scopes to HTTP and HTTPS checks. The ELB docs describe the TCP check. Closes #9031
This commit is contained in:
1 parent
4713120f3e
commit
3ae5b8b6ea
3 files changed
+71
-7
No files matched your search
@@ -13,11 +13,15 @@ import io.vertx.core.VertxOptions;
|
||||
import io.vertx.core.WorkerExecutor;
|
||||
import io.vertx.core.http.HttpServer;
|
||||
import io.vertx.core.http.HttpServerResponse;
|
||||
import io.vertx.core.net.NetServer;
|
||||
import io.vertx.core.net.NetSocket;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.CsvSource;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.ServerSocket;
|
||||
import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -113,6 +117,44 @@ class ElbV2HealthCheckerTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void tcpCheckPassesOnAnOpenConnectionWithoutSpeakingHttp() throws Exception {
|
||||
NetServer server = vertx.createNetServer().connectHandler(NetSocket::close)
|
||||
.listen(0, "127.0.0.1").toCompletionStage().toCompletableFuture().get(2, TimeUnit.SECONDS);
|
||||
try {
|
||||
ElbV2HealthChecker checker = healthChecker();
|
||||
TargetGroup targetGroup = tcpTargetGroup(server.actualPort());
|
||||
TargetDescription target = target("127.0.0.1", server.actualPort());
|
||||
|
||||
checker.addTargets(targetGroup.getTargetGroupArn(), List.of(target), targetGroup);
|
||||
|
||||
await().atMost(Duration.ofSeconds(2)).untilAsserted(() -> assertEquals("healthy",
|
||||
checker.getHealth(targetGroup.getTargetGroupArn(), target.getId(), target.getPort()).state()));
|
||||
} finally {
|
||||
server.close().toCompletionStage().toCompletableFuture().get(2, TimeUnit.SECONDS);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void tcpCheckFailsWhenTheConnectionIsRefused() throws Exception {
|
||||
int closedPort;
|
||||
try (ServerSocket socket = new ServerSocket(0, 1, InetAddress.getLoopbackAddress())) {
|
||||
closedPort = socket.getLocalPort();
|
||||
}
|
||||
ElbV2HealthChecker checker = healthChecker();
|
||||
TargetGroup targetGroup = tcpTargetGroup(closedPort);
|
||||
TargetDescription target = target("127.0.0.1", closedPort);
|
||||
|
||||
checker.addTargets(targetGroup.getTargetGroupArn(), List.of(target), targetGroup);
|
||||
|
||||
await().atMost(Duration.ofSeconds(2)).untilAsserted(() -> {
|
||||
ElbV2HealthChecker.TargetHealthStatus health = checker.getHealth(
|
||||
targetGroup.getTargetGroupArn(), target.getId(), target.getPort());
|
||||
assertEquals("unhealthy", health.state());
|
||||
assertEquals("Target.FailedHealthChecks", health.reason());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void responseCodeMismatchTransitionsTargetToUnhealthyWithAwsReason() throws Exception {
|
||||
HttpServer server = startServer(503);
|
||||
@@ -523,6 +565,13 @@ class ElbV2HealthCheckerTest {
|
||||
return targetGroup;
|
||||
}
|
||||
|
||||
private static TargetGroup tcpTargetGroup(int port) {
|
||||
TargetGroup targetGroup = targetGroup(port, "200", 1, 1);
|
||||
targetGroup.setProtocol("TCP");
|
||||
targetGroup.setHealthCheckProtocol("TCP");
|
||||
return targetGroup;
|
||||
}
|
||||
|
||||
private static TargetDescription target(String id, int port) {
|
||||
TargetDescription target = new TargetDescription();
|
||||
target.setId(id);
|
||||
|
||||
Reference in new issue
Block a user