diff --git a/app/AppLoader.scala b/app/AppLoader.scala index e1d553ce..e4ac4457 100644 --- a/app/AppLoader.scala +++ b/app/AppLoader.scala @@ -1,4 +1,3 @@ -import modules.LogShipping import play.api.ApplicationLoader.Context import play.api.{Application, ApplicationLoader, LoggerConfigurator} import services.Config @@ -9,7 +8,6 @@ class AppLoader extends ApplicationLoader { LoggerConfigurator(context.environment.classLoader).foreach { _.configure(context.environment) } - new LogShipping() new AppComponents(context, Config()).application } diff --git a/app/modules/LogShipping.scala b/app/modules/LogShipping.scala deleted file mode 100644 index 017630a6..00000000 --- a/app/modules/LogShipping.scala +++ /dev/null @@ -1,44 +0,0 @@ -package modules - -import ch.qos.logback.classic.{Logger => LogbackLogger} -import com.gu.logback.appender.kinesis.KinesisAppender -import net.logstash.logback.layout.LogstashLayout -import org.slf4j.{LoggerFactory, Logger => SLFLogger} -import services.{AWS, AwsInstanceTags, Config} - - -class LogShipping extends AwsInstanceTags { - - val rootLogger = LoggerFactory.getLogger(SLFLogger.ROOT_LOGGER_NAME).asInstanceOf[LogbackLogger] - - rootLogger.info("bootstrapping kinesis appender if configured correctly") - - for ( - stack <- readTag("Stack"); - app <- readTag("App"); - stage <- readTag("Stage"); - streamName <- Config().logShippingStreamName - ) { - - rootLogger.info(s"bootstrapping kinesis appender with $stack -> $app -> $stage") - val context = rootLogger.getLoggerContext - - val layout = new LogstashLayout() - layout.setContext(context) - layout.setCustomFields(s"""{"stack":"$stack","app":"$app","stage":"$stage"}""") - layout.start() - - val appender = new KinesisAppender() - appender.setBufferSize(1000) - appender.setRegion(AWS.region.getName) - appender.setStreamName(streamName) - appender.setContext(context) - appender.setLayout(layout) - - appender.start() - - rootLogger.addAppender(appender) - rootLogger.info("Configured kinesis appender") - - } -} diff --git a/build.sbt b/build.sbt index 8a70dd9d..b40953ae 100644 --- a/build.sbt +++ b/build.sbt @@ -33,7 +33,6 @@ lazy val dependencies = Seq( "com.gu" %% "content-api-client-default" % "17.24.1", "com.gu" %% "tags-thrift-schema" % "2.8.1", "net.logstash.logback" % "logstash-logback-encoder" % "7.2", - "com.gu" % "kinesis-logback-appender" % "1.0.5", "org.slf4j" % "slf4j-api" % "1.7.12", "org.slf4j" % "jcl-over-slf4j" % "1.7.12", "com.gu" %% "panda-hmac-play_2-8" % "2.0.1", diff --git a/cloudformation/tag-manager.yaml b/cloudformation/tag-manager.yaml index 0486761b..3b00b7a4 100644 --- a/cloudformation/tag-manager.yaml +++ b/cloudformation/tag-manager.yaml @@ -41,6 +41,14 @@ Parameters: Description: The ARN of the SNS topic to notify when an alarm occurs Type: AWS::SSM::Parameter::Value Default: /account/services/alert.topic.arn + LoggingStreamName: + Type: AWS::SSM::Parameter::Value + Description: Name of the kinesis stream for logging to ELK (logs.gutools) + Default: /account/services/logging.stream.name + LoggingStreamArn: + Type: AWS::SSM::Parameter::Value + Description: ARN of the kinesis stream for logging to ELK (logs.gutools) + Default: /account/services/logging.stream Conditions: IsProd: !Equals [!Ref Stage, PROD] Mappings: @@ -195,6 +203,21 @@ Resources: Resource: '*' Roles: - !Ref 'TagManagerRole' + LogServerPolicy: + Type: AWS::IAM::Policy + Properties: + PolicyName: LogServerPolicy + PolicyDocument: + Version: '2012-10-17' + Statement: + - Effect: Allow + Action: + - kinesis:PutRecord + - kinesis:PutRecords + - kinesis:DescribeStream + Resource: !Ref LoggingStreamArn + Roles: + - !Ref 'TagManagerRole' TagManagerInstanceProfile: Type: AWS::IAM::InstanceProfile Properties: @@ -280,6 +303,12 @@ Resources: - Key: App Value: tag-manager PropagateAtLaunch: 'true' + - Key: LogKinesisStreamName + Value: !Ref 'LoggingStreamName' + PropagateAtLaunch: 'true' + - Key: SystemdUnit + Value: tag-manager.service + PropagateAtLaunch: 'true' TagManagerLaunchConfig: Type: AWS::AutoScaling::LaunchConfiguration Properties: diff --git a/conf/logback.xml b/conf/logback.xml index ac66bdba..53c3cf9f 100644 --- a/conf/logback.xml +++ b/conf/logback.xml @@ -16,9 +16,10 @@ - - %coloredLevel %logger{15} - %message%n%xException{5} - + + + + @@ -27,7 +28,6 @@ - - + - + \ No newline at end of file diff --git a/riff-raff.yaml b/riff-raff.yaml index 30bd1d2e..a11f9fbd 100644 --- a/riff-raff.yaml +++ b/riff-raff.yaml @@ -15,7 +15,7 @@ deployments: parameters: amiTags: BuiltBy: amigo - Recipe: editorial-tools-focal-java8-ARM + Recipe: editorial-tools-focal-java8-ARM-WITH-cdk-base AmigoStage: PROD amiEncrypted: true prependStackToCloudFormationStackName: false