mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(elbv2): omit HTTP-only fields from TCP target groups (#9030)
This commit is contained in:
1 parent
9f959a3f27
commit
f08cc57437
3 files changed
+61
-4
No files matched your search
@@ -216,7 +216,8 @@ For non-Lambda targets, the checker sends an HTTP or HTTPS GET to `HealthCheckPa
|
||||
on `HealthCheckPort`, or the target's traffic port when configured as `traffic-port`.
|
||||
`HealthCheckProtocol` selects TLS independently of the target's application protocol.
|
||||
The response-code matcher and healthy/unhealthy thresholds affect target health.
|
||||
`HealthCheckProtocol=TCP` does not perform a TCP-only probe.
|
||||
`HealthCheckProtocol=TCP` does not perform a TCP-only probe: it sends the same GET with the
|
||||
stored path and matcher, which `DescribeTargetGroups` omits for TCP checks, as AWS does.
|
||||
Lambda targets are not actively probed. In ELBv2 mock mode, sockets
|
||||
and active monitoring are disabled. While a target group has a `healthy` target, the
|
||||
proxy routes only to its `healthy` targets, so a newly registered target in `initial`
|
||||
|
||||
@@ -860,7 +860,9 @@ public class ElbV2QueryHandler {
|
||||
xml.elem("TargetGroupArn", tg.getTargetGroupArn());
|
||||
xml.elem("TargetGroupName", tg.getTargetGroupName());
|
||||
xml.elem("Protocol", safe(tg.getProtocol()));
|
||||
xml.elem("ProtocolVersion", safe(tg.getProtocolVersion()));
|
||||
if (isHttpProtocol(tg.getProtocol())) {
|
||||
xml.elem("ProtocolVersion", safe(tg.getProtocolVersion()));
|
||||
}
|
||||
if (tg.getPort() != null) xml.elem("Port", String.valueOf(tg.getPort()));
|
||||
xml.elem("VpcId", safe(tg.getVpcId()));
|
||||
xml.elem("HealthCheckProtocol", safe(tg.getHealthCheckProtocol()));
|
||||
@@ -870,8 +872,10 @@ public class ElbV2QueryHandler {
|
||||
if (tg.getHealthCheckTimeoutSeconds() != null) xml.elem("HealthCheckTimeoutSeconds", String.valueOf(tg.getHealthCheckTimeoutSeconds()));
|
||||
if (tg.getHealthyThresholdCount() != null) xml.elem("HealthyThresholdCount", String.valueOf(tg.getHealthyThresholdCount()));
|
||||
if (tg.getUnhealthyThresholdCount() != null) xml.elem("UnhealthyThresholdCount", String.valueOf(tg.getUnhealthyThresholdCount()));
|
||||
xml.elem("HealthCheckPath", safe(tg.getHealthCheckPath()));
|
||||
xml.start("Matcher").elem("HttpCode", safe(tg.getMatcher())).end("Matcher");
|
||||
if (isHttpProtocol(tg.getHealthCheckProtocol())) {
|
||||
xml.elem("HealthCheckPath", safe(tg.getHealthCheckPath()));
|
||||
xml.start("Matcher").elem("HttpCode", safe(tg.getMatcher())).end("Matcher");
|
||||
}
|
||||
xml.start("LoadBalancerArns");
|
||||
for (String lbArn : tg.getLoadBalancerArns()) {
|
||||
xml.start("member").raw(lbArn).end("member");
|
||||
@@ -882,6 +886,10 @@ public class ElbV2QueryHandler {
|
||||
return xml.build();
|
||||
}
|
||||
|
||||
private static boolean isHttpProtocol(String protocol) {
|
||||
return "HTTP".equals(protocol) || "HTTPS".equals(protocol);
|
||||
}
|
||||
|
||||
private String listenerXml(Listener l) {
|
||||
XmlBuilder xml = new XmlBuilder();
|
||||
xml.elem("ListenerArn", l.getListenerArn());
|
||||
|
||||
+48
@@ -6,12 +6,15 @@ import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.function.Executable;
|
||||
import software.amazon.awssdk.regions.Region;
|
||||
import software.amazon.awssdk.services.acm.AcmClient;
|
||||
import software.amazon.awssdk.services.elasticloadbalancingv2.ElasticLoadBalancingV2Client;
|
||||
import software.amazon.awssdk.services.elasticloadbalancingv2.model.Certificate;
|
||||
import software.amazon.awssdk.services.elasticloadbalancingv2.model.Listener;
|
||||
import software.amazon.awssdk.services.elasticloadbalancingv2.model.TargetGroup;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
@@ -20,6 +23,7 @@ import static io.floci.aws.testing.QueryRequests.request;
|
||||
import static org.junit.jupiter.api.Assertions.assertAll;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@@ -34,6 +38,7 @@ class ElbV2OptionalResponseFieldsIntegrationTest {
|
||||
private String loadBalancer;
|
||||
private String targetGroup;
|
||||
private String certificate;
|
||||
private final List<String> createdTargetGroups = new ArrayList<>();
|
||||
|
||||
@BeforeEach
|
||||
void createResources() {
|
||||
@@ -64,6 +69,8 @@ class ElbV2OptionalResponseFieldsIntegrationTest {
|
||||
ownedElb.deleteTargetGroup(request -> request.targetGroupArn(targetGroup));
|
||||
}
|
||||
},
|
||||
() -> assertAll(createdTargetGroups.stream().map(arn -> (Executable) () ->
|
||||
ownedElb.deleteTargetGroup(request -> request.targetGroupArn(arn)))),
|
||||
() -> {
|
||||
if (certificate != null) {
|
||||
ownedAcm.deleteCertificate(request -> request.certificateArn(certificate));
|
||||
@@ -193,6 +200,47 @@ class ElbV2OptionalResponseFieldsIntegrationTest {
|
||||
() -> assertTerminalXml("DescribeListenerCertificates", Map.of("ListenerArn", listener)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void tcpTargetGroupsOmitFieldsOnlyHttpUses() {
|
||||
String tcp = createTargetGroup("optional-tcp", "TCP", "TCP");
|
||||
String tcpWithHttpCheck = createTargetGroup("optional-tcp-http", "TCP", "HTTP");
|
||||
String http = createTargetGroup("optional-http", "HTTP", null);
|
||||
TargetGroup tcpGroup = describeTargetGroup(tcp);
|
||||
TargetGroup tcpWithHttpCheckGroup = describeTargetGroup(tcpWithHttpCheck);
|
||||
TargetGroup httpGroup = describeTargetGroup(http);
|
||||
assertAll(
|
||||
() -> assertNull(tcpGroup.protocolVersion()),
|
||||
() -> assertNull(tcpGroup.healthCheckPath()),
|
||||
() -> assertNull(tcpGroup.matcher()),
|
||||
() -> assertNull(tcpWithHttpCheckGroup.protocolVersion()),
|
||||
() -> assertNotNull(tcpWithHttpCheckGroup.healthCheckPath()),
|
||||
() -> assertNotNull(tcpWithHttpCheckGroup.matcher()),
|
||||
() -> assertEquals("HTTP", httpGroup.healthCheckProtocolAsString()),
|
||||
() -> assertEquals("HTTP1", httpGroup.protocolVersion()),
|
||||
() -> assertEquals("/", httpGroup.healthCheckPath()),
|
||||
() -> assertEquals("200", httpGroup.matcher().httpCode()));
|
||||
|
||||
TargetGroup switchedToHttpCheck = elb.modifyTargetGroup(request -> request.targetGroupArn(tcp)
|
||||
.healthCheckProtocol("HTTP")).targetGroups().getFirst();
|
||||
assertAll("Switching to an HTTP check returns the stored path and matcher",
|
||||
() -> assertNotNull(switchedToHttpCheck.healthCheckPath()),
|
||||
() -> assertNotNull(switchedToHttpCheck.matcher()));
|
||||
}
|
||||
|
||||
private String createTargetGroup(String prefix, String protocol, String healthCheckProtocol) {
|
||||
String arn = elb.createTargetGroup(request -> request.name(uniqueName(prefix))
|
||||
.protocol(protocol).port(2022).targetType("ip")
|
||||
.vpcId(Ec2Service.defaultVpcId(REGION.id()))
|
||||
.healthCheckProtocol(healthCheckProtocol))
|
||||
.targetGroups().getFirst().targetGroupArn();
|
||||
createdTargetGroups.add(arn);
|
||||
return arn;
|
||||
}
|
||||
|
||||
private TargetGroup describeTargetGroup(String arn) {
|
||||
return elb.describeTargetGroups(request -> request.targetGroupArns(arn)).targetGroups().getFirst();
|
||||
}
|
||||
|
||||
private Listener createListener(String protocol, int port) {
|
||||
return createListener(protocol, port, SSL_POLICY);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user