mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 06:00:46 -05:00
fix(rds): require headroom for enabled storage autoscaling (#5863)
* fix(rds): require headroom for enabled storage autoscaling * fix(rds): retain autoscaling headroom during storage growth * fix(rds): check thresholds against current storage
This commit is contained in:
1 parent
5370920012
commit
043b919e85
4 files changed
+355
No files matched your search
+135
@@ -0,0 +1,135 @@
|
||||
package com.floci.test;
|
||||
|
||||
import org.junit.jupiter.api.Assumptions;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.CsvSource;
|
||||
import software.amazon.awssdk.services.rds.RdsClient;
|
||||
import software.amazon.awssdk.services.rds.model.DBInstance;
|
||||
import software.amazon.awssdk.services.rds.model.DbInstanceNotFoundException;
|
||||
import software.amazon.awssdk.services.rds.model.RdsException;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
||||
@DisplayName("RDS storage autoscaling minimum")
|
||||
class RdsAutoscalingMinimumTest {
|
||||
@ParameterizedTest
|
||||
@CsvSource({"20,21,22", "21,23,24"})
|
||||
void enabledThresholdRequiresTenPercentHeadroom(int allocated, int invalid, int valid) {
|
||||
Assumptions.assumeFalse(TestFixtures.isRealAws(), "Uses a disposable emulator DB instance");
|
||||
String id = TestFixtures.uniqueName("autoscaling-min");
|
||||
try (RdsClient rds = TestFixtures.rdsClient()) {
|
||||
try {
|
||||
create(rds, id, allocated);
|
||||
assertThatThrownBy(() -> rds.modifyDBInstance(r -> r.dbInstanceIdentifier(id)
|
||||
.maxAllocatedStorage(invalid).backupRetentionPeriod(2)))
|
||||
.isInstanceOfSatisfying(RdsException.class, e -> {
|
||||
assertThat(e.statusCode()).isEqualTo(400);
|
||||
assertThat(e.awsErrorDetails().errorCode()).isEqualTo("InvalidParameterCombination");
|
||||
assertThat(e.awsErrorDetails().errorMessage())
|
||||
.isEqualTo("Invalid max storage size for postgres");
|
||||
});
|
||||
assertState(rds, id, allocated, 100, 7);
|
||||
DBInstance modified = rds.modifyDBInstance(r -> r.dbInstanceIdentifier(id)
|
||||
.maxAllocatedStorage(valid).backupRetentionPeriod(2)).dbInstance();
|
||||
assertThat(modified.maxAllocatedStorage()).isEqualTo(valid);
|
||||
assertThat(modified.backupRetentionPeriod()).isEqualTo(2);
|
||||
assertState(rds, id, allocated, valid, 2);
|
||||
} finally {
|
||||
remove(rds, id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource({"30,30,32,false", "30,30,32,true", "21,22,24,false"})
|
||||
void simultaneousGrowthDoesNotAddAnUnverifiedMinimum(int requested, int resolved, int maximum,
|
||||
boolean immediately) {
|
||||
Assumptions.assumeFalse(TestFixtures.isRealAws(), "Uses a disposable emulator DB instance");
|
||||
String id = TestFixtures.uniqueName("autoscaling-min");
|
||||
try (RdsClient rds = TestFixtures.rdsClient()) {
|
||||
try {
|
||||
create(rds, id, 20);
|
||||
DBInstance modified = rds.modifyDBInstance(r -> r.dbInstanceIdentifier(id)
|
||||
.allocatedStorage(requested).maxAllocatedStorage(maximum).backupRetentionPeriod(2)
|
||||
.applyImmediately(immediately)).dbInstance();
|
||||
assertThat(modified.allocatedStorage()).isEqualTo(resolved);
|
||||
assertThat(modified.maxAllocatedStorage()).isEqualTo(maximum);
|
||||
assertState(rds, id, resolved, maximum, 2);
|
||||
} finally {
|
||||
remove(rds, id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource({"19", "0", "-1"})
|
||||
void lowerMaximumRejectsWithoutMutation(int maximum) {
|
||||
Assumptions.assumeFalse(TestFixtures.isRealAws(), "Uses a disposable emulator DB instance");
|
||||
String id = TestFixtures.uniqueName("autoscaling-lower");
|
||||
try (RdsClient rds = TestFixtures.rdsClient()) {
|
||||
try {
|
||||
create(rds, id, 20);
|
||||
assertThatThrownBy(() -> rds.modifyDBInstance(r -> r.dbInstanceIdentifier(id)
|
||||
.maxAllocatedStorage(maximum).backupRetentionPeriod(2)))
|
||||
.isInstanceOfSatisfying(RdsException.class, error -> {
|
||||
assertThat(error.statusCode()).isEqualTo(400);
|
||||
assertThat(error.awsErrorDetails().errorCode()).isEqualTo("InvalidParameterCombination");
|
||||
assertThat(error.awsErrorDetails().errorMessage())
|
||||
.isEqualTo("Invalid max storage size for postgres");
|
||||
});
|
||||
assertState(rds, id, 20, 100, 7);
|
||||
rds.modifyDBInstance(r -> r.dbInstanceIdentifier(id).maxAllocatedStorage(22));
|
||||
assertState(rds, id, 20, 22, 7);
|
||||
} finally {
|
||||
remove(rds, id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void omissionAndDisableRequestsRemainAccepted() {
|
||||
Assumptions.assumeFalse(TestFixtures.isRealAws(), "Uses a disposable emulator DB instance");
|
||||
String id = TestFixtures.uniqueName("autoscaling-min");
|
||||
try (RdsClient rds = TestFixtures.rdsClient()) {
|
||||
try {
|
||||
create(rds, id, 20);
|
||||
rds.modifyDBInstance(r -> r.dbInstanceIdentifier(id).backupRetentionPeriod(2));
|
||||
assertState(rds, id, 20, 100, 2);
|
||||
rds.modifyDBInstance(r -> r.dbInstanceIdentifier(id).maxAllocatedStorage(20)
|
||||
.backupRetentionPeriod(3));
|
||||
DBInstance instance = rds.describeDBInstances(r -> r.dbInstanceIdentifier(id))
|
||||
.dbInstances().get(0);
|
||||
assertThat(instance.allocatedStorage()).isEqualTo(20);
|
||||
assertThat(instance.maxAllocatedStorage()).isEqualTo(20);
|
||||
assertThat(instance.backupRetentionPeriod()).isEqualTo(3);
|
||||
} finally {
|
||||
remove(rds, id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void create(RdsClient rds, String id, int allocated) {
|
||||
rds.createDBInstance(r -> r.dbInstanceIdentifier(id).engine("postgres").dbInstanceClass("db.t3.micro")
|
||||
.masterUsername("adminuser").masterUserPassword("secret123").allocatedStorage(allocated)
|
||||
.maxAllocatedStorage(100).backupRetentionPeriod(7));
|
||||
assertState(rds, id, allocated, 100, 7);
|
||||
}
|
||||
|
||||
private static void assertState(RdsClient rds, String id, int allocated, int maximum, int retention) {
|
||||
DBInstance instance = rds.describeDBInstances(r -> r.dbInstanceIdentifier(id)).dbInstances().get(0);
|
||||
assertThat(instance.allocatedStorage()).isEqualTo(allocated);
|
||||
assertThat(instance.maxAllocatedStorage()).isEqualTo(maximum);
|
||||
assertThat(instance.backupRetentionPeriod()).isEqualTo(retention);
|
||||
}
|
||||
|
||||
private static void remove(RdsClient rds, String id) {
|
||||
try {
|
||||
rds.deleteDBInstance(r -> r.dbInstanceIdentifier(id).skipFinalSnapshot(true));
|
||||
} catch (DbInstanceNotFoundException ignored) {
|
||||
// Cleanup is registered before creation, so setup failure may leave no instance.
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -441,6 +441,28 @@ Two deviations are worth knowing:
|
||||
`StorageType`, `MultiAZ` and `Iops` are not read on a modify yet. Floci reports every instance as
|
||||
`gp2`.
|
||||
|
||||
### Storage autoscaling threshold changes
|
||||
|
||||
For standalone instances with instance-owned storage, `ModifyDBInstance` checks an explicit
|
||||
`MaxAllocatedStorage` against the current allocation. The threshold must be at least 10% higher,
|
||||
except that a value equal to the current allocation retains the existing disable handling.
|
||||
For example, with 20 GiB allocated, maxima of 19 or 21 GiB are refused and 22 GiB meets this
|
||||
minimum. Explicit zero and negative maxima are also refused. Rejection occurs before any settings
|
||||
in the request change, including backup retention and allocation. An omitted maximum retains its
|
||||
stored value without rechecking historical state.
|
||||
|
||||
The check uses the current allocation even when the request also changes storage. AWS applies
|
||||
threshold changes immediately while storage changes can wait for maintenance. Floci's existing
|
||||
immediate storage-change behavior remains; this is not a live AWS combined-growth capture or a
|
||||
complete check of all combined-update constraints.
|
||||
|
||||
Aurora/cluster members and RDS Custom remain outside this check. Engine/class upper limits,
|
||||
IOPS ratios and create/restore/replica constraints remain separate. The chosen HTTP 400
|
||||
`InvalidParameterCombination` follows the adjacent allocated-storage refusal precedent. The
|
||||
message follows the guide's example, `Invalid max storage size for {engine_name}`; neither is
|
||||
claimed as an independently captured, universal live AWS maximum-error response.
|
||||
|
||||
|
||||
## Examples
|
||||
|
||||
```bash
|
||||
|
||||
@@ -3074,6 +3074,7 @@ public class RdsService implements Resettable, ResourceProvider {
|
||||
// current size and engine version: a refusal here must leave the whole request unapplied.
|
||||
DbInstanceScalingChanges resolvedScaling = scaling.resolveFor(instance);
|
||||
DbInstanceSettings effective = withEffectiveWindows(settings, instance);
|
||||
validateAutoscalingMinimum(instance, effective.maxAllocatedStorage());
|
||||
instance.setStatus(DbInstanceStatus.AVAILABLE);
|
||||
if (optionGroupName != null && !optionGroupName.isBlank()) {
|
||||
validateInstanceOptionGroup(optionGroupName,
|
||||
@@ -3146,6 +3147,22 @@ public class RdsService implements Resettable, ResourceProvider {
|
||||
settings.validate();
|
||||
}
|
||||
|
||||
private static void validateAutoscalingMinimum(DbInstance instance, Integer maximum) {
|
||||
String clusterId = instance.getDbClusterIdentifier();
|
||||
String engine = engineName(instance);
|
||||
int allocated = instance.getAllocatedStorage();
|
||||
if (maximum == null || allocated <= 0 || maximum == allocated
|
||||
|| clusterId != null && !clusterId.isBlank()
|
||||
|| isAuroraEngine(engine)
|
||||
|| engine != null && engine.toLowerCase(Locale.ROOT).startsWith("custom-")) {
|
||||
return;
|
||||
}
|
||||
if ((long) maximum * 10 < (long) allocated * 11) {
|
||||
throw new AwsException("InvalidParameterCombination",
|
||||
"Invalid max storage size for " + (engine == null ? null : engine.toLowerCase(Locale.ROOT)), 400);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* AWS's conditional default for {@code PubliclyAccessible} when {@code CreateDBInstance}
|
||||
* omits it: with no subnet group given, Aurora engines default to not-publicly-accessible and
|
||||
|
||||
+181
@@ -0,0 +1,181 @@
|
||||
package io.github.hectorvent.floci.services.rds;
|
||||
|
||||
import io.github.hectorvent.floci.testing.RdsMockProfile;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.quarkus.test.junit.TestProfile;
|
||||
import io.restassured.response.Response;
|
||||
import io.restassured.response.ValidatableResponse;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.CsvSource;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static io.github.hectorvent.floci.testing.RdsRequests.rds;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.jupiter.api.Assertions.assertAll;
|
||||
|
||||
@QuarkusTest
|
||||
@TestProfile(RdsMockProfile.class)
|
||||
class RdsAutoscalingMinimumIntegrationTest {
|
||||
private static final String RESULT =
|
||||
"DescribeDBInstancesResponse.DescribeDBInstancesResult.DBInstances.DBInstance.";
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource({"19", "0", "-1"})
|
||||
void lowerMaximumRejectsWithoutChangingAnySetting(int maximum) {
|
||||
String id = "autoscaling-lower-" + UUID.randomUUID();
|
||||
try {
|
||||
create(id, 20);
|
||||
Response response = modify(id).formParam("MaxAllocatedStorage", maximum)
|
||||
.formParam("BackupRetentionPeriod", 2).post("/");
|
||||
Response stored = describe(id).extract().response();
|
||||
assertAll("only equality is the disable exception",
|
||||
() -> response.then().statusCode(400)
|
||||
.body("ErrorResponse.Error.Code", equalTo("InvalidParameterCombination"))
|
||||
.body("ErrorResponse.Error.Message", equalTo("Invalid max storage size for postgres")),
|
||||
() -> stored.then().body(RESULT + "AllocatedStorage", equalTo("20")),
|
||||
() -> stored.then().body(RESULT + "MaxAllocatedStorage", equalTo("100")),
|
||||
() -> stored.then().body(RESULT + "BackupRetentionPeriod", equalTo("7")));
|
||||
modify(id).formParam("MaxAllocatedStorage", 22).post("/").then().statusCode(200);
|
||||
describe(id).body(RESULT + "MaxAllocatedStorage", equalTo("22"));
|
||||
} finally {
|
||||
remove(id);
|
||||
}
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource({"20,21,22,false", "21,23,24,false", "20,21,22,true"})
|
||||
void insufficientEnabledMaximumRejectsTheWholeModification(int allocated, int invalid, int valid,
|
||||
boolean growAllocation) {
|
||||
String id = "autoscaling-min-" + UUID.randomUUID();
|
||||
try {
|
||||
create(id, allocated);
|
||||
RequestSpecification request = modify(id).formParam("MaxAllocatedStorage", invalid)
|
||||
.formParam("BackupRetentionPeriod", 2);
|
||||
if (growAllocation) {
|
||||
request.formParam("AllocatedStorage", allocated + 1);
|
||||
}
|
||||
Response response = request.post("/");
|
||||
Response stored = describe(id).extract().response();
|
||||
assertAll("invalid maximum refuses before any setting or allocation changes",
|
||||
() -> response.then().statusCode(400)
|
||||
.body("ErrorResponse.Error.Code", equalTo("InvalidParameterCombination"))
|
||||
.body("ErrorResponse.Error.Message", equalTo("Invalid max storage size for postgres")),
|
||||
() -> stored.then().body(RESULT + "MaxAllocatedStorage", equalTo("100")),
|
||||
() -> stored.then().body(RESULT + "BackupRetentionPeriod", equalTo("7")),
|
||||
() -> stored.then().body(RESULT + "AllocatedStorage", equalTo(Integer.toString(allocated))));
|
||||
modify(id).formParam("MaxAllocatedStorage", valid).formParam("BackupRetentionPeriod", 2)
|
||||
.post("/").then().statusCode(200);
|
||||
describe(id).body(RESULT + "MaxAllocatedStorage", equalTo(Integer.toString(valid)))
|
||||
.body(RESULT + "BackupRetentionPeriod", equalTo("2"))
|
||||
.body(RESULT + "AllocatedStorage", equalTo(Integer.toString(allocated)));
|
||||
} finally {
|
||||
remove(id);
|
||||
}
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource({"30,30,32,false", "30,30,32,true", "21,22,24,false"})
|
||||
void simultaneousGrowthDoesNotAddAnUnverifiedMinimum(int requested, int resolved, int maximum,
|
||||
boolean immediately) {
|
||||
String id = "autoscaling-min-" + UUID.randomUUID();
|
||||
try {
|
||||
create(id, 20);
|
||||
modify(id).formParam("AllocatedStorage", requested).formParam("MaxAllocatedStorage", maximum)
|
||||
.formParam("BackupRetentionPeriod", 2).formParam("ApplyImmediately", immediately)
|
||||
.post("/").then().statusCode(200);
|
||||
// Floci applies storage changes immediately; this is not a live AWS combined-growth capture.
|
||||
describe(id).body(RESULT + "AllocatedStorage", equalTo(Integer.toString(resolved)))
|
||||
.body(RESULT + "MaxAllocatedStorage", equalTo(Integer.toString(maximum)))
|
||||
.body(RESULT + "BackupRetentionPeriod", equalTo("2"));
|
||||
} finally {
|
||||
remove(id);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void omittedMaximumRetainsTheExistingThreshold() {
|
||||
String id = "autoscaling-min-" + UUID.randomUUID();
|
||||
try {
|
||||
create(id, 20);
|
||||
modify(id).formParam("BackupRetentionPeriod", 2).post("/").then().statusCode(200);
|
||||
describe(id).body(RESULT + "MaxAllocatedStorage", equalTo("100"))
|
||||
.body(RESULT + "BackupRetentionPeriod", equalTo("2"));
|
||||
} finally {
|
||||
remove(id);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void equalMaximumKeepsTheExistingDisableRequestAccepted() {
|
||||
String id = "autoscaling-min-" + UUID.randomUUID();
|
||||
try {
|
||||
create(id, 20);
|
||||
modify(id).formParam("MaxAllocatedStorage", 20).formParam("BackupRetentionPeriod", 2)
|
||||
.post("/").then().statusCode(200);
|
||||
// Preserve the existing emulator representation, without claiming AWS normalization.
|
||||
describe(id).body(RESULT + "BackupRetentionPeriod", equalTo("2"))
|
||||
.body(RESULT + "MaxAllocatedStorage", equalTo("20"))
|
||||
.body(RESULT + "AllocatedStorage", equalTo("20"));
|
||||
} finally {
|
||||
remove(id);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void clusterMemberThresholdHandlingRemainsSeparate() {
|
||||
String id = "autoscaling-min-" + UUID.randomUUID();
|
||||
String cluster = "autoscaling-cluster-" + UUID.randomUUID();
|
||||
try {
|
||||
rds("CreateDBCluster").formParam("DBClusterIdentifier", cluster)
|
||||
.formParam("Engine", "aurora-postgresql").formParam("MasterUsername", "adminuser")
|
||||
.formParam("MasterUserPassword", "secret123").post("/").then().statusCode(200);
|
||||
rds("CreateDBInstance").formParam("DBInstanceIdentifier", id)
|
||||
.formParam("DBClusterIdentifier", cluster).formParam("Engine", "aurora-postgresql")
|
||||
.formParam("DBInstanceClass", "db.t3.micro").formParam("AllocatedStorage", 20)
|
||||
.formParam("MaxAllocatedStorage", 100).post("/").then().statusCode(200);
|
||||
describe(id).body(RESULT + "AllocatedStorage", equalTo("20"));
|
||||
modify(id).formParam("MaxAllocatedStorage", 21).post("/").then().statusCode(200);
|
||||
describe(id).body(RESULT + "MaxAllocatedStorage", equalTo("21"));
|
||||
} finally {
|
||||
assertAll("remove member and cluster even after partial setup",
|
||||
() -> remove(id),
|
||||
() -> {
|
||||
Response response = rds("DeleteDBCluster").formParam("DBClusterIdentifier", cluster)
|
||||
.formParam("SkipFinalSnapshot", true).post("/");
|
||||
if (response.statusCode() != 404) {
|
||||
response.then().statusCode(200);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private static void create(String id, int allocated) {
|
||||
rds("CreateDBInstance").formParam("DBInstanceIdentifier", id).formParam("Engine", "postgres")
|
||||
.formParam("DBInstanceClass", "db.t3.micro").formParam("MasterUsername", "adminuser")
|
||||
.formParam("MasterUserPassword", "secret123").formParam("AllocatedStorage", allocated)
|
||||
.formParam("MaxAllocatedStorage", 100).formParam("BackupRetentionPeriod", 7)
|
||||
.post("/").then().statusCode(200);
|
||||
describe(id).body(RESULT + "AllocatedStorage", equalTo(Integer.toString(allocated)))
|
||||
.body(RESULT + "MaxAllocatedStorage", equalTo("100"))
|
||||
.body(RESULT + "BackupRetentionPeriod", equalTo("7"));
|
||||
}
|
||||
|
||||
private static RequestSpecification modify(String id) {
|
||||
return rds("ModifyDBInstance").formParam("DBInstanceIdentifier", id);
|
||||
}
|
||||
|
||||
private static ValidatableResponse describe(String id) {
|
||||
return rds("DescribeDBInstances").formParam("DBInstanceIdentifier", id).post("/").then().statusCode(200);
|
||||
}
|
||||
|
||||
private static void remove(String id) {
|
||||
Response response = rds("DeleteDBInstance").formParam("DBInstanceIdentifier", id)
|
||||
.formParam("SkipFinalSnapshot", true).post("/");
|
||||
if (response.statusCode() != 404) {
|
||||
response.then().statusCode(200);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user