Skip to content
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): cross-account metrics in env-agnostic stack #5775

Merged
merged 2 commits into from
Jan 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/@aws-cdk/aws-cloudwatch/lib/private/env-tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ class StackDependentToken implements cdk.IResolvable {
public resolve(context: cdk.IResolveContext) {
const stackValue = this.fn(cdk.Stack.of(context.scope));

if (cdk.Token.isUnresolved(stackValue) || stackValue === this.originalValue) {
// Don't render if the values are definitely the same. If the stack
// is unresolved we don't know, better output the value.
if (!cdk.Token.isUnresolved(stackValue) && stackValue === this.originalValue) {
return undefined;
}

Expand Down
32 changes: 32 additions & 0 deletions packages/@aws-cdk/aws-cloudwatch/test/test.cross-environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,38 @@ export = {

test.done();
},

'metric with explicit account and region will render in environment agnostic stack'(test: Test) {
// GIVEN
const graph = new GraphWidget({
left: [
a.with({ account: '1234', region: 'us-north-5' })
],
});

// THEN
graphMetricsAre(test, new Stack(), graph, [
[ 'Test', 'ACount', { accountId: '1234', region: 'us-north-5' }],
]);

test.done();
},

'metric attached to agnostic stack will not render in agnostic stack'(test: Test) {
// GIVEN
const graph = new GraphWidget({
left: [
a.attachTo(new Stack()),
],
});

// THEN
graphMetricsAre(test, new Stack(), graph, [
[ 'Test', 'ACount' ],
]);

test.done();
},
},

'in alarms': {
Expand Down