Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow users to specify API Gateway Access Log format #6299

Merged
merged 7 commits into from Jun 27, 2019

Conversation

@alexdebrie
Copy link
Contributor

commented Jun 25, 2019

What did you implement:

Allow users to specify APIGW access log format.

How did you implement it:

The current behavior is to set up a default log format if the user has the following configuration:

# serverless.yml
provider:
  name: aws
  logs:
    restApi: true

With this change, the user can specify a format as the value for the restApi property, and that format will be passed along instead of the default format.

# serverless.yml
provider:
  name: aws
  logs:
    restApi: 
      format: '{ "requestId":"$context.requestId",   "ip": "$context.identity.sourceIp" }'

Todos:

  • Write tests
  • Write documentation
  • Fix linting errors
  • Make sure code coverage hasn't dropped
  • Provide verification config / commands / resources
  • Enable "Allow edits from maintainers" for this PR
  • Update the messages below

Is this ready for review?: YES
Is it a breaking change?: NO

@alexdebrie alexdebrie requested review from medikoo and pmuens Jun 25, 2019

@pmuens pmuens self-assigned this Jun 26, 2019

@pmuens pmuens added this to In progress in Serverless via automation Jun 26, 2019

@pmuens pmuens added this to the 1.47.0 milestone Jun 26, 2019

@dschep
Copy link
Member

left a comment

lgtm

Serverless automation moved this from In progress to Reviewer approved Jun 27, 2019

@medikoo
Copy link
Member

left a comment

Looks good, I have just same comment as @pmuens that nesting it within format property will design-wise be more bulletproof

Serverless automation moved this from Reviewer approved to Needs review Jun 27, 2019

@medikoo
Copy link
Member

left a comment

Just added one comment

name: aws
logs:
restApi:
logFormat: '{ "requestId":"$context.requestId", "ip": "$context.identity.sourceIp" }'

This comment has been minimized.

Copy link
@medikoo

medikoo Jun 27, 2019

Member

I wonder whether format would be better. as we're already in logs context.

Currently it's logs.restApi.logFormat, wouldn' it be cleaner to have logs.restApi.format ?

@pmuens what do you think?

This comment has been minimized.

Copy link
@alexdebrie

alexdebrie Jun 27, 2019

Author Contributor

Yep, I'm good with that. Seems repetitive. Will update.

@alexdebrie alexdebrie requested a review from medikoo Jun 27, 2019

@@ -168,6 +180,11 @@ function handleLogs() {
const region = this.options.region;
const logGroupName = `/aws/api-gateway/${service}-${stage}`;

let logFormat = defaultApiGatewayLogFormat;
if (typeof provider.logs.restApi === 'object' && provider.logs.restApi.format) {

This comment has been minimized.

Copy link
@medikoo

medikoo Jun 27, 2019

Member

I mentioned in previous comment, here we could just write if (logs.format), it'll be more maintanable :)

This comment has been minimized.

Copy link
@alexdebrie

alexdebrie Jun 27, 2019

Author Contributor

Ahh, I missed that initially. Updated

@alexdebrie alexdebrie requested a review from medikoo Jun 27, 2019

@alexdebrie alexdebrie force-pushed the APIGWAccessLogFormat branch from 709809c to 86fb74c Jun 27, 2019

@alexdebrie

This comment has been minimized.

Copy link
Contributor Author

commented Jun 27, 2019

Had to rebase + force-push to get the new Prettier formatting commands in here. Should pass CI now.

Serverless automation moved this from Needs review to Reviewer approved Jun 27, 2019

@@ -174,6 +186,11 @@ function handleLogs() {
const region = this.options.region;
const logGroupName = `/aws/api-gateway/${service}-${stage}`;

let logFormat = defaultApiGatewayLogFormat;
if (typeof logs === 'object' && logs.format) {

This comment has been minimized.

Copy link
@medikoo

medikoo Jun 27, 2019

Member

No need for typeof logs === object

For any no null and no undefined value property check is safe (and here we deal with a 100% truthy value, so obviously it's neither a null nor undefined)

This comment has been minimized.

Copy link
@medikoo

medikoo Jun 27, 2019

Member

But surely if (logs.format) may feel as a hacky shortcut (as what is the point to check for .format on true).

Hence I approved :)

This comment has been minimized.

Copy link
@alexdebrie

alexdebrie Jun 27, 2019

Author Contributor

Good point! Let's fix it while we're here. Another commit incoming ...

Serverless automation moved this from Reviewer approved to Needs review Jun 27, 2019

@alexdebrie alexdebrie requested a review from medikoo Jun 27, 2019

Serverless automation moved this from Needs review to Reviewer approved Jun 27, 2019

@alexdebrie alexdebrie merged commit 590e953 into master Jun 27, 2019

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
security/snyk - package.json (medikoo) No manifest changes detected

Serverless automation moved this from Reviewer approved to Done Jun 27, 2019

@alexdebrie alexdebrie deleted the APIGWAccessLogFormat branch Jun 27, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.