fix(cloudwatch): render region and accountId when directly set on metrics #32325
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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