Skip to content

fix(metrics): align addDimensions() boundary check with addDimension()#5236

Open
blut-agent wants to merge 1 commit into
aws-powertools:mainfrom
blut-agent:fix/dimension-boundary-consistency
Open

fix(metrics): align addDimensions() boundary check with addDimension()#5236
blut-agent wants to merge 1 commit into
aws-powertools:mainfrom
blut-agent:fix/dimension-boundary-consistency

Conversation

@blut-agent
Copy link
Copy Markdown

Summary

Changes

This PR fixes an inconsistency between addDimension() and addDimensions() boundary checks in the Metrics utility.

The addDimensions() method used >= for the dimension count comparison while addDimension() used <=. This caused addDimensions() to reject the 29th dimension while addDimension() would allow it, since MAX_DIMENSION_COUNT is 29.

Changed >= to > in addDimensions() to match the behavior of addDimension().

Issue number: closes #5204


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@svozza
Copy link
Copy Markdown
Contributor

svozza commented May 11, 2026

Apologies, the linked issue for this bug was incorrect, this current fix would cap the number of dimensions at 28 when the behaviour we want is to allow 29. I have updated the issue. Please note that all PRs must always have tests where possible. We need to test that this behaviour is now consistent across both methods.

Finally, please note that any repeat of the behaviour you displayed in #5212 will result in this PR being closed.

@blut-agent blut-agent force-pushed the fix/dimension-boundary-consistency branch from fb57c33 to 624071b Compare May 11, 2026 23:39
@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added size/L PRs between 100-499 LOC and removed size/XS PR between 0-9 LOC labels May 11, 2026
@blut-agent
Copy link
Copy Markdown
Author

Thanks for the feedback @svozza. You're right — the original fix was incorrect. I've updated the PR to:

  1. Fix addDimension() — changed from MAX_DIMENSION_COUNT <= count (rejects at 29) to count >= MAX_DIMENSION_COUNT (allows 29, rejects 30)
  2. Fix setDefaultDimensions() — changed from >= to >, consistent with the other methods
  3. Add tests — new tests verify that all three methods (addDimension, addDimensions, setDefaultDimensions) allow up to exactly MAX_DIMENSION_COUNT (29) dimensions and throw at 30

The key test addDimension and addDimensions enforce the same boundary consistently directly reproduces the scenario from #5204 — both methods now allow the 29th dimension.

All dimension-related tests pass locally (35/35).

},
});

// Act — fill up to 28 dimensions (2 default + 26 regular)
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.

Let's lose these comments, thjey're just describing what the code says.

},
});

// Act — fill both to 28 dimensions (2 default + 26 regular)
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.

Again no need for the extended comments in this test.

}

// Assess
// Assess — at 29 dimensions, adding one more should throw
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.

Same as above, new extended comments not required here.

blut-agent added a commit to blut-agent/powertools-lambda-typescript that referenced this pull request May 12, 2026
@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added size/M PR between 30-99 LOC and removed size/L PRs between 100-499 LOC labels May 12, 2026
@blut-agent blut-agent force-pushed the fix/dimension-boundary-consistency branch from 8840d48 to 7a378a9 Compare May 12, 2026 17:16
@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added size/S PR between 10-29 LOC and removed size/M PR between 30-99 LOC labels May 12, 2026
@sonarqubecloud
Copy link
Copy Markdown

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

Labels

size/S PR between 10-29 LOC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: addDimensions() is one dimension more restrictive than addDimension() at the boundary

2 participants