fix(rds): report the monitoring and lifecycle settings a DB instance was given (#3688)

* fix(rds): report the monitoring and lifecycle settings a DB instance was given

CreateDBInstance and ModifyDBInstance accepted MonitoringInterval,
MonitoringRoleArn, EnablePerformanceInsights,
PerformanceInsightsRetentionPeriod, EngineLifecycleSupport,
EnableCloudwatchLogsExports and MaxAllocatedStorage, then dropped every one of
them. DescribeDBInstances reported none, so a caller that set them read its own
configuration back as absent and treated the instance as changed.

DbInstanceSettings carries the seven, DescribeDBInstances writes them, and each
one takes the default its member documents. MonitoringInterval defaults to 0,
PerformanceInsightsRetentionPeriod to 7 days and EngineLifecycleSupport to
open-source-rds-extended-support. MaxAllocatedStorage and
EnabledCloudwatchLogsExports stay absent when storage autoscaling is off and no
log type is exported, matching what a live account returns. The valid values
each member documents are enforced, so 45 as a monitoring interval and 94 as a
retention period are rejected the way AWS rejects them.

withEffectiveWindows rebuilt the settings through the constructor and would
have dropped the new members, so it now goes through withWindows, which keeps
every member it is not resolving.

* fix(rds): require a monitoring role whenever the interval is not zero

Review feedback on #3688. MonitoringInterval and MonitoringRoleArn are
documented as a pair, in both directions and on both CreateDBInstance and
ModifyDBInstance. An interval other than 0 needs a role, and a role needs an
interval other than 0. The other rules on these members were already enforced
and this was the piece left out.

The check takes the values that will be in effect rather than the ones the
request carried. A modify may raise the interval on an instance that already
holds a role, or attach a role to an instance whose interval is already
non-zero, and judging the request alone would refuse both.

Three tests cover a create with an interval and no role, a create with a role
and a zero interval, and a modify that turns monitoring off while a role stands.
The existing modify test now raises the interval without naming a role, which
proves the effective-value reading.

Also turns the three inline fully-qualified names in the test into imports, per
the review.

* fix(rds): keep ModifyDBInstance to its own monitoring and log-export contract

Two review blockers on #3688, both from ModifyDBInstance being held to
CreateDBInstance's shape.

The pair rule is create-only. CreateDBInstanceMessage words it with "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
refused the documented way to turn monitoring off, and the previous test pinned
that as if it were correct. It now asserts the opposite.

ModifyDBInstance carries no EnableCloudwatchLogsExports at all. It sends
CloudwatchLogsExportConfiguration with EnableLogTypes and DisableLogTypes,
applied to the stored set as deltas. The shared parser only looked for the
create-only key, so a real request to change exports on a live instance was a
silent no-op. Modify now has its own branch, the way StorageEncrypted and
KmsKeyId already do behind includeEncryption, and LogExportChanges folds the two
lists into what the instance holds.

Three tests cover it. Disabling by interval 0 while the role stands is accepted
and both values are reported. An enable and a disable are applied together. A
modify that omits the configuration leaves the set alone. Neutralising the parse
turns the delta test red.
This commit is contained in:
lex00 authored and GitHub committed 2026-09-18 16:30:51 -04:00
1 parent 00d1037635
commit c664b9e136
6 files changed
+486 -6

No files matched your search

@@ -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"));
}
}