From 399a96d70c0510a62a69bcfd42cf5566f8718e60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?U=C4=9Fur=20Tafral=C4=B1?= Date: Wed, 8 Apr 2026 05:11:01 +0300 Subject: [PATCH] fix: include ProvisionedThroughput in DynamoDB GSI responses (#273) DescribeTable responses were missing ProvisionedThroughput attributes on Global Secondary Indexes. Updated the JSON handler to extract and set ReadCapacityUnits and WriteCapacityUnits from the response payload for both DescribeTable and Create operations. --- .../dynamodb/DynamoDbJsonHandler.java | 24 +++++++++++++++++-- .../dynamodb/model/GlobalSecondaryIndex.java | 17 ++++++++++++- .../dynamodb/DynamoDbIntegrationTest.java | 6 +++++ 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbJsonHandler.java b/src/main/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbJsonHandler.java index 82c0f5a42d..96f859c414 100644 --- a/src/main/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbJsonHandler.java +++ b/src/main/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbJsonHandler.java @@ -95,7 +95,13 @@ public class DynamoDbJsonHandler { ks.path("AttributeName").asText(), ks.path("KeyType").asText()))); String projectionType = gsiNode.path("Projection").path("ProjectionType").asText("ALL"); - gsis.add(new GlobalSecondaryIndex(indexName, gsiKeySchema, null, projectionType)); + GlobalSecondaryIndex gsi = new GlobalSecondaryIndex(indexName, gsiKeySchema, null, projectionType); + JsonNode gsiPt = gsiNode.path("ProvisionedThroughput"); + if (!gsiPt.isMissingNode()) { + gsi.getProvisionedThroughput().setReadCapacityUnits(gsiPt.path("ReadCapacityUnits").asLong(0)); + gsi.getProvisionedThroughput().setWriteCapacityUnits(gsiPt.path("WriteCapacityUnits").asLong(0)); + } + gsis.add(gsi); } } @@ -410,7 +416,13 @@ public class DynamoDbJsonHandler { ks.path("AttributeName").asText(), ks.path("KeyType").asText()))); String projectionType = createNode.path("Projection").path("ProjectionType").asText("ALL"); - gsiCreates.add(new GlobalSecondaryIndex(indexName, gsiKeySchema, null, projectionType)); + GlobalSecondaryIndex newGsi = new GlobalSecondaryIndex(indexName, gsiKeySchema, null, projectionType); + JsonNode newGsiPt = createNode.path("ProvisionedThroughput"); + if (!newGsiPt.isMissingNode()) { + newGsi.getProvisionedThroughput().setReadCapacityUnits(newGsiPt.path("ReadCapacityUnits").asLong(0)); + newGsi.getProvisionedThroughput().setWriteCapacityUnits(newGsiPt.path("WriteCapacityUnits").asLong(0)); + } + gsiCreates.add(newGsi); } JsonNode deleteNode = update.path("Delete"); if (!deleteNode.isMissingNode()) { @@ -655,6 +667,14 @@ public class DynamoDbJsonHandler { gsi.getProjectionType() != null ? gsi.getProjectionType() : "ALL"); gsiNode.set("Projection", projection); + ObjectNode gsiPt = objectMapper.createObjectNode(); + gsiPt.put("ReadCapacityUnits", gsi.getProvisionedThroughput().getReadCapacityUnits()); + gsiPt.put("WriteCapacityUnits", gsi.getProvisionedThroughput().getWriteCapacityUnits()); + gsiPt.put("NumberOfDecreasesToday", gsi.getProvisionedThroughput().getNumberOfDecreasesToday()); + gsiNode.set("ProvisionedThroughput", gsiPt); + gsiNode.put("IndexSizeBytes", gsi.getIndexSizeBytes()); + gsiNode.put("ItemCount", gsi.getItemCount()); + gsiArray.add(gsiNode); } node.set("GlobalSecondaryIndexes", gsiArray); diff --git a/src/main/java/io/github/hectorvent/floci/services/dynamodb/model/GlobalSecondaryIndex.java b/src/main/java/io/github/hectorvent/floci/services/dynamodb/model/GlobalSecondaryIndex.java index d8b30eee38..c57692055d 100644 --- a/src/main/java/io/github/hectorvent/floci/services/dynamodb/model/GlobalSecondaryIndex.java +++ b/src/main/java/io/github/hectorvent/floci/services/dynamodb/model/GlobalSecondaryIndex.java @@ -13,8 +13,13 @@ public class GlobalSecondaryIndex { private List keySchema; private String indexArn; private String projectionType; + private ProvisionedThroughput provisionedThroughput; + private long itemCount; + private long indexSizeBytes; - public GlobalSecondaryIndex() {} + public GlobalSecondaryIndex() { + this.provisionedThroughput = new ProvisionedThroughput(0, 0); + } public GlobalSecondaryIndex(String indexName, List keySchema, String indexArn, String projectionType) { @@ -22,6 +27,7 @@ public class GlobalSecondaryIndex { this.keySchema = keySchema; this.indexArn = indexArn; this.projectionType = projectionType != null ? projectionType : "ALL"; + this.provisionedThroughput = new ProvisionedThroughput(0, 0); } public String getIndexName() { return indexName; } @@ -36,6 +42,15 @@ public class GlobalSecondaryIndex { public String getProjectionType() { return projectionType; } public void setProjectionType(String projectionType) { this.projectionType = projectionType; } + public ProvisionedThroughput getProvisionedThroughput() { return provisionedThroughput; } + public void setProvisionedThroughput(ProvisionedThroughput provisionedThroughput) { this.provisionedThroughput = provisionedThroughput; } + + public long getItemCount() { return itemCount; } + public void setItemCount(long itemCount) { this.itemCount = itemCount; } + + public long getIndexSizeBytes() { return indexSizeBytes; } + public void setIndexSizeBytes(long indexSizeBytes) { this.indexSizeBytes = indexSizeBytes; } + public String getPartitionKeyName() { return keySchema.stream() .filter(k -> "HASH".equals(k.getKeyType())) diff --git a/src/test/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbIntegrationTest.java index 50601fd303..2789ab4bb0 100644 --- a/src/test/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbIntegrationTest.java @@ -603,6 +603,12 @@ class DynamoDbIntegrationTest { .body("Table.GlobalSecondaryIndexes[0].IndexName", equalTo("TestGsi")) .body("Table.GlobalSecondaryIndexes[0].IndexStatus", equalTo("ACTIVE")) .body("Table.GlobalSecondaryIndexes[0].IndexArn", containsString("/index/TestGsi")) + .body("Table.GlobalSecondaryIndexes[0].ProvisionedThroughput", notNullValue()) + .body("Table.GlobalSecondaryIndexes[0].ProvisionedThroughput.ReadCapacityUnits", equalTo(0)) + .body("Table.GlobalSecondaryIndexes[0].ProvisionedThroughput.WriteCapacityUnits", equalTo(0)) + .body("Table.GlobalSecondaryIndexes[0].ProvisionedThroughput.NumberOfDecreasesToday", equalTo(0)) + .body("Table.GlobalSecondaryIndexes[0].IndexSizeBytes", equalTo(0)) + .body("Table.GlobalSecondaryIndexes[0].ItemCount", equalTo(0)) .body("Table.AttributeDefinitions.size()", equalTo(3)); }