-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "feat(infra): remove logging stack as that is now handled inte…
- Loading branch information
Showing
5 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import o from 'ospec'; | ||
import { onLog } from '..'; | ||
|
||
o.spec('LogFilter', () => { | ||
o('should drop lambda logs', () => { | ||
o(onLog({ '@tags': ['Lambda log'] } as any)).equals(true); | ||
o(onLog({ '@tags': ['Flow Log'] } as any)).equals(undefined); | ||
}); | ||
|
||
o('should not die if "@tags" doesnt exist', () => { | ||
o(onLog({} as any)).equals(undefined); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { Vpc } from '@aws-cdk/aws-ec2'; | ||
import * as iam from '@aws-cdk/aws-iam'; | ||
import * as firehose from '@aws-cdk/aws-kinesisfirehose'; | ||
import * as s3 from '@aws-cdk/aws-s3'; | ||
import { StringParameter } from '@aws-cdk/aws-ssm'; | ||
import * as cdk from '@aws-cdk/core'; | ||
import { Env } from '@basemaps/shared'; | ||
import { LambdaLogShipperFunction, LogObject } from '@linzjs/cdk-elastic-shipper'; | ||
import { DeployEnv } from '../deploy.env'; | ||
|
||
const ConfigName = `/es-shipper-config/accounts`; | ||
|
||
export function onLog(lo: LogObject): boolean | void { | ||
if (lo['@tags']?.includes('Lambda log')) return true; | ||
} | ||
|
||
/** | ||
* Basemap's logging | ||
* | ||
* Store all logs generated by basemaps into a s3 bucket for long term storage | ||
* One logs are added to the bucket configure a lambda to ship them elastic search | ||
* for monitoring and alerting | ||
* | ||
* General log flow: | ||
* | ||
* Lambda -> CloudWatch -> Kinesis -> Kinesis Firehose -> S3 -> Lambda -> ElasticSearch | ||
*/ | ||
export class LoggingStack extends cdk.Stack { | ||
fireHose: firehose.CfnDeliveryStream; | ||
public shipper: LambdaLogShipperFunction; | ||
|
||
public constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) { | ||
super(scope, id, props); | ||
|
||
const logBucket = new s3.Bucket(this, 'LogBucket', { | ||
versioned: true, | ||
blockPublicAccess: s3.BlockPublicAccess.BLOCK_ALL, | ||
}); | ||
|
||
const accountId = Env.get(DeployEnv.LogAccountId); | ||
if (accountId != null && accountId !== '') { | ||
logBucket.grantReadWrite(new iam.AccountPrincipal(accountId)); | ||
} | ||
|
||
new cdk.CfnOutput(this, 'LogBucketArn', { value: logBucket.bucketArn }); | ||
|
||
const vpc = Vpc.fromLookup(this, 'ShipperVpc', { tags: { default: 'true' } }); | ||
|
||
const configParameter = StringParameter.fromStringParameterName(this, 'ShipperConfig', ConfigName); | ||
this.shipper = new LambdaLogShipperFunction(this, 'ShipperFunction', { configParameter, vpc, onLog }); | ||
this.shipper.addS3Source(logBucket); | ||
} | ||
} |