Skip to content

Ministack: Free, open-source local AWS emulator - 60+ services, Terraform compatible, real databases. Free forever. MIT licensed.

fix(rds): inherit cluster Performance Insights (#2447)

Jay Janssen0b9a3bddfd14
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8f85a995..05960780 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,6 +11,7 @@ Versioning follows [Semantic Versioning](https://semver.org/).
- **Aurora DSQL — `AWS IAM GRANT` and `AWS IAM REVOKE`** — with `DSQL_STRICT=1` both were a syntax error, so a migration that maps a Postgres role to an IAM role stopped there. Sent on their own over the simple query protocol (psql, psycopg2), a GRANT maps one or more ARNs to a role and a REVOKE unmaps them; the mappings read back through `sys.iam_pg_role_mappings` with DSQL's six columns and types, a rollback undoes a GRANT, and a GRANT after other DDL in the same transaction answers DSQL's `0A000`. Re-granting raises DSQL's NOTICE and revoking a missing mapping its WARNING; an unknown role answers `42704`, a value that is not an ARN `0P000`, and granting the signed-in role to itself `42501`. Contributed by @toby6578.
### Fixed
+- **RDS — Aurora cluster Performance Insights inheritance** — explicit cluster PI settings now round-trip through create/modify/describe and propagate to existing and future members. Instance-managed clusters retain their independent settings until an explicit cluster handoff. Enabled responses include the retention and PI KMS key; cluster disablement survives removal of all members.
- **Athena — the result file is saved at the reported `OutputLocation`** — a query's `<id>.csv` and `<id>.csv.metadata` are now saved directly under the result location, at the path that `GetQueryExecution` reports, as AWS does. Before, they were saved one folder too deep, at `<location>/<id>.csv/<id>.csv`, so a client that read the reported path got `NoSuchKey`.
- **Athena — an enforced workgroup overrides the client-side result location** — when a workgroup has `EnforceWorkGroupConfiguration: true`, `StartQueryExecution` now writes results to the workgroup's `OutputLocation`, even when the request gives its own `ResultConfiguration.OutputLocation`, as AWS does. Before, the request's location was used.
- **Lambda — a partial ARN as the `FunctionName`** — `123456789012:function:my-function[:qualifier]` resolved to the account ID as the function name, so `Invoke` and the other function operations failed with `Function not found: ...:function:123456789012`; it now resolves as the full ARN in the caller's region, as on AWS, and gives the same result as that full ARN.
diff --git a/ministack/services/rds.py b/ministack/services/rds.py
index fe39f6bb..baeff3a7 100644
--- a/ministack/services/rds.py
+++ b/ministack/services/rds.py
@@ -56,6 +56,7 @@ import socket
import tarfile
import threading
import time
+import uuid
from urllib.parse import parse_qs
from xml.sax.saxutils import escape as _esc
@@ -5051,6 +5052,9 @@ def _create_db_instance_impl(p):
"_internal_port": internal_port,
"_MasterUserPassword": master_pass,
}
+ _set_performance_insights(instance, p)
+ if parent and parent.get("_PerformanceInsightsManaged"):
+ _inherit_performance_insights(instance, parent)
# Only a request that turns storage autoscaling on sets the threshold.
if _p(p, "MaxAllocatedStorage"):
instance["MaxAllocatedStorage"] = int(_p(p, "MaxAllocatedStorage"))
@@ -5895,6 +5899,46 @@ def _restore_from_snapshot(p):
# DB Clusters
# ---------------------------------------------------------------------------
+_PERFORMANCE_INSIGHTS_FIELDS = (
+ "PerformanceInsightsEnabled", "PerformanceInsightsRetentionPeriod",
+ "PerformanceInsightsKMSKeyId",
+)
+
+
+def _set_performance_insights(resource, params):
+ """Apply explicit PI policy; omission preserves legacy instance management."""
+ if not any(name in params for name in (
+ "EnablePerformanceInsights", "PerformanceInsightsRetentionPeriod",
+ "PerformanceInsightsKMSKeyId",
+ )):
+ return False
+ enabled = _p(params, "EnablePerformanceInsights")
+ if enabled:
+ resource["PerformanceInsightsEnabled"] = enabled == "true"
+ if not resource.get("PerformanceInsightsEnabled"):
+ resource.pop("PerformanceInsightsRetentionPeriod", None)
+ resource.pop("PerformanceInsightsKMSKeyId", None)
+ return True
+ resource["PerformanceInsightsRetentionPeriod"] = int(
+ _p(params, "PerformanceInsightsRetentionPeriod")
+ or resource.get("PerformanceInsightsRetentionPeriod", 7)
+ )
+ key = _p(params, "PerformanceInsightsKMSKeyId") or resource.get("PerformanceInsightsKMSKeyId")
+ if not key or key == "alias/aws/rds":
+ key_id = uuid.uuid5(uuid.NAMESPACE_URL, f"rds:{get_account_id()}:{get_region()}")
+ key = f"arn:aws:kms:{get_region()}:{get_account_id()}:key/{key_id}"
+ resource["PerformanceInsightsKMSKeyId"] = key
+ return True
+
+
+def _inherit_performance_insights(instance, cluster):
+ for field in _PERFORMANCE_INSIGHTS_FIELDS:
+ if field in cluster:
+ instance[field] = cluster[field]
+ else:
+ instance.pop(field, None)
+
+
def _serverlessv2_from_params(p):
"""Read ServerlessV2ScalingConfiguration.{Min,Max}Capacity from query params.
@@ -6142,6 +6186,9 @@ def _create_db_cluster_impl(p):
"_shared_container_epoch": 0,
"_shared_storage_initialized": False,
}
+ if _set_performance_insights(cluster, p):
+ cluster["_PerformanceInsightsManaged"] = True
+ cluster["DatabaseInsightsMode"] = "standard"
_prepare_mysql_gtid_history(cluster)
_clusters[cluster_id] = cluster
if global_cluster:
@@ -6521,6 +6568,13 @@ def _modify_db_cluster_impl(p):
{"VpcSecurityGroupId": sg, "Status": "active"} for sg in vpc_sgs
]
+ if _set_performance_insights(cluster, p):
+ cluster["_PerformanceInsightsManaged"] = True
+ cluster.setdefault("DatabaseInsightsMode", "standard")
+ for instance in _instances.values():
+ if instance.get("DBClusterIdentifier") == cluster["DBClusterIdentifier"]:
+ _inherit_performance_insights(instance, cluster)
+
return _xml(200, "ModifyDBClusterResponse",
f"<ModifyDBClusterResult><DBCluster>{_cluster_xml(cluster)}</DBCluster></ModifyDBClusterResult>")
@@ -9609,7 +9663,8 @@ def _instance_xml(i):
<DBInstanceArn>{i['DBInstanceArn']}</DBInstanceArn>
<IAMDatabaseAuthenticationEnabled>{str(i.get('IAMDatabaseAuthenticationEnabled',False)).lower()}</IAMDatabaseAuthenticationEnabled>
<PerformanceInsightsEnabled>{str(i.get('PerformanceInsightsEnabled',False)).lower()}</PerformanceInsightsEnabled>
- <PerformanceInsightsRetentionPeriod>{i.get('PerformanceInsightsRetentionPeriod',7)}</PerformanceInsightsRetentionPeriod>
+ {_performance_insights_details_xml(i)}
+ <DatabaseInsightsMode>{i.get('DatabaseInsightsMode', 'standard')}</DatabaseInsightsMode>
<EnabledCloudwatchLogsExports/>
<ProcessorFeatures/>
<DeletionProtection>{str(i.get('DeletionProtection',False)).lower()}</DeletionProtection>
@@ -9636,6 +9691,15 @@ def _serverlessv2_xml(c):
)
+def _performance_insights_details_xml(resource):
+ if not resource.get("PerformanceInsightsEnabled"):
+ return ""
+ return (
+ f"<PerformanceInsightsRetentionPeriod>{resource.get('PerformanceInsightsRetentionPeriod', 7)}</PerformanceInsightsRetentionPeriod>"
+ f"<PerformanceInsightsKMSKeyId>{_esc(resource.get('PerformanceInsightsKMSKeyId', ''))}</PerformanceInsightsKMSKeyId>"
+ )
+
+
def _cluster_xml(c):
"""Render a cluster dict to XML fields."""
vpc_sg_xml = ""
@@ -9720,6 +9784,9 @@ def _cluster_xml(c):
<KmsKeyId>{c.get('KmsKeyId','')}</KmsKeyId>
<DeletionProtection>{str(c.get('DeletionProtection',False)).lower()}</DeletionProtection>
<IAMDatabaseAuthenticationEnabled>{str(c.get('IAMDatabaseAuthenticationEnabled',False)).lower()}</IAMDatabaseAuthenticationEnabled>
+ <PerformanceInsightsEnabled>{str(c.get('PerformanceInsightsEnabled',False)).lower()}</PerformanceInsightsEnabled>
+ {_performance_insights_details_xml(c)}
+ <DatabaseInsightsMode>{c.get('DatabaseInsightsMode', 'standard')}</DatabaseInsightsMode>
<HttpEndpointEnabled>{str(c.get('HttpEndpointEnabled',False)).lower()}</HttpEndpointEnabled>
<CopyTagsToSnapshot>{str(c.get('CopyTagsToSnapshot',False)).lower()}</CopyTagsToSnapshot>
<CrossAccountClone>{str(c.get('CrossAccountClone',False)).lower()}</CrossAccountClone>
diff --git a/tests/test_rds.py b/tests/test_rds.py
index 80fcb23f..0787ad63 100644
--- a/tests/test_rds.py
+++ b/tests/test_rds.py
@@ -17144,3 +17144,86 @@ def test_rds_settings_outside_pending_modified_values_apply_immediately(imm_stat
assert status == 200
assert instance[param] == stored
assert instance["PendingModifiedValues"] == {}
+
+
+# AWS observations (2026-10-27, us-east-1, disposable Aurora MySQL 3.10.3 /
+# PostgreSQL 17.9): same-value ModifyDBCluster handoff preserves seven-day PI,
+# a new reader inherits the policy, and cluster disablement reaches both members.
+# CreateDBCluster explicit settings follow the documented cluster-level API;
+# tests deliberately leave omission as legacy instance-managed behavior.
[email protected]("engine", ["aurora-mysql", "aurora-postgresql"])
+def test_rds_cluster_performance_insights_handoff(imm_state, monkeypatch, engine):
+ monkeypatch.setattr(_imm_rds, "_get_docker", lambda: None)
+ client = _imm_sdk()
+ cluster_id = "pi-handoff"
+ key = f"arn:aws:kms:{_IMM_REGION}:{_IMM_ACCOUNT}:key/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"
+ cluster = client.create_db_cluster(
+ DBClusterIdentifier=cluster_id, Engine=engine,
+ MasterUsername="admin", MasterUserPassword="password123",
+ )["DBCluster"]
+ assert cluster["PerformanceInsightsEnabled"] is False
+ writer = client.create_db_instance(
+ DBInstanceIdentifier="pi-writer", DBClusterIdentifier=cluster_id,
+ Engine=engine, DBInstanceClass="db.r6g.large",
+ EnablePerformanceInsights=True, PerformanceInsightsRetentionPeriod=7,
+ PerformanceInsightsKMSKeyId=key,
+ )["DBInstance"]
+ assert writer["PerformanceInsightsEnabled"] is True
+ assert writer["PerformanceInsightsKMSKeyId"] == key
+ assert writer["PerformanceInsightsRetentionPeriod"] == 7
+ migrated = client.modify_db_cluster(
+ DBClusterIdentifier=cluster_id, ApplyImmediately=True,
+ EnablePerformanceInsights=True, PerformanceInsightsRetentionPeriod=7,
+ PerformanceInsightsKMSKeyId=key,
+ )["DBCluster"]
+ assert migrated["PerformanceInsightsEnabled"] is True
+ assert migrated["PerformanceInsightsKMSKeyId"] == key
+ assert migrated["PerformanceInsightsRetentionPeriod"] == 7
+ assert migrated["DatabaseInsightsMode"] == "standard"
+ client.create_db_instance(
+ DBInstanceIdentifier="pi-reader", DBClusterIdentifier=cluster_id,
+ Engine=engine, DBInstanceClass="db.r6g.large",
+ )
+ for instance in client.describe_db_instances()["DBInstances"]:
+ assert instance["PerformanceInsightsEnabled"] is True
+ assert instance["PerformanceInsightsKMSKeyId"] == key
+ assert instance["PerformanceInsightsRetentionPeriod"] == 7
+ assert instance["DatabaseInsightsMode"] == "standard"
+ client.modify_db_cluster(DBClusterIdentifier=cluster_id, EnablePerformanceInsights=False)
+ for instance in client.describe_db_instances()["DBInstances"]:
+ assert instance["PerformanceInsightsEnabled"] is False
+ assert "PerformanceInsightsKMSKeyId" not in instance
+ assert "PerformanceInsightsRetentionPeriod" not in instance
+ # Disabling remains cluster-managed after the last member is removed.
+ for identifier in ("pi-writer", "pi-reader"):
+ client.delete_db_instance(DBInstanceIdentifier=identifier, SkipFinalSnapshot=True)
+ replacement = client.create_db_instance(
+ DBInstanceIdentifier="pi-replacement", DBClusterIdentifier=cluster_id,
+ Engine=engine, DBInstanceClass="db.r6g.large",
+ )["DBInstance"]
+ assert replacement["PerformanceInsightsEnabled"] is False
+ assert client.describe_db_clusters(DBClusterIdentifier=cluster_id)["DBClusters"][0]["DatabaseInsightsMode"] == "standard"
+
+
[email protected]("enabled", [True, False])
+def test_rds_cluster_performance_insights_explicit_create(imm_state, monkeypatch, enabled):
+ monkeypatch.setattr(_imm_rds, "_get_docker", lambda: None)
+ client = _imm_sdk()
+ cluster = client.create_db_cluster(
+ DBClusterIdentifier="pi-new", Engine="aurora-mysql",
+ MasterUsername="admin", MasterUserPassword="password123",
+ EnablePerformanceInsights=enabled,
+ )["DBCluster"]
+ member = client.create_db_instance(
+ DBInstanceIdentifier="pi-new-member", DBClusterIdentifier="pi-new",
+ Engine="aurora-mysql", DBInstanceClass="db.r6g.large",
+ )["DBInstance"]
+ assert cluster["PerformanceInsightsEnabled"] is enabled
+ assert member["PerformanceInsightsEnabled"] is enabled
+ if enabled:
+ assert member["PerformanceInsightsRetentionPeriod"] == 7
+ assert member["PerformanceInsightsKMSKeyId"] == cluster["PerformanceInsightsKMSKeyId"]
+ assert member["PerformanceInsightsKMSKeyId"].startswith(f"arn:aws:kms:{_IMM_REGION}:{_IMM_ACCOUNT}:key/")
+ else:
+ assert "PerformanceInsightsKMSKeyId" not in cluster
+ assert "PerformanceInsightsRetentionPeriod" not in member