-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
…rics (#32325) ### Issue # Closes #28731 ### Reason for this change Currently, if a user creates a metric that includes `region` and `accountId`, 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 via `metric.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` and `account` were public properties that were set by `metric.attachTo(stack)`, making it impossible to differentiate whether they were set directly or via `attachTo`. To differentiate them while maintaining backward compatibility, I took this approach: 1. `attachTo` sets internal properties called `stackRegion` and `stackAccount`. Setting `region` and `account` directly sets internal properties called `regionOverride` and `accountOverride`. 2. The public `region` and `account` properties are now getters that return the override (if set) and fall back on the stack properties. 3. The `toMetricConfig()` method returns the `region` and `account` from the getters, but also includes the `regionOverride` and `accountOverride`. That way, everything that looks at `region` and `account` works the same way it did before, except in `metricGraphJson`, which skips the "if different from stack" tokenization if the overrides are set. ### Description of how you validated changes 1. Confirmed that all existing unit tests pass. 2. Added a new unit test to show that `region` and `account` are now preserved when set directly on a metric. 3. Modified an integration test to show how setting `region` and `account` on a metric affects the snapshot. ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/** | ||
* Make a property from the specified prototype enumerable on the specific instance. | ||
*/ | ||
export function makeEnumerable(prototype: object, instance: object, propertyKey: string) { | ||
Object.defineProperty(instance, propertyKey, { | ||
...Object.getOwnPropertyDescriptor(prototype, propertyKey), | ||
enumerable: true, | ||
}); | ||
} |