fix(dynamodb): report WarmThroughput on each global secondary index (#7120)

This commit is contained in:
Aymen JAMAAOUI authored and GitHub committed 2026-10-31 14:59:30 -04:00
1 parent f74744dc5f
commit 2eb75ee686
3 files changed
+115 -1

No files matched your search

@@ -77,6 +77,8 @@ class DynamoDbBackupIntegrationTest {
equalTo("gsi1"))
.body("BackupDescription.SourceTableFeatureDetails.GlobalSecondaryIndexes[0]",
not(hasKey("IndexStatus")))
.body("BackupDescription.SourceTableFeatureDetails.GlobalSecondaryIndexes[0]",
not(hasKey("WarmThroughput")))
.body("BackupDescription.SourceTableFeatureDetails.LocalSecondaryIndexes[0].IndexName",
equalTo("lsi1"))
.body("BackupDescription.SourceTableFeatureDetails.LocalSecondaryIndexes[0]",
@@ -590,6 +590,98 @@ class NativeDynamoDbJsonHandlerTest {
assertEquals(30, describedGsi.get("ProvisionedThroughput").get("WriteCapacityUnits").asInt());
}
@Test
void describeTableReportsProvisionedGsiCapacityAsWarmThroughput() throws Exception {
createProvisionedTableWithGsi("gsi-warm-provisioned", "eu-west-1");
JsonNode warmThroughput = warmThroughputOf(describedGsi("gsi-warm-provisioned", "TitleIndex"));
assertEquals(5, warmThroughput.get("ReadUnitsPerSecond").asLong());
assertEquals(5, warmThroughput.get("WriteUnitsPerSecond").asLong());
assertEquals("ACTIVE", warmThroughput.get("Status").asText());
}
@Test
void describeTableReportsOnDemandGsiWarmThroughput() throws Exception {
handler.handle("CreateTable", json("""
{
"TableName": "gsi-warm-on-demand",
"KeySchema": [{"AttributeName": "pk", "KeyType": "HASH"}],
"AttributeDefinitions": [
{"AttributeName": "pk", "AttributeType": "S"},
{"AttributeName": "g", "AttributeType": "S"}
],
"BillingMode": "PAY_PER_REQUEST",
"GlobalSecondaryIndexes": [{
"IndexName": "gsi1",
"KeySchema": [{"AttributeName": "g", "KeyType": "HASH"}],
"Projection": {"ProjectionType": "ALL"}
}]
}
"""), "eu-west-1");
JsonNode warmThroughput = warmThroughputOf(describedGsi("gsi-warm-on-demand", "gsi1"));
assertEquals(12000, warmThroughput.get("ReadUnitsPerSecond").asLong());
assertEquals(4000, warmThroughput.get("WriteUnitsPerSecond").asLong());
assertEquals("ACTIVE", warmThroughput.get("Status").asText());
}
@Test
void updateTableCreatedGsiReportsItsWarmThroughput() throws Exception {
handler.handle("CreateTable", json("""
{
"TableName": "gsi-warm-created",
"KeySchema": [{"AttributeName": "pk", "KeyType": "HASH"}],
"AttributeDefinitions": [{"AttributeName": "pk", "AttributeType": "S"}],
"BillingMode": "PROVISIONED",
"ProvisionedThroughput": {"ReadCapacityUnits": 5, "WriteCapacityUnits": 5}
}
"""), "eu-west-1");
Response response = handler.handle("UpdateTable", json("""
{
"TableName": "gsi-warm-created",
"AttributeDefinitions": [{"AttributeName": "g", "AttributeType": "S"}],
"GlobalSecondaryIndexUpdates": [{"Create": {
"IndexName": "gsi1",
"KeySchema": [{"AttributeName": "g", "KeyType": "HASH"}],
"Projection": {"ProjectionType": "ALL"},
"ProvisionedThroughput": {"ReadCapacityUnits": 2, "WriteCapacityUnits": 3}
}}]
}
"""), "eu-west-1");
assertEquals(200, response.getStatus());
JsonNode body = mapper.convertValue(response.getEntity(), JsonNode.class);
JsonNode updatedWarmThroughput = warmThroughputOf(
body.get("TableDescription").get("GlobalSecondaryIndexes").get(0));
assertEquals(2, updatedWarmThroughput.get("ReadUnitsPerSecond").asLong());
assertEquals(3, updatedWarmThroughput.get("WriteUnitsPerSecond").asLong());
JsonNode describedWarmThroughput = warmThroughputOf(describedGsi("gsi-warm-created", "gsi1"));
assertEquals(2, describedWarmThroughput.get("ReadUnitsPerSecond").asLong());
assertEquals(3, describedWarmThroughput.get("WriteUnitsPerSecond").asLong());
assertEquals("ACTIVE", describedWarmThroughput.get("Status").asText());
}
private JsonNode describedGsi(String tableName, String indexName) throws Exception {
Response response = handler.handle("DescribeTable",
mapper.createObjectNode().put("TableName", tableName), "eu-west-1");
assertEquals(200, response.getStatus());
JsonNode body = mapper.convertValue(response.getEntity(), JsonNode.class);
for (JsonNode gsi : body.get("Table").get("GlobalSecondaryIndexes")) {
if (indexName.equals(gsi.get("IndexName").asText())) {
return gsi;
}
}
throw new AssertionError("DescribeTable lists no GSI named " + indexName);
}
private static JsonNode warmThroughputOf(JsonNode gsi) {
assertTrue(gsi.has("WarmThroughput"), "The GSI description must report its WarmThroughput");
return gsi.get("WarmThroughput");
}
@Test
void updateTableRejectsConflictingDeleteAndUpdateWithoutRemovingGsi() throws Exception {
createProvisionedTableWithGsi("gsi-conflicting-update-table", "eu-west-1");