-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(cloudwatch): render region and accountId when directly set on metrics #32325
fix(cloudwatch): render region and accountId when directly set on metrics #32325
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.
A comment requesting an exemption should contain the text Exemption Request
. Additionally, if clarification is needed add Clarification Request
to a comment.
✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.
I don't know what's going on in the build log. It says:
But there are no matches for |
This PR has been in the BUILD FAILING state for 3 weeks, and looks abandoned. To keep this PR from being closed, please continue work on it. If not, it will automatically be closed in a week. |
2595f62
to
91680a5
Compare
I tried again, but the build is still failing. It's very strange; the build log says:
But the output for
|
@TrevorBurnham Looking at the build logs I believe some unit tests need to be updated, e.g.
You can search for |
91680a5
to
dc87654
Compare
@gracelu0 Thanks for pointing me in the right direction! I figured out the issue:
This caused backward compatibility-breaking behavior that showed up in those unit tests. I've corrected this by explicitly making the getters enumerable using |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #32325 +/- ##
=======================================
Coverage 81.52% 81.52%
=======================================
Files 222 222
Lines 13715 13715
Branches 2417 2417
=======================================
Hits 11181 11181
Misses 2254 2254
Partials 280 280
Flags with carried forward coverage won't be shown. Click here to find out more.
|
stackAccount: cdk.Token.isUnresolved(stack.account) ? undefined : stack.account, | ||
stackRegion: cdk.Token.isUnresolved(stack.region) ? undefined : stack.region, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to stackAccount
and stackRegion
here? Can we directly set region
and account
?
Do we need to differentiate whether they're set directly or via attachTo? |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
The intent is to fix #28731 while preserving as much of the existing behavior as possible. The background facts are:
That means there are two possible solutions:
This PR takes the first approach in order to maximize backward compatibility: Users who aren't directly setting account/region values won't see any change in serialized output. The second approach would make for a simpler code change, but a large number of users would see their serialized output change. |
Got it. Thanks for the explanations. Approved. |
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
Comments on closed issues and PRs are hard for our team to see. |
Issue
Closes #28731
Reason for this change
Currently, if a user creates a metric that includes
region
andaccountId
, those fields are omitted when the metric renders in a stack with those same values. The intended behavior is to omit those fields when they're implicitly set viametric.attachTo(stack)
, not to omit them when set directly by the user.Description of changes
This is a second attempt at #29935, which was auto-closed after the pull request linter complained that there were no integration test changes. This time around I've tried to satisfy the linter. Otherwise, the changes are the same as before:
The key changes here are on the
Metric
class. Previously,region
andaccount
were public properties that were set bymetric.attachTo(stack)
, making it impossible to differentiate whether they were set directly or viaattachTo
. To differentiate them while maintaining backward compatibility, I took this approach:attachTo
sets internal properties calledstackRegion
andstackAccount
. Settingregion
andaccount
directly sets internal properties calledregionOverride
andaccountOverride
.region
andaccount
properties are now getters that return the override (if set) and fall back on the stack properties.toMetricConfig()
method returns theregion
andaccount
from the getters, but also includes theregionOverride
andaccountOverride
.That way, everything that looks at
region
andaccount
works the same way it did before, except inmetricGraphJson
, which skips the "if different from stack" tokenization if the overrides are set.Description of how you validated changes
region
andaccount
are now preserved when set directly on a metric.region
andaccount
on a metric affects the snapshot.Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license