Skip to content

Commit

Permalink
feat(filterPattern): Adding option for overriding default filter pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-cottone committed Sep 17, 2018
1 parent 5c7be7a commit e2065bd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@ custom:
endpoint: some-elasticsearch-endpoint.us-east-1.es.amazonaws.com
```

#### filterPattern

(Optional) The filter pattern that the Cloudwatch subscription should use for your lambda
functions. Default is `[timestamp=*Z, request_id="*-*", event]`. See
[Cloudwatch filter pattern syntax](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/FilterAndPatternSyntax.html)
for more info.

```yaml
custom:
esLogs:
filterPattern: '[timestamp=*Z, request_id="*-*", event]'
```

#### includeApiGWLogs

(Optional) An option to be used in conjunction with the [serverless-aws-alias](https://github.com/HyperBrain/serverless-aws-alias) plugin. This will capture logs created by API Gateway and transport them to Elasticsearch.
Expand Down
7 changes: 5 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class ServerlessEsLogsPlugin {
private custom: { [name: string]: any };
private logProcesserDir: string = '_es-logs';
private logProcesserName: string = 'esLogsProcesser';
private defaultLambdaFilterPattern: string = '[timestamp=*Z, request_id="*-*", event]';
private defaultApiGWFilterPattern: string = '[apigw_request_id="*-*", event]';

constructor(serverless: any, options: { [name: string]: any }) {
this.serverless = serverless;
Expand Down Expand Up @@ -111,7 +113,7 @@ class ServerlessEsLogsPlugin {
}

private addApiGwCloudwatchSubscription(): void {
const filterPattern = '[apigw_request_id="*-*", event]';
const filterPattern = this.defaultApiGWFilterPattern;
const apiGatewayStageLogicalId = 'ApiGatewayStage';
const processorAliasLogicalId = 'EsLogsProcesserAlias';
const template = this.serverless.service.provider.compiledCloudFormationAliasTemplate;
Expand Down Expand Up @@ -178,7 +180,8 @@ class ServerlessEsLogsPlugin {
}

private addLambdaCloudwatchSubscriptions(): void {
const filterPattern = '[timestamp=*Z, request_id="*-*", event]';
const { esLogs } = this.custom;
const filterPattern = esLogs.filterPattern || this.defaultLambdaFilterPattern;
const template = this.serverless.service.provider.compiledCloudFormationTemplate;
const functions = this.serverless.service.getAllFunctions();
const processorLogicalId = 'EsLogsProcesserLambdaFunction';
Expand Down

0 comments on commit e2065bd

Please sign in to comment.