mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(route53): return the health check on a CreateHealthCheck retry (#5298)
* fix(route53): return the health check on a CreateHealthCheck retry CreateHealthCheck refused any CallerReference already in use with HealthCheckAlreadyExists. AWS treats the same reference with the same settings as a retry and returns the health check it already created; only different settings are refused. The Go SDK resends the same input after a transient failure, so a Terraform or OpenTofu apply failed on Floci where it succeeds on AWS. A matching retry now returns the existing health check, and the docs note that a deleted health check's reference is reusable at once here, while AWS keeps refusing it. * fix(route53): compare a CreateHealthCheck retry on every setting it sends The retry check compared only the seven HealthCheckConfig fields Floci models, so two requests that differed in an unmodelled setting such as EnableSNI passed as a retry, and a retry stating RequestInterval or FailureThreshold at its default was refused as different from one that omitted it. The controller now records the request's settings in a canonical form, every value under HealthCheckConfig sorted (Regions and ChildHealthChecks are sets), with an omitted RequestInterval or FailureThreshold counted as AWS's default of 30 or 3 except for RECOVERY_CONTROL, and a retry must match it. A non-numeric Port, RequestInterval or FailureThreshold is now InvalidInput instead of being dropped. * refactor(route53): read the health check settings with XmlParser.extractElementTree
This commit is contained in:
1 parent
4927f71ce1
commit
0d4b8cda74
7 files changed
+249
-16
No files matched your search
+62
@@ -0,0 +1,62 @@
|
||||
package io.github.hectorvent.floci.services.route53;
|
||||
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
class Route53HealthCheckSettingsTest {
|
||||
|
||||
private static String request(String config) {
|
||||
return """
|
||||
<CreateHealthCheckRequest xmlns="https://route53.amazonaws.com/doc/2013-04-01/">
|
||||
<CallerReference>ref</CallerReference>
|
||||
<HealthCheckConfig>%s</HealthCheckConfig>
|
||||
</CreateHealthCheckRequest>
|
||||
""".formatted(config);
|
||||
}
|
||||
|
||||
private static String settings(String config) {
|
||||
return Route53Controller.healthCheckSettings(request(config));
|
||||
}
|
||||
|
||||
// Catches: a retry that states RequestInterval or FailureThreshold at its default refused as a
|
||||
// different request from one that omitted them.
|
||||
@Test
|
||||
void omittedIntervalAndThresholdEqualTheirDefaults() {
|
||||
assertEquals(settings("<Type>HTTP</Type><IPAddress>10.0.0.1</IPAddress>"),
|
||||
settings("<Type>HTTP</Type><IPAddress>10.0.0.1</IPAddress>"
|
||||
+ "<RequestInterval>30</RequestInterval><FailureThreshold>3</FailureThreshold>"));
|
||||
assertNotEquals(settings("<Type>HTTP</Type><IPAddress>10.0.0.1</IPAddress>"),
|
||||
settings("<Type>HTTP</Type><IPAddress>10.0.0.1</IPAddress><RequestInterval>10</RequestInterval>"));
|
||||
}
|
||||
|
||||
// Catches: requests that differ only in a setting Floci does not model passing as a retry.
|
||||
@Test
|
||||
void settingsFlociDoesNotModelStillCount() {
|
||||
assertNotEquals(settings("<Type>HTTPS</Type><FullyQualifiedDomainName>example.com</FullyQualifiedDomainName>"),
|
||||
settings("<Type>HTTPS</Type><FullyQualifiedDomainName>example.com</FullyQualifiedDomainName>"
|
||||
+ "<EnableSNI>false</EnableSNI>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void regionsAreASet() {
|
||||
assertEquals(settings("<Type>HTTP</Type><Regions><Region>us-east-1</Region><Region>eu-west-1</Region></Regions>"),
|
||||
settings("<Type>HTTP</Type><Regions><Region>eu-west-1</Region><Region>us-east-1</Region></Regions>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void recoveryControlGetsNoIntervalOrThresholdDefaults() {
|
||||
assertEquals("RoutingControlArn=arn\nType=RECOVERY_CONTROL",
|
||||
settings("<Type>RECOVERY_CONTROL</Type><RoutingControlArn>arn</RoutingControlArn>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void malformedXmlIsInvalidInput() {
|
||||
AwsException e = assertThrows(AwsException.class,
|
||||
() -> Route53Controller.healthCheckSettings("<CreateHealthCheckRequest><HealthCheckConfig>"));
|
||||
assertEquals("InvalidInput", e.getErrorCode());
|
||||
}
|
||||
}
|
||||
@@ -387,6 +387,81 @@ class Route53IntegrationTest {
|
||||
|
||||
// ── Health Checks ─────────────────────────────────────────────────────────
|
||||
|
||||
private static String healthCheckRequest(String callerReference, String resourcePath) {
|
||||
return """
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<CreateHealthCheckRequest xmlns="https://route53.amazonaws.com/doc/2013-04-01/">
|
||||
<CallerReference>%s</CallerReference>
|
||||
<HealthCheckConfig>
|
||||
<Type>HTTPS</Type>
|
||||
<FullyQualifiedDomainName>example.com</FullyQualifiedDomainName>
|
||||
<Port>443</Port>
|
||||
<ResourcePath>%s</ResourcePath>
|
||||
<RequestInterval>30</RequestInterval>
|
||||
<FailureThreshold>3</FailureThreshold>
|
||||
</HealthCheckConfig>
|
||||
</CreateHealthCheckRequest>
|
||||
""".formatted(callerReference, resourcePath);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(26)
|
||||
void createHealthCheck_nonNumericFailureThreshold_isInvalidInput() {
|
||||
given()
|
||||
.contentType(XML)
|
||||
.body(healthCheckRequest("hc-bad-" + System.nanoTime(), "/health")
|
||||
.replace("<FailureThreshold>3</FailureThreshold>", "<FailureThreshold>three</FailureThreshold>"))
|
||||
.when().post("/2013-04-01/healthcheck")
|
||||
.then().statusCode(400)
|
||||
.body("ErrorResponse.Error.Code", equalTo("InvalidInput"));
|
||||
}
|
||||
|
||||
// Catches: an SDK retry of CreateHealthCheck (same caller reference and settings) answered with
|
||||
// HealthCheckAlreadyExists instead of the health check it already created.
|
||||
@Test
|
||||
@Order(25)
|
||||
void createHealthCheck_retryWithSameReferenceAndSettings_returnsTheSameHealthCheck() {
|
||||
String reference = "hc-retry-" + System.nanoTime();
|
||||
String firstId = given()
|
||||
.contentType(XML).body(healthCheckRequest(reference, "/health"))
|
||||
.when().post("/2013-04-01/healthcheck")
|
||||
.then().statusCode(201)
|
||||
.extract().path("CreateHealthCheckResponse.HealthCheck.Id");
|
||||
try {
|
||||
given()
|
||||
.contentType(XML).body(healthCheckRequest(reference, "/health"))
|
||||
.when().post("/2013-04-01/healthcheck")
|
||||
.then().statusCode(201)
|
||||
.body("CreateHealthCheckResponse.HealthCheck.Id", equalTo(firstId));
|
||||
|
||||
given()
|
||||
.contentType(XML).body(healthCheckRequest(reference, "/other"))
|
||||
.when().post("/2013-04-01/healthcheck")
|
||||
.then().statusCode(409)
|
||||
.body("ErrorResponse.Error.Code", equalTo("HealthCheckAlreadyExists"));
|
||||
|
||||
given()
|
||||
.contentType(XML)
|
||||
.body(healthCheckRequest(reference, "/health")
|
||||
.replace("<FailureThreshold>3</FailureThreshold>",
|
||||
"<FailureThreshold>3</FailureThreshold><EnableSNI>false</EnableSNI>"))
|
||||
.when().post("/2013-04-01/healthcheck")
|
||||
.then().statusCode(409)
|
||||
.body("ErrorResponse.Error.Code", equalTo("HealthCheckAlreadyExists"));
|
||||
|
||||
given()
|
||||
.contentType(XML)
|
||||
.body(healthCheckRequest(reference, "/health")
|
||||
.replace("<RequestInterval>30</RequestInterval>", "")
|
||||
.replace("<FailureThreshold>3</FailureThreshold>", ""))
|
||||
.when().post("/2013-04-01/healthcheck")
|
||||
.then().statusCode(201)
|
||||
.body("CreateHealthCheckResponse.HealthCheck.Id", equalTo(firstId));
|
||||
} finally {
|
||||
given().when().delete("/2013-04-01/healthcheck/" + firstId).then().statusCode(200);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(16)
|
||||
void createHealthCheck_returns201() {
|
||||
|
||||
@@ -7,6 +7,8 @@ import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
import io.github.hectorvent.floci.services.ec2.Ec2Service;
|
||||
import io.github.hectorvent.floci.services.route53.model.AliasTarget;
|
||||
import io.github.hectorvent.floci.services.route53.model.HealthCheck;
|
||||
import io.github.hectorvent.floci.services.route53.model.HealthCheckConfig;
|
||||
import io.github.hectorvent.floci.services.route53.model.ResourceRecord;
|
||||
import io.github.hectorvent.floci.services.route53.model.ResourceRecordSet;
|
||||
import io.github.hectorvent.floci.services.route53.model.VpcAssociation;
|
||||
@@ -365,4 +367,40 @@ class Route53ServiceTest {
|
||||
assertFalse(service.isCoveredByPrivateZone("othercorp.internal"));
|
||||
assertFalse(service.isCoveredByPrivateZone("example.org"));
|
||||
}
|
||||
|
||||
private static HealthCheckConfig httpsCheck(String path) {
|
||||
HealthCheckConfig cfg = new HealthCheckConfig();
|
||||
cfg.setType("HTTPS");
|
||||
cfg.setFullyQualifiedDomainName("example.com");
|
||||
cfg.setPort(443);
|
||||
cfg.setResourcePath(path);
|
||||
cfg.setRequestInterval(30);
|
||||
cfg.setFailureThreshold(3);
|
||||
return cfg;
|
||||
}
|
||||
|
||||
// Catches: an SDK retry of CreateHealthCheck (same caller reference, same settings) refused with
|
||||
// HealthCheckAlreadyExists, which fails a Terraform or OpenTofu apply.
|
||||
@Test
|
||||
void createHealthCheck_retryWithSameReferenceAndSettings_returnsTheExistingHealthCheck() {
|
||||
Route53Service service = newService();
|
||||
HealthCheck first = service.createHealthCheck("tf-ref-1", httpsCheck("/health"), "ResourcePath=/health");
|
||||
|
||||
HealthCheck retried = service.createHealthCheck("tf-ref-1", httpsCheck("/health"), "ResourcePath=/health");
|
||||
|
||||
assertEquals(first.getId(), retried.getId());
|
||||
assertThat(service.listHealthChecks(null, 0), hasSize(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createHealthCheck_sameReferenceWithDifferentSettings_isHealthCheckAlreadyExists() {
|
||||
Route53Service service = newService();
|
||||
service.createHealthCheck("tf-ref-2", httpsCheck("/health"), "ResourcePath=/health");
|
||||
|
||||
AwsException e = assertThrows(AwsException.class,
|
||||
() -> service.createHealthCheck("tf-ref-2", httpsCheck("/other"), "ResourcePath=/other"));
|
||||
|
||||
assertEquals("HealthCheckAlreadyExists", e.getErrorCode());
|
||||
assertEquals(409, e.getHttpStatus());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user