Skip to content

feat(dynamodb): operation-specific convenience methods for successful request latency metrics#35527

Closed
hsiaoa wants to merge 4 commits intoaws:mainfrom
hsiaoa:fix-34785
Closed

feat(dynamodb): operation-specific convenience methods for successful request latency metrics#35527
hsiaoa wants to merge 4 commits intoaws:mainfrom
hsiaoa:fix-34785

Conversation

@hsiaoa
Copy link
Copy Markdown

@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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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?

@aws-cdk-automation
Copy link
Copy Markdown
Collaborator

This PR has been in the CHANGES REQUESTED state for 3 weeks, and looks abandoned. Note that PRs with failing linting check or builds are not reviewed, please ensure your build is passing

To prevent automatic closure:

  • Resume work on the PR
  • OR request an exemption by adding a comment containing 'Exemption Request' with justification e.x "Exemption Request: "
  • OR request clarification by adding a comment containing 'Clarification Request' with a question e.x "Clarification Request: "

This PR will automatically close in 14 days if no action is taken.

@aws-cdk-automation
Copy link
Copy Markdown
Collaborator

This PR has been deemed to be abandoned, and will be automatically closed. Please create a new PR for these changes if you think this decision has been made in error.

@aws-cdk-automation aws-cdk-automation added the closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. label Nov 5, 2025
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Nov 5, 2025

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 5, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK bug This issue is a bug. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. 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