Light, fluffy, and always free - The AWS Local Emulator alternative
fix(rds): report the monitoring and lifecycle settings a DB instance was given (#3688)
lex00c664b9e13660
diff --git a/src/main/java/io/github/hectorvent/floci/services/rds/RdsQueryHandler.java b/src/main/java/io/github/hectorvent/floci/services/rds/RdsQueryHandler.javaindex 18476c3b71..b726b9ced7 100644--- a/src/main/java/io/github/hectorvent/floci/services/rds/RdsQueryHandler.java+++ b/src/main/java/io/github/hectorvent/floci/services/rds/RdsQueryHandler.java@@ -14,6 +14,7 @@ import io.github.hectorvent.floci.services.docdb.DocDbQueryHandler;import io.github.hectorvent.floci.services.neptune.NeptuneQueryHandler;import io.github.hectorvent.floci.services.rds.model.DbInstance;import io.github.hectorvent.floci.services.rds.model.DbInstanceSettings;+import io.github.hectorvent.floci.services.rds.model.LogExportChanges;import io.github.hectorvent.floci.services.rds.model.DbInstanceStatus;import io.github.hectorvent.floci.services.rds.model.DbParameterGroup;import io.github.hectorvent.floci.services.rds.model.DbProxy;@@ -419,9 +420,45 @@ public class RdsQueryHandler {optionalInt(params.getFirst("BackupRetentionPeriod")),params.getFirst("PreferredBackupWindow"),params.getFirst("PreferredMaintenanceWindow"),- optionalBoolean(params.getFirst("CopyTagsToSnapshot")));+ optionalBoolean(params.getFirst("CopyTagsToSnapshot")),+ optionalInt(params.getFirst("MonitoringInterval")),+ params.getFirst("MonitoringRoleArn"),+ optionalBoolean(params.getFirst("EnablePerformanceInsights")),+ optionalInt(params.getFirst("PerformanceInsightsRetentionPeriod")),+ params.getFirst("EngineLifecycleSupport"),+ includeEncryption ? cloudwatchLogsExports(params) : null,+ includeEncryption ? null : cloudwatchLogsExportChanges(params),+ optionalInt(params.getFirst("MaxAllocatedStorage")));}+ /**+ * CreateDBInstance names the log types once, as EnableCloudwatchLogsExports.member.N. The+ * response member is EnabledCloudwatchLogsExports, so the two never line up on the wire.+ * An absent list is null (leave it alone) rather than empty (clear it).+ */+ private static List<String> cloudwatchLogsExports(MultivaluedMap<String, String> params) {+ List<String> types = memberList(params, "EnableCloudwatchLogsExports");+ return types.isEmpty() ? null : types;+ }++ /**+ * ModifyDBInstance has no EnableCloudwatchLogsExports at all. It carries+ * CloudwatchLogsExportConfiguration with an EnableLogTypes list and a DisableLogTypes list,+ * which are applied to the stored set as deltas rather than as a replacement. Reading the+ * create-only key here is why an SDK request to change exports on a live instance did nothing.+ */+ private static LogExportChanges cloudwatchLogsExportChanges(MultivaluedMap<String, String> params) {+ List<String> enable = memberList(params,+ "CloudwatchLogsExportConfiguration.EnableLogTypes");+ List<String> disable = memberList(params,+ "CloudwatchLogsExportConfiguration.DisableLogTypes");+ if (enable.isEmpty() && disable.isEmpty()) {+ return null;+ }+ return new LogExportChanges(enable, disable);+ }++private static Boolean optionalBoolean(String value) {return value == null ? null : Boolean.parseBoolean(value);}@@ -1959,7 +1996,24 @@ public class RdsQueryHandler {.raw(optionGroupMembershipsXml(i)).raw(dbSubnetGroupXml(dbSubnetGroupForInstance(i))).elem("DbiResourceId", i.getDbiResourceId())- .elem("DBInstanceArn", i.getDbInstanceArn());+ .elem("DBInstanceArn", i.getDbInstanceArn())+ .elem("MonitoringInterval", i.getMonitoringInterval())+ .elem("PerformanceInsightsEnabled", i.isPerformanceInsightsEnabled())+ .elem("EngineLifecycleSupport", i.getEngineLifecycleSupport());+ if (i.getMonitoringRoleArn() != null && !i.getMonitoringRoleArn().isBlank()) {+ xml.elem("MonitoringRoleArn", i.getMonitoringRoleArn());+ }+ if (i.isPerformanceInsightsEnabled()) {+ xml.elem("PerformanceInsightsRetentionPeriod", i.getPerformanceInsightsRetentionPeriod());+ }+ if (i.getMaxAllocatedStorage() != null) {+ xml.elem("MaxAllocatedStorage", i.getMaxAllocatedStorage());+ }+ if (i.getEnabledCloudwatchLogsExports() != null && !i.getEnabledCloudwatchLogsExports().isEmpty()) {+ xml.start("EnabledCloudwatchLogsExports");+ i.getEnabledCloudwatchLogsExports().forEach(t -> xml.elem("member", t));+ xml.end("EnabledCloudwatchLogsExports");+ }if (i.getKmsKeyId() != null && !i.getKmsKeyId().isBlank()) {xml.elem("KmsKeyId", i.getKmsKeyId());}diff --git a/src/main/java/io/github/hectorvent/floci/services/rds/RdsService.java b/src/main/java/io/github/hectorvent/floci/services/rds/RdsService.javaindex 2216461093..04748b52fc 100644--- a/src/main/java/io/github/hectorvent/floci/services/rds/RdsService.java+++ b/src/main/java/io/github/hectorvent/floci/services/rds/RdsService.java@@ -617,6 +617,8 @@ public class RdsService implements Resettable, ResourceProvider {// resolved with the other validations, before a port is taken or a container startedDbInstanceSettings resolvedSettings = withEffectiveWindows(settings, null).withKmsKeyId(resolveKmsKeyArn(settings.kmsKeyId(), effectiveRegion));+ DbInstanceSettings.validateMonitoringPairOnCreate(+ settings.monitoringInterval(), settings.monitoringRoleArn());boolean mock = config.services().rds().mock();// Always reserve a unique port (even in mock) so endpoints stay distinct and usedPorts// is consistent; mock mode only skips starting the container and auth proxy.@@ -1971,8 +1973,7 @@ public class RdsService implements Resettable, ResourceProvider {if (DbInstanceSettings.windowsOverlap(backup, maintenance)) {throw DbInstanceSettings.overlappingWindows();}- return new DbInstanceSettings(settings.storageEncrypted(), settings.kmsKeyId(),- settings.backupRetentionPeriod(), backup, maintenance, settings.copyTagsToSnapshot());+ return settings.withWindows(backup, maintenance);}/**diff --git a/src/main/java/io/github/hectorvent/floci/services/rds/model/DbInstance.java b/src/main/java/io/github/hectorvent/floci/services/rds/model/DbInstance.javaindex 9ee5b21348..78c8d50e19 100644--- a/src/main/java/io/github/hectorvent/floci/services/rds/model/DbInstance.java+++ b/src/main/java/io/github/hectorvent/floci/services/rds/model/DbInstance.java@@ -45,6 +45,17 @@ public class DbInstance {private String preferredMaintenanceWindow;private boolean copyTagsToSnapshot;private boolean publiclyAccessible;+ /** MonitoringInterval documents 0 as its default. */+ private int monitoringInterval;+ private String monitoringRoleArn;+ private boolean performanceInsightsEnabled;+ /** PerformanceInsightsRetentionPeriod documents 7 days as its default. */+ private int performanceInsightsRetentionPeriod = 7;+ /** EngineLifecycleSupport documents open-source-rds-extended-support as its default. */+ private String engineLifecycleSupport = DbInstanceSettings.ENGINE_LIFECYCLE_SUPPORT_ENABLED;+ private List<String> enabledCloudwatchLogsExports = new ArrayList<>();+ /** Absent unless storage autoscaling is on, which is how AWS reports it. */+ private Integer maxAllocatedStorage;private Map<String, String> subnetAvailabilityZones = new LinkedHashMap<>();private String dbiResourceId;private String dbInstanceArn;@@ -256,4 +267,35 @@ public class DbInstance {public int getContainerPort() { return containerPort; }public void setContainerPort(int containerPort) { this.containerPort = containerPort; }++ public int getMonitoringInterval() { return monitoringInterval; }+ public void setMonitoringInterval(int monitoringInterval) { this.monitoringInterval = monitoringInterval; }++ public String getMonitoringRoleArn() { return monitoringRoleArn; }+ public void setMonitoringRoleArn(String monitoringRoleArn) { this.monitoringRoleArn = monitoringRoleArn; }++ public boolean isPerformanceInsightsEnabled() { return performanceInsightsEnabled; }+ public void setPerformanceInsightsEnabled(boolean performanceInsightsEnabled) {+ this.performanceInsightsEnabled = performanceInsightsEnabled;+ }++ public int getPerformanceInsightsRetentionPeriod() { return performanceInsightsRetentionPeriod; }+ public void setPerformanceInsightsRetentionPeriod(int performanceInsightsRetentionPeriod) {+ this.performanceInsightsRetentionPeriod = performanceInsightsRetentionPeriod;+ }++ public String getEngineLifecycleSupport() { return engineLifecycleSupport; }+ public void setEngineLifecycleSupport(String engineLifecycleSupport) {+ this.engineLifecycleSupport = engineLifecycleSupport;+ }++ public List<String> getEnabledCloudwatchLogsExports() { return enabledCloudwatchLogsExports; }+ public void setEnabledCloudwatchLogsExports(List<String> enabledCloudwatchLogsExports) {+ this.enabledCloudwatchLogsExports = enabledCloudwatchLogsExports;+ }++ public Integer getMaxAllocatedStorage() { return maxAllocatedStorage; }+ public void setMaxAllocatedStorage(Integer maxAllocatedStorage) {+ this.maxAllocatedStorage = maxAllocatedStorage;+ }}diff --git a/src/main/java/io/github/hectorvent/floci/services/rds/model/DbInstanceSettings.java b/src/main/java/io/github/hectorvent/floci/services/rds/model/DbInstanceSettings.javaindex 1ddce881a1..b897e3b1b8 100644--- a/src/main/java/io/github/hectorvent/floci/services/rds/model/DbInstanceSettings.java+++ b/src/main/java/io/github/hectorvent/floci/services/rds/model/DbInstanceSettings.java@@ -4,6 +4,9 @@ import io.github.hectorvent.floci.core.common.AwsException;import io.github.hectorvent.floci.core.common.BackupWindows;import io.quarkus.runtime.annotations.RegisterForReflection;+import java.util.List;+import java.util.Set;+/*** The storage and backup settings of a DB instance as a request carries them: a null member is@@ -15,7 +18,34 @@ public record DbInstanceSettings(Boolean storageEncrypted,Integer backupRetentionPeriod,String preferredBackupWindow,String preferredMaintenanceWindow,- Boolean copyTagsToSnapshot) {+ Boolean copyTagsToSnapshot,+ Integer monitoringInterval,+ String monitoringRoleArn,+ Boolean performanceInsightsEnabled,+ Integer performanceInsightsRetentionPeriod,+ String engineLifecycleSupport,+ List<String> enabledCloudwatchLogsExports,+ LogExportChanges logExportChanges,+ Integer maxAllocatedStorage) {++ /** The settings a caller that touches none of the monitoring members gives. */+ public DbInstanceSettings(Boolean storageEncrypted,+ String kmsKeyId,+ Integer backupRetentionPeriod,+ String preferredBackupWindow,+ String preferredMaintenanceWindow,+ Boolean copyTagsToSnapshot) {+ this(storageEncrypted, kmsKeyId, backupRetentionPeriod, preferredBackupWindow,+ preferredMaintenanceWindow, copyTagsToSnapshot, null, null, null, null, null,+ null, null, null);+ }++ /** MonitoringInterval documents these as its valid values. */+ private static final Set<Integer> MONITORING_INTERVALS = Set.of(0, 1, 5, 10, 15, 30, 60);++ public static final String ENGINE_LIFECYCLE_SUPPORT_ENABLED = "open-source-rds-extended-support";+ public static final String ENGINE_LIFECYCLE_SUPPORT_DISABLED =+ "open-source-rds-extended-support-disabled";/** Where AWS picks a random 30-minute window, Floci picks these. */public static final String DEFAULT_BACKUP_WINDOW = BackupWindows.DEFAULT_BACKUP_WINDOW;@@ -46,6 +76,60 @@ public record DbInstanceSettings(Boolean storageEncrypted,if (preferredMaintenanceWindow != null) {BackupWindows.parseMaintenanceWindow(preferredMaintenanceWindow);}+ if (monitoringInterval != null && !MONITORING_INTERVALS.contains(monitoringInterval)) {+ throw new AwsException("InvalidParameterValue",+ "Invalid monitoring interval: " + monitoringInterval+ + ". Valid values are 0, 1, 5, 10, 15, 30, 60.", 400);+ }+ if (performanceInsightsRetentionPeriod != null+ && !validPerformanceInsightsRetention(performanceInsightsRetentionPeriod)) {+ throw new AwsException("InvalidParameterValue",+ "Invalid Performance Insights retention period: "+ + performanceInsightsRetentionPeriod+ + ". Valid values are 7, 731, or a multiple of 31 up to 713.", 400);+ }+ if (engineLifecycleSupport != null+ && !ENGINE_LIFECYCLE_SUPPORT_ENABLED.equals(engineLifecycleSupport)+ && !ENGINE_LIFECYCLE_SUPPORT_DISABLED.equals(engineLifecycleSupport)) {+ throw new AwsException("InvalidParameterValue",+ "Invalid engine lifecycle support: " + engineLifecycleSupport+ + ". Valid values are " + ENGINE_LIFECYCLE_SUPPORT_ENABLED + ", "+ + ENGINE_LIFECYCLE_SUPPORT_DISABLED + ".", 400);+ }+ }++ /**+ * The monitoring pair, as CreateDBInstance states it. An interval other than 0 needs a role and+ * a role needs an interval other than 0, judged on what this request carries.+ *+ * <p>Create only, deliberately. The two messages word the rule differently and the difference+ * is the whole point. CreateDBInstanceMessage says "you must supply a MonitoringRoleArn value"+ * and "you must set MonitoringInterval to a value other than 0". ModifyDBInstanceMessage drops+ * the "must" from both, and its MonitoringInterval adds "To disable collection of Enhanced+ * Monitoring metrics, specify 0" with no mention of clearing the role. Enforcing the pair on a+ * modify would refuse the documented way to turn monitoring off.+ */+ public static void validateMonitoringPairOnCreate(Integer interval, String roleArn) {+ int effectiveInterval = interval != null ? interval : 0;+ boolean roleGiven = roleArn != null && !roleArn.isBlank();+ if (effectiveInterval != 0 && !roleGiven) {+ throw new AwsException("InvalidParameterCombination",+ "You must supply a MonitoringRoleArn value when MonitoringInterval is set to a "+ + "value other than 0.", 400);+ }+ if (roleGiven && effectiveInterval == 0) {+ throw new AwsException("InvalidParameterCombination",+ "You must set MonitoringInterval to a value other than 0 when MonitoringRoleArn "+ + "is specified.", 400);+ }+ }++ /**+ * 7 days, 731 days, or month * 31 for a whole number of months from 1 to 23, which is what+ * the member documents. A period outside that set, 94 for instance, is an error on AWS.+ */+ private static boolean validPerformanceInsightsRetention(int days) {+ return days == 7 || days == 731 || (days % 31 == 0 && days / 31 >= 1 && days / 31 <= 23);}/** Whether a daily backup window and a weekly maintenance window share any minute. */@@ -84,9 +168,21 @@ public record DbInstanceSettings(Boolean storageEncrypted,return BackupWindows.overlapping();}+ /** The same settings with the windows the service resolved, leaving every other member alone. */+ public DbInstanceSettings withWindows(String backupWindow, String maintenanceWindow) {+ return new DbInstanceSettings(storageEncrypted, kmsKeyId, backupRetentionPeriod,+ backupWindow, maintenanceWindow, copyTagsToSnapshot,+ monitoringInterval, monitoringRoleArn, performanceInsightsEnabled,+ performanceInsightsRetentionPeriod, engineLifecycleSupport,+ enabledCloudwatchLogsExports, logExportChanges, maxAllocatedStorage);+ }+public DbInstanceSettings withKmsKeyId(String resolvedKmsKeyId) {return new DbInstanceSettings(storageEncrypted, resolvedKmsKeyId, backupRetentionPeriod,- preferredBackupWindow, preferredMaintenanceWindow, copyTagsToSnapshot);+ preferredBackupWindow, preferredMaintenanceWindow, copyTagsToSnapshot,+ monitoringInterval, monitoringRoleArn, performanceInsightsEnabled,+ performanceInsightsRetentionPeriod, engineLifecycleSupport,+ enabledCloudwatchLogsExports, logExportChanges, maxAllocatedStorage);}public void applyTo(DbInstance instance) {@@ -108,5 +204,31 @@ public record DbInstanceSettings(Boolean storageEncrypted,if (copyTagsToSnapshot != null) {instance.setCopyTagsToSnapshot(copyTagsToSnapshot);}+ if (monitoringInterval != null) {+ instance.setMonitoringInterval(monitoringInterval);+ }+ if (monitoringRoleArn != null && !monitoringRoleArn.isBlank()) {+ instance.setMonitoringRoleArn(monitoringRoleArn);+ }+ if (performanceInsightsEnabled != null) {+ instance.setPerformanceInsightsEnabled(performanceInsightsEnabled);+ }+ if (performanceInsightsRetentionPeriod != null) {+ instance.setPerformanceInsightsRetentionPeriod(performanceInsightsRetentionPeriod);+ }+ if (engineLifecycleSupport != null && !engineLifecycleSupport.isBlank()) {+ instance.setEngineLifecycleSupport(engineLifecycleSupport);+ }+ if (enabledCloudwatchLogsExports != null) {+ instance.setEnabledCloudwatchLogsExports(List.copyOf(enabledCloudwatchLogsExports));+ }+ // A modify sends deltas rather than a replacement, so they fold into the stored set.+ if (logExportChanges != null) {+ instance.setEnabledCloudwatchLogsExports(+ logExportChanges.applyTo(instance.getEnabledCloudwatchLogsExports()));+ }+ if (maxAllocatedStorage != null) {+ instance.setMaxAllocatedStorage(maxAllocatedStorage);+ }}}diff --git a/src/main/java/io/github/hectorvent/floci/services/rds/model/LogExportChanges.java b/src/main/java/io/github/hectorvent/floci/services/rds/model/LogExportChanges.javanew file mode 100644index 0000000000..1bfd6924d5--- /dev/null+++ b/src/main/java/io/github/hectorvent/floci/services/rds/model/LogExportChanges.java@@ -0,0 +1,32 @@+package io.github.hectorvent.floci.services.rds.model;++import io.quarkus.runtime.annotations.RegisterForReflection;++import java.util.ArrayList;+import java.util.LinkedHashSet;+import java.util.List;+import java.util.Set;++/**+ * The two lists ModifyDBInstance carries in {@code CloudwatchLogsExportConfiguration}.+ *+ * <p>They are deltas against whatever the instance already exports, not a replacement for it, which+ * is what separates a modify from a create. CreateDBInstance names the whole set once in+ * {@code EnableCloudwatchLogsExports}; a modify turns individual types on and off and leaves the+ * rest alone. A null list is one the request omitted.+ */+@RegisterForReflection+public record LogExportChanges(List<String> enableLogTypes, List<String> disableLogTypes) {++ /** The stored set with the enables added and the disables removed, order preserved. */+ public List<String> applyTo(List<String> current) {+ Set<String> result = new LinkedHashSet<>(current == null ? List.of() : current);+ if (enableLogTypes != null) {+ result.addAll(enableLogTypes);+ }+ if (disableLogTypes != null) {+ disableLogTypes.forEach(result::remove);+ }+ return new ArrayList<>(result);+ }+}diff --git a/src/test/java/io/github/hectorvent/floci/services/rds/RdsInstanceMonitoringFieldsIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/rds/RdsInstanceMonitoringFieldsIntegrationTest.javanew file mode 100644index 0000000000..6554d051a9--- /dev/null+++ b/src/test/java/io/github/hectorvent/floci/services/rds/RdsInstanceMonitoringFieldsIntegrationTest.java@@ -0,0 +1,229 @@+package io.github.hectorvent.floci.services.rds;++import io.quarkus.test.junit.QuarkusTest;+import io.restassured.response.ValidatableResponse;+import io.restassured.specification.RequestSpecification;+import io.quarkus.test.junit.QuarkusTestProfile;+import io.quarkus.test.junit.TestProfile;+import org.junit.jupiter.api.AfterEach;+import org.junit.jupiter.api.Test;++import java.util.Map;++import static io.restassured.RestAssured.given;+import static io.restassured.http.ContentType.URLENC;+import static org.hamcrest.Matchers.containsString;+import static org.junit.jupiter.api.Assertions.assertFalse;+import static org.hamcrest.Matchers.equalTo;+import static org.hamcrest.Matchers.not;++/**+ * CreateDBInstance and ModifyDBInstance took the monitoring, Performance Insights, engine+ * lifecycle, log export and storage autoscaling settings and dropped them, so DescribeDBInstances+ * reported none of them and a caller saw its own configuration missing on every read.+ *+ * <p>Each member's documented default and valid values come from the RDS model.+ */+@QuarkusTest+@TestProfile(RdsInstanceMonitoringFieldsIntegrationTest.NoContainersProfile.class)+class RdsInstanceMonitoringFieldsIntegrationTest {++ public static class NoContainersProfile implements QuarkusTestProfile {+ @Override+ public Map<String, String> getConfigOverrides() {+ return Map.of("floci.services.rds.mock", "true");+ }+ }++ private static final String ID = "monitoring-fields-db";+ private static final String ROLE = "arn:aws:iam::000000000000:role/rds-monitoring-role";+ private static final String RESULT =+ "DescribeDBInstancesResponse.DescribeDBInstancesResult.DBInstances.DBInstance.";++ private static RequestSpecification rds(String action) {+ return given().header("Authorization",+ "AWS4-HMAC-SHA256 Credential=test/20260615/us-east-1/rds/aws4_request, "+ + "SignedHeaders=content-type;host, Signature=test")+ .contentType(URLENC)+ .formParam("Action", action)+ .formParam("Version", "2014-10-31");+ }++ private static RequestSpecification create() {+ return rds("CreateDBInstance")+ .formParam("DBInstanceIdentifier", ID)+ .formParam("Engine", "postgres")+ .formParam("DBInstanceClass", "db.t3.micro")+ .formParam("MasterUsername", "adminuser")+ .formParam("MasterUserPassword", "secret123")+ .formParam("AllocatedStorage", "20");+ }++ private static ValidatableResponse describe() {+ return rds("DescribeDBInstances").formParam("DBInstanceIdentifier", ID)+ .when().post("/").then().statusCode(200);+ }++ @AfterEach+ void cleanUp() {+ rds("DeleteDBInstance").formParam("DBInstanceIdentifier", ID)+ .formParam("SkipFinalSnapshot", "true").when().post("/");+ }++ @Test+ void createDBInstance_roundTripsEveryMonitoringMember() {+ create()+ .formParam("MonitoringInterval", "30")+ .formParam("MonitoringRoleArn", ROLE)+ .formParam("EnablePerformanceInsights", "true")+ .formParam("PerformanceInsightsRetentionPeriod", "93")+ .formParam("EngineLifecycleSupport", "open-source-rds-extended-support-disabled")+ .formParam("MaxAllocatedStorage", "100")+ .formParam("EnableCloudwatchLogsExports.member.1", "postgresql")+ .formParam("EnableCloudwatchLogsExports.member.2", "upgrade")+ .when().post("/").then().statusCode(200);++ describe()+ .body(RESULT + "MonitoringInterval", equalTo("30"))+ .body(RESULT + "MonitoringRoleArn", equalTo(ROLE))+ .body(RESULT + "PerformanceInsightsEnabled", equalTo("true"))+ .body(RESULT + "PerformanceInsightsRetentionPeriod", equalTo("93"))+ .body(RESULT + "EngineLifecycleSupport",+ equalTo("open-source-rds-extended-support-disabled"))+ .body(RESULT + "MaxAllocatedStorage", equalTo("100"))+ .body(RESULT + "EnabledCloudwatchLogsExports.member[0]", equalTo("postgresql"))+ .body(RESULT + "EnabledCloudwatchLogsExports.member[1]", equalTo("upgrade"));+ }++ @Test+ void createDBInstance_withoutTheMembers_reportsTheirDocumentedDefaults() {+ create().when().post("/").then().statusCode(200);++ describe()+ .body(RESULT + "MonitoringInterval", equalTo("0"))+ .body(RESULT + "PerformanceInsightsEnabled", equalTo("false"))+ .body(RESULT + "EngineLifecycleSupport",+ equalTo("open-source-rds-extended-support"));++ // AWS reports neither when storage autoscaling is off and no log type is exported.+ String body = rds("DescribeDBInstances").formParam("DBInstanceIdentifier", ID)+ .when().post("/").then().extract().asString();+ assertFalse(body.contains("MaxAllocatedStorage"));+ assertFalse(body.contains("EnabledCloudwatchLogsExports"));+ }++ @Test+ void modifyDBInstance_replacesTheStoredMonitoringMembers() {+ create().formParam("MonitoringInterval", "15").formParam("MonitoringRoleArn", ROLE)+ .when().post("/").then().statusCode(200);++ // Raising the interval without naming a role is valid, because the instance already holds+ // one. The pair is judged on what will be in effect, not on what the request carried.+ rds("ModifyDBInstance")+ .formParam("DBInstanceIdentifier", ID)+ .formParam("MonitoringInterval", "60")+ .formParam("MaxAllocatedStorage", "500")+ .when().post("/").then().statusCode(200);++ describe()+ .body(RESULT + "MonitoringInterval", equalTo("60"))+ .body(RESULT + "MaxAllocatedStorage", equalTo("500"));+ }++ @Test+ void createDBInstance_rejectsAMonitoringIntervalOutsideTheValidValues() {+ create().formParam("MonitoringInterval", "45").formParam("MonitoringRoleArn", ROLE)+ .when().post("/").then().statusCode(400)+ .body(containsString("InvalidParameterValue"))+ .body(containsString("Valid values are 0, 1, 5, 10, 15, 30, 60"));+ }++ // MonitoringInterval and MonitoringRoleArn are documented as a pair, in both directions and on+ // both operations, so neither is valid alone.+ @Test+ void createDBInstance_withAnIntervalAndNoRole_isRejected() {+ create().formParam("MonitoringInterval", "30")+ .when().post("/").then().statusCode(400)+ .body(containsString("InvalidParameterCombination"))+ .body(containsString("You must supply a MonitoringRoleArn value"));+ }++ @Test+ void createDBInstance_withARoleAndAZeroInterval_isRejected() {+ create().formParam("MonitoringRoleArn", ROLE).formParam("MonitoringInterval", "0")+ .when().post("/").then().statusCode(400)+ .body(containsString("InvalidParameterCombination"))+ .body(containsString("You must set MonitoringInterval to a value other than 0"));+ }++ // ModifyDBInstance.MonitoringInterval says "To disable collection of Enhanced Monitoring+ // metrics, specify 0" and says nothing about clearing the role first. The pair rule is worded+ // with "must" only on the create message, so a modify must not be held to it.+ @Test+ void modifyDBInstance_turningMonitoringOffWhileARoleStandsIsAllowed() {+ create().formParam("MonitoringInterval", "30").formParam("MonitoringRoleArn", ROLE)+ .when().post("/").then().statusCode(200);++ rds("ModifyDBInstance")+ .formParam("DBInstanceIdentifier", ID)+ .formParam("MonitoringInterval", "0")+ .when().post("/").then().statusCode(200);++ describe().body(RESULT + "MonitoringInterval", equalTo("0"))+ .body(RESULT + "MonitoringRoleArn", equalTo(ROLE));+ }++ // ModifyDBInstance carries no EnableCloudwatchLogsExports at all. It sends+ // CloudwatchLogsExportConfiguration with EnableLogTypes and DisableLogTypes, applied to the+ // stored set as deltas. Reading the create-only key made a real modify a silent no-op.+ @Test+ void modifyDBInstance_appliesLogExportEnableAndDisableDeltas() {+ create()+ .formParam("MonitoringInterval", "0")+ .formParam("EnableCloudwatchLogsExports.member.1", "postgresql")+ .formParam("EnableCloudwatchLogsExports.member.2", "upgrade")+ .when().post("/").then().statusCode(200);++ rds("ModifyDBInstance")+ .formParam("DBInstanceIdentifier", ID)+ .formParam("CloudwatchLogsExportConfiguration.EnableLogTypes.member.1", "audit")+ .formParam("CloudwatchLogsExportConfiguration.DisableLogTypes.member.1", "upgrade")+ .when().post("/").then().statusCode(200);++ describe()+ .body(RESULT + "EnabledCloudwatchLogsExports.member[0]", equalTo("postgresql"))+ .body(RESULT + "EnabledCloudwatchLogsExports.member[1]", equalTo("audit"));++ String body = rds("DescribeDBInstances").formParam("DBInstanceIdentifier", ID)+ .when().post("/").then().extract().asString();+ assertFalse(body.contains("upgrade"), "a disabled log type is dropped from the set");+ }++ @Test+ void modifyDBInstance_withoutTheExportConfiguration_leavesTheSetAlone() {+ create()+ .formParam("EnableCloudwatchLogsExports.member.1", "postgresql")+ .when().post("/").then().statusCode(200);++ rds("ModifyDBInstance").formParam("DBInstanceIdentifier", ID)+ .formParam("MaxAllocatedStorage", "500")+ .when().post("/").then().statusCode(200);++ describe().body(RESULT + "EnabledCloudwatchLogsExports.member[0]", equalTo("postgresql"));+ }++ @Test+ void createDBInstance_rejectsAPerformanceInsightsRetentionPeriodThatIsNotAllowed() {+ create().formParam("PerformanceInsightsRetentionPeriod", "94")+ .when().post("/").then().statusCode(400)+ .body(containsString("InvalidParameterValue"))+ .body(not(containsString("<DBInstance>")));+ }++ @Test+ void createDBInstance_rejectsAnUnknownEngineLifecycleSupportValue() {+ create().formParam("EngineLifecycleSupport", "open-source-rds-standard-support")+ .when().post("/").then().statusCode(400)+ .body(containsString("InvalidParameterValue"));+ }+}