fix(rds): keep DB proxies across restarts in file-backed storage (#8970)

DbProxy.getEndpoint() is a getter with no setter, so the storage mapper wrote an "endpoint" field to rds-proxies.json and then refused it as unknown on load. The file was quarantined and every DB proxy was lost on restart in persistent, hybrid and wal modes. The mapper now ignores the getter; endpointHost is still stored, and the RDS response and the CloudFormation Endpoint attribute still read it.

Closes #8968
This commit is contained in:
Ignas authored and GitHub committed 2026-11-19 10:47:56 -04:00
1 parent 5a0529ba31
commit 6f71e2877f
3 files changed
+78

No files matched your search

@@ -1,5 +1,6 @@
package io.floci.aws.services.rds.model;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.quarkus.runtime.annotations.RegisterForReflection;
import java.time.Instant;
@@ -43,6 +44,7 @@ public class DbProxy {
public DbProxy() {}
/** AWS RDS Proxy exposes a bare hostname and clients connect on the engine's default port. */
@JsonIgnore
public String getEndpoint() {
return endpointHost;
}
@@ -8931,6 +8931,46 @@ class RdsServiceTest {
assertTrue(targetGroup.getTargetGroupArn().contains(":target-group:prx-tg-"));
}
@Test
void proxyAndItsTargetGroupSurviveRestartThroughJsonStorage(@TempDir Path tempDir) {
Path proxyFile = tempDir.resolve("rds-proxies.json");
Path targetGroupFile = tempDir.resolve("rds-proxy-target-groups.json");
TypeReference<Map<String, DbProxy>> proxyType = new TypeReference<>() {};
TypeReference<Map<String, DbProxyTargetGroup>> targetGroupType = new TypeReference<>() {};
RdsService first = proxyStoreService(regionResolver, config,
new PersistentStorage<>(proxyFile, proxyType),
new PersistentStorage<>(targetGroupFile, targetGroupType),
new InMemoryStorage<>(), new InMemoryStorage<>());
DbProxy proxy = first.createDbProxy("restart-proxy", "POSTGRESQL", true, false, PROXY_ROLE_ARN,
PROXY_SUBNET_IDS, List.of(), PROXY_AUTH, Map.of());
DbProxyTargetGroup targetGroup = first.configureDbProxyTargetGroup("restart-proxy", "default",
70, 30, 45, "SET search_path TO app", List.of("EXCLUDE_VARIABLE_SETS"), "us-east-1");
PersistentStorage<String, DbProxy> reloadedProxies = new PersistentStorage<>(proxyFile, proxyType);
reloadedProxies.load();
PersistentStorage<String, DbProxyTargetGroup> reloadedTargetGroups =
new PersistentStorage<>(targetGroupFile, targetGroupType);
reloadedTargetGroups.load();
assertEquals("restart-proxy",
reloadedTargetGroups.get("us-east-1::restart-proxy").orElseThrow().getDbProxyName());
RdsService restarted = proxyStoreService(regionResolver, config, reloadedProxies, reloadedTargetGroups,
new InMemoryStorage<>(), new InMemoryStorage<>());
restarted.restorePersistedRuntime();
DbProxy restoredProxy = restarted.getDbProxy("restart-proxy");
assertEquals(proxy.getDbProxyArn(), restoredProxy.getDbProxyArn());
assertEquals(proxy.getProxyPort(), restoredProxy.getProxyPort());
DbProxyTargetGroup restoredGroup =
restarted.describeDbProxyTargetGroups("restart-proxy").iterator().next();
assertEquals("restart-proxy", restoredGroup.getDbProxyName());
assertEquals(targetGroup.getTargetGroupArn(), restoredGroup.getTargetGroupArn());
assertEquals(70, restoredGroup.getMaxConnectionsPercent());
assertEquals(30, restoredGroup.getMaxIdleConnectionsPercent());
assertEquals(45, restoredGroup.getConnectionBorrowTimeout());
assertEquals("SET search_path TO app", restoredGroup.getInitQuery());
assertEquals(List.of("EXCLUDE_VARIABLE_SETS"), restoredGroup.getSessionPinningFilters());
}
@Test
void createDbProxyRejectsDuplicate() {
rdsService.createDbProxy("app-proxy", "POSTGRESQL", true, false, PROXY_ROLE_ARN,
@@ -0,0 +1,36 @@
package io.floci.aws.services.rds.model;
import com.fasterxml.jackson.core.type.TypeReference;
import io.floci.aws.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;
class DbProxyPersistenceTest {
@Test
void proxyPersistsAcrossInstances(@TempDir Path directory) {
Path file = directory.resolve("rds-proxies.json");
DbProxy proxy = new DbProxy();
proxy.setDbProxyName("restart-proxy");
proxy.setEngineFamily("POSTGRESQL");
proxy.setEndpointHost("restart-proxy.proxy-000000000000.us-east-1.rds.amazonaws.com");
proxy.setProxyPort(5433);
new PersistentStorage<String, DbProxy>(file, new TypeReference<Map<String, DbProxy>>() {})
.put(proxy.getDbProxyName(), proxy);
PersistentStorage<String, DbProxy> reader = new PersistentStorage<>(
file, new TypeReference<Map<String, DbProxy>>() {});
reader.load();
DbProxy restored = reader.get("restart-proxy").orElseThrow();
assertEquals("POSTGRESQL", restored.getEngineFamily());
assertEquals("restart-proxy.proxy-000000000000.us-east-1.rds.amazonaws.com", restored.getEndpoint());
assertEquals(5433, restored.getProxyPort());
}
}