Skip to content

Commit 555afcf

Browse files
committed
appstagingsynth snap
2 parents a203c3b + 6858edf commit 555afcf

4 files changed

Lines changed: 48 additions & 0 deletions

File tree

packages/@aws-cdk/app-staging-synthesizer-alpha/lib/default-staging-stack.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,27 @@ import {
1818
INLINE_CUSTOM_RESOURCE_CONTEXT,
1919
} from 'aws-cdk-lib/core';
2020
import { StringSpecializer } from 'aws-cdk-lib/core/lib/helpers-internal';
21+
import * as cxapi from 'aws-cdk-lib/cx-api';
22+
import { Construct } from 'constructs';
2123
import { BootstrapRole } from './bootstrap-roles';
2224
import { FileStagingLocation, IStagingResources, IStagingResourcesFactory, ImageStagingLocation } from './staging-stack';
2325

2426
export const DEPLOY_TIME_PREFIX = 'deploy-time/';
2527

28+
/**
29+
* This is a dummy construct meant to signify that a stack is utilizing
30+
* the AppStagingSynthesizer. It does not do anything, and is not meant
31+
* to be created on its own. This construct will be a part of the
32+
* construct tree only and not the Cfn template. The construct tree is
33+
* then encoded in the AWS::CDK::Metadata resource of the stack and
34+
* injested in our metrics like every other construct.
35+
*/
36+
export class UsingAppStagingSynthesizer extends Construct {
37+
constructor(scope: Construct, id: string) {
38+
super(scope, id);
39+
}
40+
}
41+
2642
/**
2743
* User configurable options to the DefaultStagingStack.
2844
*/
@@ -137,6 +153,12 @@ export class DefaultStagingStack extends Stack implements IStagingResources {
137153
throw new Error(`Stack ${stack.stackName} must be part of an App`);
138154
}
139155

156+
// Because we do not keep metrics in the DefaultStagingStack, we will inject
157+
// a dummy construct into the stack using the DefaultStagingStack instead.
158+
if (cxapi.ANALYTICS_REPORTING_ENABLED_CONTEXT) {
159+
new UsingAppStagingSynthesizer(stack, `UsingAppStagingSynthesizer/${stack.stackName}`);
160+
}
161+
140162
const stackId = `StagingStack-${appId}-${context.environmentString}`;
141163
return new DefaultStagingStack(app, stackId, {
142164
...options,
@@ -209,7 +231,10 @@ export class DefaultStagingStack extends Stack implements IStagingResources {
209231
super(scope, id, {
210232
...props,
211233
synthesizer: new BootstraplessSynthesizer(),
234+
analyticsReporting: false, // removing AWS::CDK::Metadata construct saves ~3KB
212235
});
236+
// removing path metadata saves ~2KB
237+
this.node.setContext(cxapi.PATH_METADATA_ENABLE_CONTEXT, false);
213238

214239
// For all resources under the default staging stack, we want to inline custom
215240
// resources because the staging bucket necessary for custom resource assets

packages/@aws-cdk/app-staging-synthesizer-alpha/test/app-staging-synthesizer.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@ describe(AppStagingSynthesizer, () => {
121121
expect(depStack.stackName).toEqual(`StagingStack-${APP_ID}`);
122122
});
123123

124+
test('stack has dummy construct for metrics', () => {
125+
// WHEN
126+
const dummyConstruct = stack.node.tryFindChild(`UsingAppStagingSynthesizer/${stack.stackName}`);
127+
expect(dummyConstruct).toBeDefined();
128+
});
129+
124130
test('add file asset', () => {
125131
// WHEN
126132
const location = stack.synthesizer.addFileAsset({

packages/@aws-cdk/app-staging-synthesizer-alpha/test/integ.synth-default-resources.js.snapshot/manifest.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,15 @@
7878
"type": "aws:cdk:logicalId",
7979
"data": "lambdaecr2615DAF68"
8080
}
81+
],
82+
"UsingDefaultStagingStacksynthesizedefaultresources": [
83+
{
84+
"type": "aws:cdk:logicalId",
85+
"data": "UsingDefaultStagingStacksynthesizedefaultresources",
86+
"trace": [
87+
"!!DESTRUCTIVE_CHANGES: WILL_DESTROY"
88+
]
89+
}
8190
]
8291
},
8392
"displayName": "synthesize-default-resources"

packages/@aws-cdk/app-staging-synthesizer-alpha/test/integ.synth-default-resources.js.snapshot/tree.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@
88
"id": "synthesize-default-resources",
99
"path": "synthesize-default-resources",
1010
"children": {
11+
"UsingAppStagingSynthesizer--synthesize-default-resources": {
12+
"id": "UsingAppStagingSynthesizer--synthesize-default-resources",
13+
"path": "synthesize-default-resources/UsingAppStagingSynthesizer--synthesize-default-resources",
14+
"constructInfo": {
15+
"fqn": "@aws-cdk/app-staging-synthesizer-alpha.UsingAppStagingSynthesizer",
16+
"version": "0.0.0"
17+
}
18+
},
1119
"lambda-s3": {
1220
"id": "lambda-s3",
1321
"path": "synthesize-default-resources/lambda-s3",

0 commit comments

Comments
 (0)