Skip to content

Commit 95df073

Browse files
authored
Merge pull request #1614 from guardian/aa/logging-stream-parameter
refactor(cdk): Adjust logging stream parameter within `adjustCloudformationParameters`
2 parents cdb5efd + f46713d commit 95df073

4 files changed

Lines changed: 43 additions & 41 deletions

File tree

cdk/bin/cdk.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ export const reportPropsCode: ReportProps = {
7575
app: 'report',
7676
domainName: 'report.notifications.code.dev-guardianapis.com',
7777
instanceMetricGranularity: '5Minute',
78-
loggingStreamParameterName: '/account/services/logging.stream.name.code',
7978
minAsgSize: 1,
8079
};
8180
new Report(app, 'Report-CODE', reportPropsCode);
@@ -88,7 +87,6 @@ export const reportPropsProd: ReportProps = {
8887
app: 'report',
8988
domainName: 'report.notifications.guardianapis.com',
9089
instanceMetricGranularity: '1Minute',
91-
loggingStreamParameterName: '/account/services/logging.stream.name',
9290
minAsgSize: 3,
9391
};
9492
new Report(app, 'Report-PROD', reportPropsProd);

cdk/lib/__snapshots__/report.test.ts.snap

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,6 @@ exports[`The Report stack matches the snapshot for CODE 1`] = `
6060
"Description": "SSM parameter containing the S3 bucket name holding distribution artifacts",
6161
"Type": "AWS::SSM::Parameter::Value<String>",
6262
},
63-
"GuCdkVpcId": {
64-
"AllowedValues": [
65-
"/account/vpc/notifications/id",
66-
],
67-
"Default": "/account/vpc/notifications/id",
68-
"Description": "Virtual Private Cloud to run EC2 instances within. Should NOT be the account default VPC.",
69-
"Type": "AWS::SSM::Parameter::Value<AWS::EC2::VPC::Id>",
70-
},
7163
"LoggingStreamName": {
7264
"AllowedValues": [
7365
"/account/services/logging.stream.name.code",
@@ -76,6 +68,14 @@ exports[`The Report stack matches the snapshot for CODE 1`] = `
7668
"Description": "SSM parameter containing the Name (not ARN) on the kinesis stream",
7769
"Type": "AWS::SSM::Parameter::Value<String>",
7870
},
71+
"VpcId": {
72+
"AllowedValues": [
73+
"/account/vpc/notifications/id",
74+
],
75+
"Default": "/account/vpc/notifications/id",
76+
"Description": "Virtual Private Cloud to run EC2 instances within. Should NOT be the account default VPC.",
77+
"Type": "AWS::SSM::Parameter::Value<AWS::EC2::VPC::Id>",
78+
},
7979
"reportPrivateSubnets": {
8080
"AllowedValues": [
8181
"/account/vpc/notifications/subnets/private",
@@ -430,7 +430,7 @@ exports[`The Report stack matches the snapshot for CODE 1`] = `
430430
},
431431
],
432432
"VpcId": {
433-
"Ref": "GuCdkVpcId",
433+
"Ref": "VpcId",
434434
},
435435
},
436436
"Type": "AWS::EC2::SecurityGroup",
@@ -663,7 +663,7 @@ exports[`The Report stack matches the snapshot for CODE 1`] = `
663663
},
664664
],
665665
"VpcId": {
666-
"Ref": "GuCdkVpcId",
666+
"Ref": "VpcId",
667667
},
668668
},
669669
"Type": "AWS::EC2::SecurityGroup",
@@ -1139,7 +1139,7 @@ exports[`The Report stack matches the snapshot for CODE 1`] = `
11391139
"TargetType": "instance",
11401140
"UnhealthyThresholdCount": 10,
11411141
"VpcId": {
1142-
"Ref": "GuCdkVpcId",
1142+
"Ref": "VpcId",
11431143
},
11441144
},
11451145
"Type": "AWS::ElasticLoadBalancingV2::TargetGroup",
@@ -1364,14 +1364,6 @@ exports[`The Report stack matches the snapshot for PROD 1`] = `
13641364
"Description": "SSM parameter containing the S3 bucket name holding distribution artifacts",
13651365
"Type": "AWS::SSM::Parameter::Value<String>",
13661366
},
1367-
"GuCdkVpcId": {
1368-
"AllowedValues": [
1369-
"/account/vpc/notifications/id",
1370-
],
1371-
"Default": "/account/vpc/notifications/id",
1372-
"Description": "Virtual Private Cloud to run EC2 instances within. Should NOT be the account default VPC.",
1373-
"Type": "AWS::SSM::Parameter::Value<AWS::EC2::VPC::Id>",
1374-
},
13751367
"LoggingStreamName": {
13761368
"AllowedValues": [
13771369
"/account/services/logging.stream.name",
@@ -1380,6 +1372,14 @@ exports[`The Report stack matches the snapshot for PROD 1`] = `
13801372
"Description": "SSM parameter containing the Name (not ARN) on the kinesis stream",
13811373
"Type": "AWS::SSM::Parameter::Value<String>",
13821374
},
1375+
"VpcId": {
1376+
"AllowedValues": [
1377+
"/account/vpc/notifications/id",
1378+
],
1379+
"Default": "/account/vpc/notifications/id",
1380+
"Description": "Virtual Private Cloud to run EC2 instances within. Should NOT be the account default VPC.",
1381+
"Type": "AWS::SSM::Parameter::Value<AWS::EC2::VPC::Id>",
1382+
},
13831383
"reportPrivateSubnets": {
13841384
"AllowedValues": [
13851385
"/account/vpc/notifications/subnets/private",
@@ -1734,7 +1734,7 @@ exports[`The Report stack matches the snapshot for PROD 1`] = `
17341734
},
17351735
],
17361736
"VpcId": {
1737-
"Ref": "GuCdkVpcId",
1737+
"Ref": "VpcId",
17381738
},
17391739
},
17401740
"Type": "AWS::EC2::SecurityGroup",
@@ -1967,7 +1967,7 @@ exports[`The Report stack matches the snapshot for PROD 1`] = `
19671967
},
19681968
],
19691969
"VpcId": {
1970-
"Ref": "GuCdkVpcId",
1970+
"Ref": "VpcId",
19711971
},
19721972
},
19731973
"Type": "AWS::EC2::SecurityGroup",
@@ -2443,7 +2443,7 @@ exports[`The Report stack matches the snapshot for PROD 1`] = `
24432443
"TargetType": "instance",
24442444
"UnhealthyThresholdCount": 10,
24452445
"VpcId": {
2446-
"Ref": "GuCdkVpcId",
2446+
"Ref": "VpcId",
24472447
},
24482448
},
24492449
"Type": "AWS::ElasticLoadBalancingV2::TargetGroup",

cdk/lib/mobile-n10n-compatibility.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,32 @@ function adjustArtifactBucketParameter(stack: GuStack) {
5555
);
5656
}
5757

58+
/**
59+
* In the Mobile account there are separate Kinesis streams for CODE and PROD, so we can't always use the account-wide default
60+
*/
61+
function adjustLoggingStreamParameter(stack: GuStack) {
62+
if (stack.stage !== 'PROD') {
63+
adjustParameter(
64+
stack,
65+
'/account/services/logging.stream.name',
66+
'/account/services/logging.stream.name.code',
67+
);
68+
} else {
69+
// Keep the same value, but explicitly set `allowedValues`
70+
adjustParameter(
71+
stack,
72+
'/account/services/logging.stream.name',
73+
'/account/services/logging.stream.name',
74+
);
75+
}
76+
}
77+
5878
/**
5979
* Applications within the `mobile-n10n` stack do not use account (/GuCDK) defaults.
6080
* This adjusts CloudFormation parameters with values suitable for the `mobile-n10n` stack.
6181
*/
6282
export function adjustCloudformationParameters(stack: GuStack) {
6383
adjustVpcParameters(stack);
6484
adjustArtifactBucketParameter(stack);
85+
adjustLoggingStreamParameter(stack);
6586
}

cdk/lib/report.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { GuPlayApp, GuScheduledLambda } from '@guardian/cdk';
22
import { AccessScope } from '@guardian/cdk/lib/constants';
33
import type { GuStackProps } from '@guardian/cdk/lib/constructs/core';
4-
import { GuVpcParameter } from '@guardian/cdk/lib/constructs/core';
5-
import { GuLoggingStreamNameParameter } from '@guardian/cdk/lib/constructs/core';
64
import { GuStack } from '@guardian/cdk/lib/constructs/core';
75
import { GuCname } from '@guardian/cdk/lib/constructs/dns';
86
import { GuAllowPolicy } from '@guardian/cdk/lib/constructs/iam';
@@ -22,9 +20,6 @@ export interface ReportProps extends GuStackProps {
2220
| 'report.notifications.guardianapis.com'
2321
| 'report.notifications.code.dev-guardianapis.com';
2422
instanceMetricGranularity: '1Minute' | '5Minute';
25-
loggingStreamParameterName:
26-
| '/account/services/logging.stream.name'
27-
| '/account/services/logging.stream.name.code';
2823
minAsgSize: number;
2924
}
3025

@@ -103,20 +98,8 @@ export class Report extends GuStack {
10398
`/opt/aws-kinesis-agent/configure-aws-kinesis-agent ${region} mobile-log-aggregation-${stage} /var/log/${app}/application.log`,
10499
);
105100

106-
const vpcParameter = GuVpcParameter.getInstance(this);
107-
// This is necessary whilst dual-stacking because there is already a parameter called VpcId in the YAML template
108-
// Once the YAML template has been removed we should be able to drop this override
109-
vpcParameter.overrideLogicalId('GuCdkVpcId');
110-
111101
adjustCloudformationParameters(this);
112102

113-
// In the Mobile account there are separate Kinesis streams for CODE and PROD, so we can't use the account-wide
114-
// default
115-
const loggingStreamParameter =
116-
GuLoggingStreamNameParameter.getInstance(this);
117-
loggingStreamParameter.allowedValues = [props.loggingStreamParameterName];
118-
loggingStreamParameter.default = props.loggingStreamParameterName;
119-
120103
new GuCname(this, 'DnsRecordForReport', {
121104
app,
122105
domainName,

0 commit comments

Comments
 (0)