Skip to content

Commit 0f40810

Browse files
authored
Merge pull request #1631 from guardian/aa/devx-logs
feat: Switch to `devx-logs`
2 parents 464a092 + 0b298b0 commit 0f40810

File tree

13 files changed

+126
-31
lines changed

13 files changed

+126
-31
lines changed

.scala-steward.conf

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,4 @@ updates.pin = [
3232

3333
# Pin Play framework to 2.9 until we've migrated the code from Akka to Pekko
3434
{ groupId = "com.typesafe.play", artifactId = "sbt-plugin", version = "2.9.1" },
35-
36-
# Pin logstash to 1.8 until we have bumped simple-configuration
37-
{ groupId = "com.gu", artifactId = "mobile-logstash-encoder", version = "1.1.8" },
3835
]

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,11 @@ lazy val common = project
118118
"org.tpolecat" %% "doobie-specs2" % doobieVersion % Test,
119119
"org.tpolecat" %% "doobie-scalatest" % doobieVersion % Test,
120120
"org.tpolecat" %% "doobie-h2" % doobieVersion % Test,
121-
"com.gu" %% "mobile-logstash-encoder" % "1.1.8",
122121
"com.gu" %% "simple-configuration-ssm" % simpleConfigurationVersion,
123122
"org.postgresql" % "postgresql" % "42.7.7",
124123
"ch.qos.logback" % "logback-core" % logbackVersion,
125124
"ch.qos.logback" % "logback-classic" % logbackVersion,
125+
"net.logstash.logback" % "logstash-logback-encoder" % "8.1"
126126
),
127127
fork := true,
128128
startDynamoDBLocal := startDynamoDBLocal.dependsOn(Test / compile).value,

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

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@ exports[`The Registration stack matches the snapshot for CODE 1`] = `
7676
"Description": "The HostedZone, should contain the trailing dot zone.example.com.",
7777
"Type": "String",
7878
},
79+
"LoggingStreamName": {
80+
"AllowedValues": [
81+
"/account/services/logging.stream.name.code",
82+
"/account/services/logging.stream.name",
83+
],
84+
"Description": "SSM parameter containing the Name (not ARN) on the kinesis stream",
85+
"Type": "AWS::SSM::Parameter::Value<String>",
86+
},
7987
"NotEnough200sPerDayThreshold": {
8088
"Description": "Alarm if less than too many 200s. This value was based on just below 2 standard deviations from the mean over 6 weeks of data.",
8189
"Type": "Number",
@@ -156,7 +164,10 @@ exports[`The Registration stack matches the snapshot for CODE 1`] = `
156164
},
157165
},
158166
{
159-
"Action": "ec2:DescribeTags",
167+
"Action": [
168+
"ec2:DescribeTags",
169+
"ec2:DescribeInstances",
170+
],
160171
"Effect": "Allow",
161172
"Resource": "*",
162173
},
@@ -729,6 +740,13 @@ exports[`The Registration stack matches the snapshot for CODE 1`] = `
729740
"PropagateAtLaunch": true,
730741
"Value": "guardian/mobile-n10n",
731742
},
743+
{
744+
"Key": "LogKinesisStreamName",
745+
"PropagateAtLaunch": true,
746+
"Value": {
747+
"Ref": "LoggingStreamName",
748+
},
749+
},
732750
{
733751
"Key": "Stack",
734752
"PropagateAtLaunch": true,
@@ -739,6 +757,11 @@ exports[`The Registration stack matches the snapshot for CODE 1`] = `
739757
"PropagateAtLaunch": true,
740758
"Value": "CODE",
741759
},
760+
{
761+
"Key": "SystemdUnit",
762+
"PropagateAtLaunch": true,
763+
"Value": "registration.service",
764+
},
742765
],
743766
"VPCZoneIdentifier": {
744767
"Ref": "PrivateSubnets",
@@ -781,7 +804,6 @@ exports[`The Registration stack matches the snapshot for CODE 1`] = `
781804
"#!/bin/bash -ev
782805
aws --region \${AWS::Region} s3 cp s3://\${DistBucket}/\${Stack}/\${Stage}/\${App}/\${App}_1.0-latest_all.deb /tmp
783806
dpkg -i /tmp/\${App}_1.0-latest_all.deb
784-
/opt/aws-kinesis-agent/configure-aws-kinesis-agent \${AWS::Region} mobile-log-aggregation-\${Stage} /var/log/\${App}/application.log
785807
",
786808
{
787809
"App": {
@@ -907,6 +929,14 @@ exports[`The Registration stack matches the snapshot for PROD 1`] = `
907929
"Description": "The HostedZone, should contain the trailing dot zone.example.com.",
908930
"Type": "String",
909931
},
932+
"LoggingStreamName": {
933+
"AllowedValues": [
934+
"/account/services/logging.stream.name.code",
935+
"/account/services/logging.stream.name",
936+
],
937+
"Description": "SSM parameter containing the Name (not ARN) on the kinesis stream",
938+
"Type": "AWS::SSM::Parameter::Value<String>",
939+
},
910940
"NotEnough200sPerDayThreshold": {
911941
"Description": "Alarm if less than too many 200s. This value was based on just below 2 standard deviations from the mean over 6 weeks of data.",
912942
"Type": "Number",
@@ -987,7 +1017,10 @@ exports[`The Registration stack matches the snapshot for PROD 1`] = `
9871017
},
9881018
},
9891019
{
990-
"Action": "ec2:DescribeTags",
1020+
"Action": [
1021+
"ec2:DescribeTags",
1022+
"ec2:DescribeInstances",
1023+
],
9911024
"Effect": "Allow",
9921025
"Resource": "*",
9931026
},
@@ -1560,6 +1593,13 @@ exports[`The Registration stack matches the snapshot for PROD 1`] = `
15601593
"PropagateAtLaunch": true,
15611594
"Value": "guardian/mobile-n10n",
15621595
},
1596+
{
1597+
"Key": "LogKinesisStreamName",
1598+
"PropagateAtLaunch": true,
1599+
"Value": {
1600+
"Ref": "LoggingStreamName",
1601+
},
1602+
},
15631603
{
15641604
"Key": "Stack",
15651605
"PropagateAtLaunch": true,
@@ -1570,6 +1610,11 @@ exports[`The Registration stack matches the snapshot for PROD 1`] = `
15701610
"PropagateAtLaunch": true,
15711611
"Value": "PROD",
15721612
},
1613+
{
1614+
"Key": "SystemdUnit",
1615+
"PropagateAtLaunch": true,
1616+
"Value": "registration.service",
1617+
},
15731618
],
15741619
"VPCZoneIdentifier": {
15751620
"Ref": "PrivateSubnets",
@@ -1612,7 +1657,6 @@ exports[`The Registration stack matches the snapshot for PROD 1`] = `
16121657
"#!/bin/bash -ev
16131658
aws --region \${AWS::Region} s3 cp s3://\${DistBucket}/\${Stack}/\${Stage}/\${App}/\${App}_1.0-latest_all.deb /tmp
16141659
dpkg -i /tmp/\${App}_1.0-latest_all.deb
1615-
/opt/aws-kinesis-agent/configure-aws-kinesis-agent \${AWS::Region} mobile-log-aggregation-\${Stage} /var/log/\${App}/application.log
16161660
",
16171661
{
16181662
"App": {

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,11 @@ exports[`The Report stack matches the snapshot for CODE 1`] = `
150150
"PropagateAtLaunch": true,
151151
"Value": "CODE",
152152
},
153+
{
154+
"Key": "SystemdUnit",
155+
"PropagateAtLaunch": true,
156+
"Value": "report.service",
157+
},
153158
],
154159
"TargetGroupARNs": [
155160
{
@@ -1616,8 +1621,7 @@ aws s3 cp 's3://",
16161621
"Ref": "DistributionBucketName",
16171622
},
16181623
"/mobile-notifications/CODE/report/report_1.0-latest_all.deb' '/report/report_1.0-latest_all.deb'
1619-
dpkg -i /report/report_1.0-latest_all.deb
1620-
/opt/aws-kinesis-agent/configure-aws-kinesis-agent eu-west-1 mobile-log-aggregation-CODE /var/log/report/application.log",
1624+
dpkg -i /report/report_1.0-latest_all.deb",
16211625
],
16221626
],
16231627
},
@@ -1821,6 +1825,11 @@ exports[`The Report stack matches the snapshot for PROD 1`] = `
18211825
"PropagateAtLaunch": true,
18221826
"Value": "PROD",
18231827
},
1828+
{
1829+
"Key": "SystemdUnit",
1830+
"PropagateAtLaunch": true,
1831+
"Value": "report.service",
1832+
},
18241833
],
18251834
"TargetGroupARNs": [
18261835
{
@@ -3287,8 +3296,7 @@ aws s3 cp 's3://",
32873296
"Ref": "DistributionBucketName",
32883297
},
32893298
"/mobile-notifications/PROD/report/report_1.0-latest_all.deb' '/report/report_1.0-latest_all.deb'
3290-
dpkg -i /report/report_1.0-latest_all.deb
3291-
/opt/aws-kinesis-agent/configure-aws-kinesis-agent eu-west-1 mobile-log-aggregation-PROD /var/log/report/application.log",
3299+
dpkg -i /report/report_1.0-latest_all.deb",
32923300
],
32933301
],
32943302
},

cdk/lib/report.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ export class Report extends GuStack {
8585
timeout: Duration.seconds(10), // The default is 5s
8686
unhealthyThresholdCount: 10, // This also seems unusually high - the default is 2
8787
},
88+
applicationLogging: {
89+
enabled: true,
90+
systemdUnitName: app,
91+
},
8892
});
8993

9094
//TODO check if this customisation is really necessary (it has been copied across from
@@ -93,11 +97,6 @@ export class Report extends GuStack {
9397
const cfnAsg = autoScalingGroup.node.defaultChild as CfnAutoScalingGroup;
9498
cfnAsg.healthCheckGracePeriod = Duration.seconds(400).toSeconds();
9599

96-
//TODO replace configure-aws-kinesis-agent with devx-logs?
97-
autoScalingGroup.userData.addCommands(
98-
`/opt/aws-kinesis-agent/configure-aws-kinesis-agent ${region} mobile-log-aggregation-${stage} /var/log/${app}/application.log`,
99-
);
100-
101100
adjustCloudformationParameters(this);
102101

103102
new GuCname(this, 'DnsRecordForReport', {

notification/conf/logback.xml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,22 @@
1010
<maxHistory>30</maxHistory>
1111
</rollingPolicy>
1212

13-
<encoder class="com.gu.mobile.logback.MobileLogstashEncoder">
14-
<defaultAppName>notifications</defaultAppName>
13+
<encoder>
14+
<pattern>%date [%thread] %-5level {%mdc} %logger{36}:%L - %msg%n%xException{15}</pattern>
1515
</encoder>
1616
</appender>
1717

1818
<appender name="ASYNCFILE" class="ch.qos.logback.classic.AsyncAppender">
1919
<appender-ref ref="FILE" />
2020
</appender>
2121

22+
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
23+
<encoder class="net.logstash.logback.encoder.LogstashEncoder" />
24+
</appender>
25+
2226
<root level="INFO">
2327
<appender-ref ref="ASYNCFILE"/>
28+
<appender-ref ref="STDOUT"/>
2429
</root>
2530

2631
</configuration>

notification/conf/notification.yaml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,12 @@ Parameters:
9595
RunbookCopy:
9696
Type: String
9797
Default: <<<Runbook|https://docs.google.com/document/d/1aJMytnPGeWH8YLpD2_66doxqyr8dPvAVonYIOG-zmOA>>>
98-
98+
LoggingStreamName:
99+
Type: AWS::SSM::Parameter::Value<String>
100+
Description: SSM parameter containing the Name (not ARN) on the kinesis stream
101+
AllowedValues:
102+
- /account/services/logging.stream.name.code
103+
- /account/services/logging.stream.name
99104
Resources:
100105
DnsRecord:
101106
Type: AWS::Route53::RecordSet
@@ -238,7 +243,9 @@ Resources:
238243
Resource:
239244
- !Sub arn:aws:s3:::${DistBucket}/*
240245
- !Sub arn:aws:s3:::${S3TopicCountBucket}/*
241-
- Action: ec2:DescribeTags
246+
- Action:
247+
- ec2:DescribeTags
248+
- ec2:DescribeInstances
242249
Effect: Allow
243250
Resource: '*'
244251
- Action:
@@ -324,6 +331,12 @@ Resources:
324331
PropagateAtLaunch: true
325332
Value:
326333
!FindInMap [Constants, App, Value]
334+
- Key: SystemdUnit
335+
Value: notification.service
336+
PropagateAtLaunch: true
337+
- Key: LogKinesisStreamName
338+
Value: !Ref LoggingStreamName
339+
PropagateAtLaunch: true
327340
VPCZoneIdentifier: !Ref PrivateSubnets
328341
NotificationInstanceProfile:
329342
Type: AWS::IAM::InstanceProfile
@@ -350,7 +363,6 @@ Resources:
350363
#!/bin/bash -ev
351364
aws --region ${AWS::Region} s3 cp s3://${DistBucket}/${Stack}/${Stage}/${App}/${App}_1.0-latest_all.deb /tmp
352365
dpkg -i /tmp/${App}_1.0-latest_all.deb
353-
/opt/aws-kinesis-agent/configure-aws-kinesis-agent ${AWS::Region} mobile-log-aggregation-${Stage} /var/log/${App}/application.log
354366
- Stack: !FindInMap [Constants, Stack, Value]
355367
App: !FindInMap [Constants, App, Value]
356368
ScaleDownPolicy:

notification/conf/riff-raff.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@ deployments:
77
parameters:
88
amiEncrypted: true
99
amiTags:
10-
Recipe: mobile-java11-jammy-ARM
10+
Recipe: mobile-java11-jammy-ARM-with-cdk-base
1111
AmigoStage: PROD
1212
templatePath: notification.yaml
1313
templateStageParameters:
1414
CODE:
1515
SloSqsQueueArn: /notifications/CODE/mobile-notifications/notifications.queues.sloMonitoringArn
16+
LoggingStreamName: /account/services/logging.stream.name.code
1617
PROD:
1718
SloSqsQueueArn: /notifications/PROD/mobile-notifications/notifications.queues.sloMonitoringArn
19+
LoggingStreamName: /account/services/logging.stream.name
1820
notification:
1921
type: autoscaling
2022
parameters:

registration/conf/logback.xml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,22 @@
1010
<maxHistory>30</maxHistory>
1111
</rollingPolicy>
1212

13-
<encoder class="com.gu.mobile.logback.MobileLogstashEncoder">
14-
<defaultAppName>notifications</defaultAppName>
13+
<encoder>
14+
<pattern>%date [%thread] %-5level {%mdc} %logger{36}:%L - %msg%n%xException{15}</pattern>
1515
</encoder>
1616
</appender>
1717

1818
<appender name="ASYNCFILE" class="ch.qos.logback.classic.AsyncAppender">
1919
<appender-ref ref="FILE" />
2020
</appender>
2121

22+
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
23+
<encoder class="net.logstash.logback.encoder.LogstashEncoder" />
24+
</appender>
25+
2226
<root level="INFO">
2327
<appender-ref ref="ASYNCFILE"/>
28+
<appender-ref ref="STDOUT"/>
2429
</root>
2530

2631
</configuration>

registration/conf/registration.yaml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ Parameters:
8080
RunbookCopy:
8181
Type: String
8282
Default: <<<Runbook|https://docs.google.com/document/d/1aJMytnPGeWH8YLpD2_66doxqyr8dPvAVonYIOG-zmOA>>>
83+
LoggingStreamName:
84+
Type: AWS::SSM::Parameter::Value<String>
85+
Description: SSM parameter containing the Name (not ARN) on the kinesis stream
86+
AllowedValues:
87+
- /account/services/logging.stream.name.code
88+
- /account/services/logging.stream.name
8389
Resources:
8490
DistributionInstanceProfile:
8591
Type: AWS::IAM::InstanceProfile
@@ -105,7 +111,9 @@ Resources:
105111
- Action: s3:GetObject
106112
Effect: Allow
107113
Resource: !Sub arn:aws:s3:::${DistBucket}/*
108-
- Action: ec2:DescribeTags
114+
- Action:
115+
- ec2:DescribeTags
116+
- ec2:DescribeInstances
109117
Effect: Allow
110118
Resource: '*'
111119
- Action:
@@ -267,6 +275,12 @@ Resources:
267275
PropagateAtLaunch: true
268276
Value:
269277
!FindInMap [Constants, App, Value]
278+
- Key: SystemdUnit
279+
Value: registration.service
280+
PropagateAtLaunch: true
281+
- Key: LogKinesisStreamName
282+
Value: !Ref LoggingStreamName
283+
PropagateAtLaunch: true
270284
VPCZoneIdentifier: !Ref PrivateSubnets
271285
RegistrationLaunchConfig:
272286
Type: AWS::AutoScaling::LaunchConfiguration
@@ -287,7 +301,6 @@ Resources:
287301
#!/bin/bash -ev
288302
aws --region ${AWS::Region} s3 cp s3://${DistBucket}/${Stack}/${Stage}/${App}/${App}_1.0-latest_all.deb /tmp
289303
dpkg -i /tmp/${App}_1.0-latest_all.deb
290-
/opt/aws-kinesis-agent/configure-aws-kinesis-agent ${AWS::Region} mobile-log-aggregation-${Stage} /var/log/${App}/application.log
291304
- Stack: !FindInMap [Constants, Stack, Value]
292305
App: !FindInMap [Constants, App, Value]
293306
ScaleDownPolicy:

0 commit comments

Comments
 (0)