Skip to content

Conversation

hsiaoa
Copy link

@hsiaoa hsiaoa commented Sep 19, 2025

Issue # (if applicable)

Closes #34785.

Reason for this change

The metricSuccessfulRequestLatency() method in TableV2 throws a validation error requiring an "Operation" dimension, but .NET CDK users cannot easily provide this dimension through the available options. This creates a usability issue where .NET developers cannot create SuccessfulRequestLatency metrics for DynamoDB TableV2 instances without complex workarounds.

The root cause is a cross-language compatibility limitation with JSII (JavaScript Interop Interface). While TypeScript users can easily pass complex dimensionsMap objects, .NET users struggle with the JSII translation of nested object structures, making it difficult or impossible to provide the required Operation dimension.

Description of changes

Added 5 JSII-friendly convenience methods to TableV2Base class for creating SuccessfulRequestLatency metrics:

  • metricSuccessfulRequestLatencyForGetItem(props?: MetricOptions): Metric
  • metricSuccessfulRequestLatencyForPutItem(props?: MetricOptions): Metric
  • metricSuccessfulRequestLatencyForQuery(props?: MetricOptions): Metric
  • metricSuccessfulRequestLatencyForScan(props?: MetricOptions): Metric
  • metricSuccessfulRequestLatencyForOperation(operation: string, props?: MetricOptions): Metric

These methods internally handle the required Operation dimension, providing a clean API for cross-language CDK users. The implementation follows the existing metricXxxForOperation pattern used throughout the CDK DynamoDB module and extends the ITable interface for consistency between Table and TableV2.

Each method internally calls metricSuccessfulRequestLatencyForOperation() with the appropriate operation string, which constructs the proper dimensionsMap with both TableName and Operation dimensions before delegating to the existing metric infrastructure.

Describe any new or updated permissions being added

N/A - No IAM permissions changes. This is a client-side metric creation enhancement that uses existing CloudWatch metric functionality.

Description of how you validated changes

  • Unit tests: Added 6 comprehensive unit tests covering all new convenience methods, custom MetricOptions parameter handling, proper dimension validation, and metric properties verification
  • Integration tests: Created new integration test integ.dynamodb-v2.alarm-metrics.ts that validates CloudFormation template generation for all 5 new methods, confirming proper AWS::CloudWatch::Alarm resource creation with correct dimensions, namespace, and statistics
  • Build verification: Full TypeScript compilation, linting, and JSII compatibility verified
  • Cross-language testing: JSII compatibility confirmed for .NET CDK usage through successful CloudFormation template generation
  • Regression testing: Existing integration tests confirm no CloudFormation impact and backward compatibility

The integration test generates 6 AWS::CloudWatch::Alarm resources with proper SuccessfulRequestLatency metrics, each containing correct Operation dimensions (GetItem, PutItem, Query, Scan, BatchGetItem) and AWS/DynamoDB namespace configuration.

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

…sfulRequestLatency metric in TableV2

- Add metricSuccessfulRequestLatencyForGetItem()
- Add metricSuccessfulRequestLatencyForPutItem()
- Add metricSuccessfulRequestLatencyForQuery()
- Add metricSuccessfulRequestLatencyForScan()
- Add metricSuccessfulRequestLatencyForOperation(operation: string)
- Update ITable interface with optional methods for consistency
- Add comprehensive unit tests for all new methods

Fixes aws#34785: .NET CDK users can now create SuccessfulRequestLatency metrics
without manually specifying Operation dimension through dimensionsMap
@aws-cdk-automation aws-cdk-automation requested a review from a team September 19, 2025 07:01
@github-actions github-actions bot added beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK bug This issue is a bug. effort/medium Medium work item – several days of effort p2 labels Sep 19, 2025
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(This review is outdated)

@pahud pahud self-assigned this Sep 19, 2025
@pahud pahud changed the title feat(dynamodb): add operation-specific convenience methods for Succes… feat(dynamodb): operation-specific convenience methods for successful request latency metrics Sep 19, 2025
@pahud pahud marked this pull request as draft September 19, 2025 11:02
@aws-cdk-automation aws-cdk-automation dismissed their stale review September 19, 2025 19:56

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

pahud
pahud previously requested changes Sep 22, 2025
Copy link
Contributor

@pahud pahud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's fix them

[jsii-rosetta] [INFO] Loading 36 assemblies
[jsii-rosetta] [INFO] Translating
[jsii-rosetta] [INFO] Preparing dependency closure at /tmp/rosetta4U5BW8 (-vv for more details)
[jsii-rosetta] [INFO] Translating 3241 snippets using 16 workers
[jsii-rosetta] [INFO] Translated 3241 snippets in 681.724 seconds (0.210s/snippet)
[jsii-rosetta] [INFO] Adding translations to /root/.s3buildcache/rosetta-cache.tabl.json
Error: aws-cdk-lib.aws_dynamodb-README-L966.ts:27:5 - error TS2304: Cannot find name 'cloudwatch'.

27 new cloudwatch.Alarm(this, 'GetItemLatencyAlarm', {
       ~~~~~~~~~~
Error: aws-cdk-lib.aws_dynamodb-README-L966.ts:33:5 - error TS2304: Cannot find name 'cloudwatch'.

33 new cloudwatch.Alarm(this, 'QueryLatencyAlarm', {
       ~~~~~~~~~~
Error: aws-cdk-lib.aws_dynamodb-README-L996.ts:13:29 - error TS2304: Cannot find name 'table'.

13 const customLatencyMetric = table.metricSuccessfulRequestLatencyForGetItem({
                               ~~~~~
[jsii-rosetta] [WARN] 3 diagnostics from assemblies with 'strict' mode on (and 75 more non-strict diagnostics)

@mergify mergify bot dismissed pahud’s stale review September 22, 2025 16:04

Pull request has been modified.

@pahud pahud marked this pull request as ready for review September 22, 2025 16:05
/// !cdk-integ dynamodb-v2-alarm-metrics

/**
* Integration Test: DynamoDB TableV2 SuccessfulRequestLatency Convenience Methods
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This all doesn't need to be in the code that we submit.

*
* @param props properties of a metric
*/
metricSuccessfulRequestLatencyForGetItem?(props?: cloudwatch.MetricOptions): cloudwatch.Metric;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are not necessary anymore if we have the generic one below.

* @param operation The DynamoDB operation to get metrics for
* @param props properties of a metric
*/
metricSuccessfulRequestLatencyForOperation?(operation: string, props?: cloudwatch.MetricOptions): cloudwatch.Metric;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better yet, this could just be metricSuccessfulRequestLatencyV2, deprecating the old one.

The lack of ability to pass in an operation could be seen as a serious defect that needs to be rectified.

Please tell me we at least had TableName in there already?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK bug This issue is a bug. effort/medium Medium work item – several days of effort p2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DynamoDB: Validation error on Metric create

4 participants