mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(rds): retain cluster settings and member promotion tiers (#8849)
RDS accepted a cluster's CopyTagsToSnapshot and CloudWatch log exports and an Aurora member's PromotionTier but returned none of them, so Terraform planned changes right after a successful apply. CreateDBCluster and ModifyDBCluster now keep CopyTagsToSnapshot, an explicit false included, and the enabled log exports, with a modify applying CloudwatchLogsExportConfiguration as enable and disable deltas and leaving omitted fields alone. PromotionTier is kept from CreateDBInstance and ModifyDBInstance, defaults to 1 and is refused outside 0 to 15 before anything changes, and both the instance and the cluster member list report it. The new fields persist, and state saved before them loads with the defaults. Closes #8418
This commit is contained in:
1 parent
1c3a6b615e
commit
72b746be13
7 files changed
+319
-1
No files matched your search
@@ -0,0 +1,177 @@
|
||||
package io.floci.aws.services.rds;
|
||||
|
||||
import io.floci.aws.testing.RdsMockProfile;
|
||||
import io.quarkus.arc.ClientProxy;
|
||||
import io.quarkus.test.common.http.TestHTTPResource;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.quarkus.test.junit.TestProfile;
|
||||
import jakarta.inject.Inject;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
|
||||
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
|
||||
import software.amazon.awssdk.regions.Region;
|
||||
import software.amazon.awssdk.services.rds.RdsClient;
|
||||
import software.amazon.awssdk.services.rds.model.DBCluster;
|
||||
import software.amazon.awssdk.services.rds.model.DBInstance;
|
||||
import software.amazon.awssdk.services.rds.model.RdsException;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
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.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@QuarkusTest
|
||||
@TestProfile(RdsMockProfile.class)
|
||||
class RdsSettingsRoundTripIntegrationTest {
|
||||
@TestHTTPResource
|
||||
URI endpoint;
|
||||
@Inject
|
||||
RdsService service;
|
||||
private RdsClient client;
|
||||
private String cluster;
|
||||
private String member;
|
||||
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
client = RdsClient.builder().endpointOverride(endpoint).region(Region.US_EAST_1)
|
||||
.credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create("test", "test")))
|
||||
.build();
|
||||
cluster = "settings-" + UUID.randomUUID();
|
||||
member = cluster + "-member";
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void cleanup() {
|
||||
try {
|
||||
try {
|
||||
client.deleteDBInstance(r -> r.dbInstanceIdentifier(member).skipFinalSnapshot(true));
|
||||
} catch (RdsException ignored) {
|
||||
// Some cases intentionally reject creation before a resource exists.
|
||||
}
|
||||
try {
|
||||
client.deleteDBCluster(r -> r.dbClusterIdentifier(cluster).skipFinalSnapshot(true));
|
||||
} catch (RdsException ignored) {
|
||||
// A create rejected before mutation leaves no cluster to delete.
|
||||
}
|
||||
} finally {
|
||||
client.close();
|
||||
}
|
||||
}
|
||||
|
||||
private DBCluster createCluster(boolean configured) {
|
||||
return client.createDBCluster(r -> {
|
||||
r.dbClusterIdentifier(cluster).engine("aurora-postgresql").engineVersion("16.3")
|
||||
.masterUsername("admin").masterUserPassword(UUID.randomUUID().toString());
|
||||
if (configured) {
|
||||
r.copyTagsToSnapshot(true).enableCloudwatchLogsExports("postgresql");
|
||||
}
|
||||
}).dbCluster();
|
||||
}
|
||||
|
||||
private DBCluster describeCluster() {
|
||||
return client.describeDBClusters(r -> r.dbClusterIdentifier(cluster)).dbClusters().getFirst();
|
||||
}
|
||||
|
||||
@Test
|
||||
void clusterSnapshotAndLogSettingsRoundTripThroughCreateAndDescribe() {
|
||||
DBCluster created = createCluster(true);
|
||||
DBCluster described = describeCluster();
|
||||
assertAll(() -> assertEquals(true, created.copyTagsToSnapshot()),
|
||||
() -> assertEquals(List.of("postgresql"), created.enabledCloudwatchLogsExports()),
|
||||
() -> assertEquals(true, described.copyTagsToSnapshot()),
|
||||
() -> assertEquals(List.of("postgresql"), described.enabledCloudwatchLogsExports()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void clusterModifyPreservesOmittedSettingsAndAppliesFalseAndLogDeltas() {
|
||||
createCluster(true);
|
||||
DBCluster unchanged = client.modifyDBCluster(r -> r.dbClusterIdentifier(cluster).applyImmediately(true)).dbCluster();
|
||||
assertEquals(true, unchanged.copyTagsToSnapshot());
|
||||
assertEquals(List.of("postgresql"), unchanged.enabledCloudwatchLogsExports());
|
||||
DBCluster changed = client.modifyDBCluster(r -> r.dbClusterIdentifier(cluster).copyTagsToSnapshot(false)
|
||||
.cloudwatchLogsExportConfiguration(c -> c.enableLogTypes("iam-db-auth-error")
|
||||
.disableLogTypes("postgresql")).applyImmediately(true)).dbCluster();
|
||||
assertEquals(false, changed.copyTagsToSnapshot());
|
||||
assertEquals(List.of("iam-db-auth-error"), changed.enabledCloudwatchLogsExports());
|
||||
client.modifyDBCluster(r -> r.dbClusterIdentifier(cluster)
|
||||
.cloudwatchLogsExportConfiguration(c -> c.disableLogTypes("iam-db-auth-error")));
|
||||
assertFalse(describeCluster().copyTagsToSnapshot());
|
||||
assertTrue(describeCluster().enabledCloudwatchLogsExports().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void clusterDefaultsAndEnableOnlyChangesPreserveExistingExports() {
|
||||
DBCluster created = createCluster(false);
|
||||
assertFalse(created.copyTagsToSnapshot());
|
||||
assertTrue(created.enabledCloudwatchLogsExports().isEmpty());
|
||||
client.modifyDBCluster(r -> r.dbClusterIdentifier(cluster).copyTagsToSnapshot(true)
|
||||
.cloudwatchLogsExportConfiguration(c -> c.enableLogTypes("postgresql")));
|
||||
DBCluster changed = client.modifyDBCluster(r -> r.dbClusterIdentifier(cluster)
|
||||
.cloudwatchLogsExportConfiguration(c -> c.enableLogTypes("iam-db-auth-error"))).dbCluster();
|
||||
assertTrue(changed.copyTagsToSnapshot());
|
||||
assertEquals(List.of("postgresql", "iam-db-auth-error"), changed.enabledCloudwatchLogsExports());
|
||||
assertEquals(changed.enabledCloudwatchLogsExports(), describeCluster().enabledCloudwatchLogsExports());
|
||||
}
|
||||
|
||||
@Test
|
||||
void memberPromotionTierRoundTripsAndTracksExplicitZero() {
|
||||
createCluster(false);
|
||||
DBInstance created = client.createDBInstance(r -> r.dbInstanceIdentifier(member).dbClusterIdentifier(cluster)
|
||||
.engine("aurora-postgresql").dbInstanceClass("db.r6g.large").promotionTier(7)).dbInstance();
|
||||
assertEquals(7, created.promotionTier());
|
||||
assertEquals(7, describeCluster().dbClusterMembers().getFirst().promotionTier());
|
||||
assertEquals(7, client.modifyDBInstance(r -> r.dbInstanceIdentifier(member)
|
||||
.autoMinorVersionUpgrade(false)).dbInstance().promotionTier());
|
||||
assertEquals(0, client.modifyDBInstance(r -> r.dbInstanceIdentifier(member).promotionTier(0))
|
||||
.dbInstance().promotionTier());
|
||||
assertEquals(0, client.describeDBInstances(r -> r.dbInstanceIdentifier(member))
|
||||
.dbInstances().getFirst().promotionTier());
|
||||
assertEquals(0, describeCluster().dbClusterMembers().getFirst().promotionTier());
|
||||
assertEquals(15, client.modifyDBInstance(r -> r.dbInstanceIdentifier(member).promotionTier(15))
|
||||
.dbInstance().promotionTier());
|
||||
assertEquals(15, describeCluster().dbClusterMembers().getFirst().promotionTier());
|
||||
}
|
||||
|
||||
@Test
|
||||
void clusterDescribeDoesNotWaitForServiceMonitor() throws Exception {
|
||||
createCluster(false);
|
||||
client.createDBInstance(r -> r.dbInstanceIdentifier(member).dbClusterIdentifier(cluster)
|
||||
.engine("aurora-postgresql").dbInstanceClass("db.r6g.large").promotionTier(7));
|
||||
try (ExecutorService executor = Executors.newSingleThreadExecutor()) {
|
||||
synchronized (ClientProxy.unwrap(service)) {
|
||||
Future<DBCluster> response = executor.submit(this::describeCluster);
|
||||
assertEquals(7, response.get(10, TimeUnit.SECONDS).dbClusterMembers().getFirst().promotionTier());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void promotionTierDefaultsToOneAndInvalidChangesAreAtomic() {
|
||||
createCluster(false);
|
||||
for (int tier : List.of(-1, 16)) {
|
||||
RdsException error = assertThrows(RdsException.class, () -> client.createDBInstance(r ->
|
||||
r.dbInstanceIdentifier(member).dbClusterIdentifier(cluster).engine("aurora-postgresql")
|
||||
.dbInstanceClass("db.r6g.large").promotionTier(tier)));
|
||||
assertEquals("InvalidParameterValue", error.awsErrorDetails().errorCode());
|
||||
assertTrue(describeCluster().dbClusterMembers().isEmpty());
|
||||
}
|
||||
assertEquals(1, client.createDBInstance(r -> r.dbInstanceIdentifier(member).dbClusterIdentifier(cluster)
|
||||
.engine("aurora-postgresql").dbInstanceClass("db.r6g.large")).dbInstance().promotionTier());
|
||||
assertThrows(RdsException.class, () -> client.modifyDBInstance(r -> r.dbInstanceIdentifier(member)
|
||||
.promotionTier(16).autoMinorVersionUpgrade(false)));
|
||||
DBInstance unchanged = client.describeDBInstances(r -> r.dbInstanceIdentifier(member)).dbInstances().getFirst();
|
||||
assertEquals(1, unchanged.promotionTier());
|
||||
assertTrue(unchanged.autoMinorVersionUpgrade());
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,53 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class DbClusterPersistenceTest {
|
||||
|
||||
@Test
|
||||
void snapshotLogAndPromotionSettingsPersistAcrossInstances(@TempDir Path directory) {
|
||||
DbCluster cluster = new DbCluster();
|
||||
cluster.setDbClusterIdentifier("settings-cluster");
|
||||
cluster.setCopyTagsToSnapshot(true);
|
||||
cluster.setEnabledCloudwatchLogsExports(List.of("postgresql", "iam-db-auth-error"));
|
||||
DbInstance instance = new DbInstance();
|
||||
instance.setDbInstanceIdentifier("settings-member");
|
||||
instance.setPromotionTier(0);
|
||||
|
||||
Path clusters = directory.resolve("rds-clusters.json");
|
||||
new PersistentStorage<String, DbCluster>(clusters, new TypeReference<Map<String, DbCluster>>() {})
|
||||
.put(cluster.getDbClusterIdentifier(), cluster);
|
||||
Path instances = directory.resolve("rds-instances.json");
|
||||
new PersistentStorage<String, DbInstance>(instances, new TypeReference<Map<String, DbInstance>>() {})
|
||||
.put(instance.getDbInstanceIdentifier(), instance);
|
||||
|
||||
PersistentStorage<String, DbCluster> clusterReader = new PersistentStorage<>(
|
||||
clusters, new TypeReference<Map<String, DbCluster>>() {});
|
||||
clusterReader.load();
|
||||
DbCluster restored = clusterReader.get("settings-cluster").orElseThrow();
|
||||
assertTrue(restored.isCopyTagsToSnapshot());
|
||||
assertEquals(List.of("postgresql", "iam-db-auth-error"), restored.getEnabledCloudwatchLogsExports());
|
||||
PersistentStorage<String, DbInstance> instanceReader = new PersistentStorage<>(
|
||||
instances, new TypeReference<Map<String, DbInstance>>() {});
|
||||
instanceReader.load();
|
||||
assertEquals(0, instanceReader.get("settings-member").orElseThrow().getPromotionTier());
|
||||
}
|
||||
|
||||
@Test
|
||||
void stateSavedBeforeSettingsLoadsWithDefaults(@TempDir Path directory) throws Exception {
|
||||
Path clusters = directory.resolve("rds-clusters.json");
|
||||
Files.writeString(clusters, "{\"legacy\":{\"dbClusterIdentifier\":\"legacy\"}}");
|
||||
Path instances = directory.resolve("rds-instances.json");
|
||||
Files.writeString(instances, "{\"legacy\":{\"dbInstanceIdentifier\":\"legacy\"}}");
|
||||
PersistentStorage<String, DbCluster> clusterReader = new PersistentStorage<>(
|
||||
clusters, new TypeReference<Map<String, DbCluster>>() {});
|
||||
clusterReader.load();
|
||||
DbCluster restored = clusterReader.get("legacy").orElseThrow();
|
||||
assertFalse(restored.isCopyTagsToSnapshot());
|
||||
assertTrue(restored.getEnabledCloudwatchLogsExports().isEmpty());
|
||||
PersistentStorage<String, DbInstance> instanceReader = new PersistentStorage<>(
|
||||
instances, new TypeReference<Map<String, DbInstance>>() {});
|
||||
instanceReader.load();
|
||||
assertEquals(1, instanceReader.get("legacy").orElseThrow().getPromotionTier());
|
||||
}
|
||||
|
||||
@Test
|
||||
void serverlessV2ScalingConfigurationPersistsAcrossInstances(@TempDir Path directory) {
|
||||
Path file = directory.resolve("rds-clusters.json");
|
||||
|
||||
Reference in new issue
Block a user