mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(rds): model Aurora Serverless v2 scaling configuration on DB clusters (#1829)
* feat(rds): model Aurora Serverless v2 scaling configuration * test(dynamodb): retain Quarkus port for cleanup
This commit is contained in:
1 parent
bc13801121
commit
d778a6e393
11 files changed
+669
-29
No files matched your search
+47
-2
@@ -199,6 +199,49 @@ class RdsCfnProvisionerTest {
|
||||
null, null, null, false, null, null, null, false, "us-west-2");
|
||||
}
|
||||
|
||||
@Test
|
||||
void provisionsDbClusterWithServerlessV2Scaling() {
|
||||
DbCluster cluster = mock(DbCluster.class);
|
||||
when(cluster.getDbClusterIdentifier()).thenReturn("mycluster");
|
||||
when(rdsService.createDbCluster(any(), any(), any(), any(), any(), any(), anyBoolean(), any(),
|
||||
any(), any(), anyBoolean(), any(), any(), any(), any()))
|
||||
.thenReturn(cluster);
|
||||
|
||||
provision("Cluster", "AWS::RDS::DBCluster", """
|
||||
{"DBClusterIdentifier":"mycluster","Engine":"aurora-postgresql",
|
||||
"ServerlessV2ScalingConfiguration":{
|
||||
"MinCapacity":0,"MaxCapacity":16,"SecondsUntilAutoPause":600}}
|
||||
""");
|
||||
|
||||
verify(rdsService).createDbCluster("mycluster", "aurora-postgresql", null,
|
||||
null, null, null, false, null, null, null, false, "us-east-1",
|
||||
0.0, 16.0, 600);
|
||||
}
|
||||
|
||||
@Test
|
||||
void rejectsNonNumericServerlessV2Capacity() {
|
||||
// A non-numeric capacity is invalid input, not an absent value: the stack fails rather than
|
||||
// silently dropping the scaling configuration.
|
||||
StackResource r = provision("Cluster", "AWS::RDS::DBCluster", """
|
||||
{"DBClusterIdentifier":"mycluster","Engine":"aurora-postgresql",
|
||||
"ServerlessV2ScalingConfiguration":{"MinCapacity":"abc","MaxCapacity":16}}
|
||||
""");
|
||||
assertEquals("CREATE_FAILED", r.getStatus());
|
||||
assertTrue(r.getStatusReason().contains("MinCapacity"), r.getStatusReason());
|
||||
}
|
||||
|
||||
@Test
|
||||
void rejectsNonIntegerServerlessV2AutoPauseInterval() {
|
||||
StackResource r = provision("Cluster", "AWS::RDS::DBCluster", """
|
||||
{"DBClusterIdentifier":"mycluster","Engine":"aurora-postgresql",
|
||||
"ServerlessV2ScalingConfiguration":{
|
||||
"MinCapacity":0,"MaxCapacity":16,"SecondsUntilAutoPause":"300.5"}}
|
||||
""");
|
||||
|
||||
assertEquals("CREATE_FAILED", r.getStatus());
|
||||
assertTrue(r.getStatusReason().contains("SecondsUntilAutoPause"), r.getStatusReason());
|
||||
}
|
||||
|
||||
@Test
|
||||
void resolvesSecretsManagerDynamicReferencesInDbClusterCredentials() {
|
||||
SecretVersion version = mock(SecretVersion.class);
|
||||
@@ -1100,7 +1143,8 @@ class RdsCfnProvisionerTest {
|
||||
when(rdsService.getDbCluster("mycluster")).thenReturn(existing);
|
||||
DbCluster reconciled = mock(DbCluster.class);
|
||||
when(reconciled.getDbClusterIdentifier()).thenReturn("mycluster");
|
||||
when(rdsService.modifyDbCluster(eq("mycluster"), any(), anyBoolean())).thenReturn(reconciled);
|
||||
when(rdsService.modifyDbCluster(eq("mycluster"), any(), anyBoolean(),
|
||||
any(), any(), any(), eq("us-east-1"))).thenReturn(reconciled);
|
||||
|
||||
StackResource r = provisionUpdate("Cluster", "AWS::RDS::DBCluster", """
|
||||
{"DBClusterIdentifier":"mycluster","Engine":"aurora-postgresql",
|
||||
@@ -1110,7 +1154,8 @@ class RdsCfnProvisionerTest {
|
||||
assertEquals("mycluster", r.getPhysicalId());
|
||||
verify(rdsService, never()).createDbCluster(any(), any(), any(), any(), any(), any(),
|
||||
anyBoolean(), any(), any(), any(), anyBoolean(), any());
|
||||
verify(rdsService).modifyDbCluster("mycluster", "secret", false);
|
||||
verify(rdsService).modifyDbCluster("mycluster", "secret", false,
|
||||
null, null, null, "us-east-1");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+3
-5
@@ -252,9 +252,7 @@ class SharedClusterIdentifierIntegrationTest {
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
// Floci reports the aurora-postgresql request as its postgres engine; what matters
|
||||
// here is that RDS answered at all rather than DocumentDB refusing it as existing.
|
||||
.body(containsString("<Engine>postgres</Engine>"));
|
||||
.body(containsString("<Engine>aurora-postgresql</Engine>"));
|
||||
|
||||
// And each region's describe answers from the service that owns the record there.
|
||||
queryIn("us-east-1", "DescribeDBClusters")
|
||||
@@ -262,7 +260,7 @@ class SharedClusterIdentifierIntegrationTest {
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<Engine>postgres</Engine>"))
|
||||
.body(containsString("<Engine>aurora-postgresql</Engine>"))
|
||||
.body(not(containsString("docdb")));
|
||||
|
||||
queryIn("eu-west-1", "DescribeDBClusters")
|
||||
@@ -309,7 +307,7 @@ class SharedClusterIdentifierIntegrationTest {
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<Engine>postgres</Engine>"));
|
||||
.body(containsString("<Engine>aurora-postgresql</Engine>"));
|
||||
|
||||
rdsService.deleteDbCluster(id, "us-east-1");
|
||||
}
|
||||
|
||||
@@ -215,7 +215,8 @@ class RdsQueryHandlerTest {
|
||||
when(service.rebootDbInstance("mydb", "us-west-2")).thenReturn(instance);
|
||||
when(service.listDbClusters(null, "us-west-2")).thenReturn(List.of());
|
||||
when(service.getDbCluster("mycluster", "us-west-2")).thenReturn(cluster);
|
||||
when(service.modifyDbCluster("mycluster", null, null, "us-west-2"))
|
||||
when(service.modifyDbCluster("mycluster", null, null,
|
||||
null, null, null, "us-west-2"))
|
||||
.thenReturn(cluster);
|
||||
|
||||
handler.handle("DescribeDBInstances", params(), "us-west-2");
|
||||
@@ -240,7 +241,8 @@ class RdsQueryHandlerTest {
|
||||
verify(service).listDbClusters(null, "us-west-2");
|
||||
verify(service).getDbCluster("mycluster", "us-west-2");
|
||||
verify(service).deleteDbCluster("mycluster", "us-west-2");
|
||||
verify(service).modifyDbCluster("mycluster", null, null, "us-west-2");
|
||||
verify(service).modifyDbCluster("mycluster", null, null,
|
||||
null, null, null, "us-west-2");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -792,6 +792,219 @@ class RdsServiceTest {
|
||||
any(), any(), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createDbClusterAppliesServerlessV2Scaling() {
|
||||
when(config.services().rds().mock()).thenReturn(true);
|
||||
|
||||
DbCluster cluster = rdsService.createDbCluster("cluster1", "aurora-postgresql", "16.3",
|
||||
"admin", "password", "dbname", false, null, null, null, false, "us-east-1",
|
||||
0.0, 16.0, 600);
|
||||
|
||||
assertEquals(0.0, cluster.getServerlessV2MinCapacity());
|
||||
assertEquals(16.0, cluster.getServerlessV2MaxCapacity());
|
||||
assertEquals(600, cluster.getServerlessV2SecondsUntilAutoPause());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createDbClusterRejectsServerlessV2ScalingForNonAuroraEngines() {
|
||||
when(config.services().rds().mock()).thenReturn(true);
|
||||
|
||||
for (String engine : List.of("postgres", "mysql", "mariadb")) {
|
||||
String clusterId = "cluster-" + engine;
|
||||
AwsException exception = assertThrows(AwsException.class,
|
||||
() -> rdsService.createDbCluster(
|
||||
clusterId, engine, null, "admin", "password", "dbname",
|
||||
false, null, null, null, false, "us-east-1",
|
||||
0.5, 16.0, null));
|
||||
|
||||
assertEquals("InvalidParameterCombination", exception.getErrorCode());
|
||||
assertEquals(400, exception.getHttpStatus());
|
||||
assertEquals(
|
||||
"Parameters that must not be used together were used together. "
|
||||
+ "Remove one of the conflicting parameters and try again.",
|
||||
exception.getMessage());
|
||||
assertTrue(rdsService.listDbClusters(clusterId).isEmpty());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void createDbClusterDefaultsAndClearsServerlessV2AutoPauseInterval() {
|
||||
when(config.services().rds().mock()).thenReturn(true);
|
||||
|
||||
DbCluster autoPauseCluster = rdsService.createDbCluster(
|
||||
"auto-pause", "aurora-postgresql", "16.3",
|
||||
"admin", "password", "dbname", false, null, null, null, false, "us-east-1",
|
||||
0.0, 16.0);
|
||||
DbCluster alwaysActiveCluster = rdsService.createDbCluster(
|
||||
"always-active", "aurora-postgresql", "16.3",
|
||||
"admin", "password", "dbname", false, null, null, null, false, "us-east-1",
|
||||
0.5, 16.0, 600);
|
||||
|
||||
assertEquals(300, autoPauseCluster.getServerlessV2SecondsUntilAutoPause());
|
||||
assertNull(alwaysActiveCluster.getServerlessV2SecondsUntilAutoPause());
|
||||
}
|
||||
|
||||
@Test
|
||||
void modifyDbClusterAppliesServerlessV2ScalingConfiguration() {
|
||||
when(config.services().rds().mock()).thenReturn(true);
|
||||
rdsService.createDbCluster("cluster1", "aurora-postgresql", "16.3",
|
||||
"admin", "password", "dbname", false, null, null, null, false, "us-east-1",
|
||||
0.0, 16.0, 600);
|
||||
|
||||
DbCluster widerRange = rdsService.modifyDbCluster(
|
||||
"cluster1", null, null, null, 32.0, null);
|
||||
|
||||
assertEquals(0.0, widerRange.getServerlessV2MinCapacity());
|
||||
assertEquals(32.0, widerRange.getServerlessV2MaxCapacity());
|
||||
assertEquals(600, widerRange.getServerlessV2SecondsUntilAutoPause());
|
||||
|
||||
DbCluster longerAutoPause = rdsService.modifyDbCluster(
|
||||
"cluster1", null, null, null, null, 900);
|
||||
|
||||
assertEquals(0.0, longerAutoPause.getServerlessV2MinCapacity());
|
||||
assertEquals(32.0, longerAutoPause.getServerlessV2MaxCapacity());
|
||||
assertEquals(900, longerAutoPause.getServerlessV2SecondsUntilAutoPause());
|
||||
|
||||
DbCluster alwaysActiveCluster = rdsService.modifyDbCluster(
|
||||
"cluster1", null, null, 0.5, null, null);
|
||||
assertEquals(0.5, alwaysActiveCluster.getServerlessV2MinCapacity());
|
||||
assertEquals(32.0, alwaysActiveCluster.getServerlessV2MaxCapacity());
|
||||
assertNull(alwaysActiveCluster.getServerlessV2SecondsUntilAutoPause());
|
||||
|
||||
DbCluster autoPauseAgain = rdsService.modifyDbCluster(
|
||||
"cluster1", null, null, 0.0, null, null);
|
||||
assertEquals(300, autoPauseAgain.getServerlessV2SecondsUntilAutoPause());
|
||||
|
||||
DbCluster passwordOnlyChange = rdsService.modifyDbCluster(
|
||||
"cluster1", "new-password", null);
|
||||
assertEquals(0.0, passwordOnlyChange.getServerlessV2MinCapacity());
|
||||
assertEquals(32.0, passwordOnlyChange.getServerlessV2MaxCapacity());
|
||||
assertEquals(300, passwordOnlyChange.getServerlessV2SecondsUntilAutoPause());
|
||||
}
|
||||
|
||||
@Test
|
||||
void modifyDbClusterRejectsServerlessV2ScalingForNonAuroraCluster() {
|
||||
when(config.services().rds().mock()).thenReturn(true);
|
||||
DbCluster cluster = rdsService.createDbCluster(
|
||||
"cluster1", "postgres", "16.3", "admin", "original-password",
|
||||
"dbname", false, null);
|
||||
|
||||
AwsException exception = assertThrows(AwsException.class,
|
||||
() -> rdsService.modifyDbCluster(
|
||||
"cluster1", "new-password", true, 0.5, 16.0, null));
|
||||
|
||||
assertEquals("InvalidParameterCombination", exception.getErrorCode());
|
||||
assertEquals(400, exception.getHttpStatus());
|
||||
assertEquals(
|
||||
"Parameters that must not be used together were used together. "
|
||||
+ "Remove one of the conflicting parameters and try again.",
|
||||
exception.getMessage());
|
||||
assertEquals("original-password", cluster.getMasterPassword());
|
||||
assertFalse(cluster.isIamDatabaseAuthenticationEnabled());
|
||||
assertNull(cluster.getServerlessV2MinCapacity());
|
||||
assertNull(cluster.getServerlessV2MaxCapacity());
|
||||
}
|
||||
|
||||
@Test
|
||||
void modifyDbClusterCanAddServerlessV2ScalingToExistingAuroraCluster() {
|
||||
when(config.services().rds().mock()).thenReturn(true);
|
||||
rdsService.createDbCluster("cluster1", "aurora-postgresql", "16.3",
|
||||
"admin", "password", "dbname", false, null);
|
||||
|
||||
DbCluster cluster = rdsService.modifyDbCluster(
|
||||
"cluster1", null, null, 0.5, 16.0, null);
|
||||
|
||||
assertEquals("aurora-postgresql", cluster.getEngineIdentifier());
|
||||
assertEquals(0.5, cluster.getServerlessV2MinCapacity());
|
||||
assertEquals(16.0, cluster.getServerlessV2MaxCapacity());
|
||||
}
|
||||
|
||||
@Test
|
||||
void modifyDbClusterRejectsScalingWhenPersistedEngineIdentityIsMissing() {
|
||||
when(config.services().rds().mock()).thenReturn(true);
|
||||
DbCluster cluster = rdsService.createDbCluster(
|
||||
"cluster1", "aurora-postgresql", "16.3", "admin", "password",
|
||||
"dbname", false, null);
|
||||
cluster.setEngineIdentifier(null);
|
||||
|
||||
AwsException exception = assertThrows(AwsException.class,
|
||||
() -> rdsService.modifyDbCluster(
|
||||
"cluster1", null, null, 0.5, 16.0, null));
|
||||
|
||||
assertEquals("InvalidParameterCombination", exception.getErrorCode());
|
||||
assertEquals(400, exception.getHttpStatus());
|
||||
assertNull(cluster.getServerlessV2MinCapacity());
|
||||
assertNull(cluster.getServerlessV2MaxCapacity());
|
||||
}
|
||||
|
||||
@Test
|
||||
void modifyDbClusterRejectsPartialScalingWithoutAnExistingConfiguration() {
|
||||
when(config.services().rds().mock()).thenReturn(true);
|
||||
DbCluster cluster = rdsService.createDbCluster("cluster1", "aurora-postgresql", "16.3",
|
||||
"admin", "original-password", "dbname", false, null);
|
||||
|
||||
assertThrows(AwsException.class, () -> rdsService.modifyDbCluster(
|
||||
"cluster1", "new-password", true, null, 16.0, null));
|
||||
|
||||
assertEquals("original-password", cluster.getMasterPassword());
|
||||
assertFalse(cluster.isIamDatabaseAuthenticationEnabled());
|
||||
assertNull(cluster.getServerlessV2MinCapacity());
|
||||
assertNull(cluster.getServerlessV2MaxCapacity());
|
||||
}
|
||||
|
||||
@Test
|
||||
void modifyDbClusterValidatesScalingBeforeApplyingOtherChanges() {
|
||||
when(config.services().rds().mock()).thenReturn(true);
|
||||
DbCluster cluster = rdsService.createDbCluster("cluster1", "aurora-postgresql", "16.3",
|
||||
"admin", "original-password", "dbname", false, null);
|
||||
|
||||
assertThrows(AwsException.class, () -> rdsService.modifyDbCluster(
|
||||
"cluster1", "new-password", true, 0.0, 16.0, 299));
|
||||
|
||||
assertEquals("original-password", cluster.getMasterPassword());
|
||||
assertFalse(cluster.isIamDatabaseAuthenticationEnabled());
|
||||
assertNull(cluster.getServerlessV2MinCapacity());
|
||||
assertNull(cluster.getServerlessV2MaxCapacity());
|
||||
}
|
||||
|
||||
@Test
|
||||
void serverlessV2CapacityValidationEnforcesAcuConstraints() {
|
||||
// Non-half-step increment.
|
||||
assertThrows(AwsException.class, () -> rdsService.validateServerlessV2Capacity(0.3, 16.0));
|
||||
// Above the 256-ACU ceiling.
|
||||
assertThrows(AwsException.class, () -> rdsService.validateServerlessV2Capacity(0.5, 300.0));
|
||||
// AWS requires MaxCapacity to be greater than 0.5 ACUs.
|
||||
assertThrows(AwsException.class, () -> rdsService.validateServerlessV2Capacity(0.0, 0.5));
|
||||
// Non-finite values are not valid AWS Query numbers.
|
||||
assertThrows(AwsException.class, () -> rdsService.validateServerlessV2Capacity(Double.NaN, 16.0));
|
||||
assertThrows(AwsException.class, () -> rdsService.validateServerlessV2Capacity(0.5, Double.NaN));
|
||||
assertThrows(AwsException.class,
|
||||
() -> rdsService.validateServerlessV2Capacity(0.5, Double.POSITIVE_INFINITY));
|
||||
assertThrows(AwsException.class,
|
||||
() -> rdsService.validateServerlessV2Capacity(Double.NEGATIVE_INFINITY, 16.0));
|
||||
// MaxCapacity below MinCapacity.
|
||||
assertThrows(AwsException.class, () -> rdsService.validateServerlessV2Capacity(16.0, 8.0));
|
||||
// Valid: 0 (auto-pause), the 256 ceiling, and half-step values.
|
||||
assertDoesNotThrow(() -> rdsService.validateServerlessV2Capacity(0.0, 256.0));
|
||||
assertDoesNotThrow(() -> rdsService.validateServerlessV2Capacity(0.5, 128.0));
|
||||
// Both null is a no-op (not a Serverless v2 cluster).
|
||||
assertDoesNotThrow(() -> rdsService.validateServerlessV2Capacity(null, null));
|
||||
// A create-time or otherwise incomplete effective configuration requires both bounds.
|
||||
assertThrows(AwsException.class, () -> rdsService.validateServerlessV2Capacity(0.5, null));
|
||||
assertThrows(AwsException.class, () -> rdsService.validateServerlessV2Capacity(null, 16.0));
|
||||
assertThrows(AwsException.class,
|
||||
() -> rdsService.validateServerlessV2ScalingConfiguration(0.0, 16.0, 299));
|
||||
assertThrows(AwsException.class,
|
||||
() -> rdsService.validateServerlessV2ScalingConfiguration(0.0, 16.0, 86_401));
|
||||
assertThrows(AwsException.class,
|
||||
() -> rdsService.validateServerlessV2ScalingConfiguration(null, null, 300));
|
||||
assertEquals(300,
|
||||
rdsService.validateServerlessV2ScalingConfiguration(0.0, 16.0, null));
|
||||
assertEquals(86_400,
|
||||
rdsService.validateServerlessV2ScalingConfiguration(0.0, 16.0, 86_400));
|
||||
assertNull(rdsService.validateServerlessV2ScalingConfiguration(0.5, 16.0, 600));
|
||||
}
|
||||
|
||||
@Test
|
||||
void mockModeCreatesClusterInstanceAvailableWithoutContainer() {
|
||||
when(config.services().rds().mock()).thenReturn(true);
|
||||
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
package io.github.hectorvent.floci.services.rds.model;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import io.github.hectorvent.floci.core.storage.PersistentStorage;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class DbClusterPersistenceTest {
|
||||
|
||||
@Test
|
||||
void serverlessV2ScalingConfigurationPersistsAcrossInstances(@TempDir Path directory) {
|
||||
Path file = directory.resolve("rds-clusters.json");
|
||||
DbCluster cluster = new DbCluster();
|
||||
cluster.setDbClusterIdentifier("serverless-cluster");
|
||||
cluster.setEngineIdentifier("aurora-postgresql");
|
||||
cluster.setServerlessV2MinCapacity(0.0);
|
||||
cluster.setServerlessV2MaxCapacity(16.0);
|
||||
cluster.setServerlessV2SecondsUntilAutoPause(600);
|
||||
|
||||
var writer = new PersistentStorage<String, DbCluster>(
|
||||
file, new TypeReference<Map<String, DbCluster>>() {});
|
||||
writer.put(cluster.getDbClusterIdentifier(), cluster);
|
||||
|
||||
var reader = new PersistentStorage<String, DbCluster>(
|
||||
file, new TypeReference<Map<String, DbCluster>>() {});
|
||||
reader.load();
|
||||
|
||||
var restored = reader.get(cluster.getDbClusterIdentifier());
|
||||
assertTrue(restored.isPresent());
|
||||
assertEquals("aurora-postgresql", restored.get().getEngineIdentifier());
|
||||
assertEquals(0.0, restored.get().getServerlessV2MinCapacity());
|
||||
assertEquals(16.0, restored.get().getServerlessV2MaxCapacity());
|
||||
assertEquals(600, restored.get().getServerlessV2SecondsUntilAutoPause());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user