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

Activated Cloudwatch Logs in Stage is overwritten in endpoint configuration #16

Open
patrickwerz opened this issue Oct 1, 2021 · 3 comments

Comments

@patrickwerz
Copy link

patrickwerz commented Oct 1, 2021

Hello,
thx for this great plugin.
I noticed the problem that when I activate execution logging on the stage level it gets falsely overwritten or not updated on the endpoint level.

custom:
apiGatewayThrottling:
maxConcurrentRequests: 1000
provider:
logs:
restApi:
level: INFO
accessLogging: true
executionLogging: true
roleManagedExternally: false

here the function

foo:
handler: handlers.main.api_proxy.handle
events:
- http:
path: v1/send-archive
method: POST
authorizer:
arn: ${cf:${self:custom.baseapplication}-${sls:stage}.CustomAuthorizerArn}
type: request
throttling:
maxRequestsPerSecond: 100
maxConcurrentRequests: 20
timeout: 30

Is this a known Problem? How can I fix it?

Thanks in advance,
Patrick

@DianaIonita
Copy link
Owner

DianaIonita commented Oct 6, 2021

Hi Patrick,

Thanks for raising this. I couldn't replicate the issue. I tried this yaml configuration:

provider:
  logs:
    restApi:
      level: INFO
      accessLogging: true
      executionLogging: true

custom:
  apiGatewayThrottling:
    maxRequestsPerSecond: 10
    maxConcurrentRequests: 5

functions:
  the-endpoint:
    handler: handler.handle
    events:
      - http:
          path: /
          method: GET
          throttling:
            maxRequestsPerSecond: 20
            maxConcurrentRequests: 10

The result is that logging is enabled, and throttling is configured on both the stage and the HTTP endpoint:

image

image

image

Are you using the latest version of the Serverless framework?

@patrickwerz
Copy link
Author

Thanks for your reply. I updated serverless framework and this plugin to the latest version. Today I created a new aws environment (serverless created a new stack) and everything worked fine as you described. It won't work for environments where you activate the exectionLogs after the creation (serverless update). Can you reproduce this?

@DianaIonita
Copy link
Owner

Hi @patrickwerz,

Thanks for bringing this to my attention. You're right about the behaviour of the plugin and I was able to reproduce it.

The issue seems to be around whether an endpoint inherits their settings from the stage, or whether it chooses to override stage settings.
When the serverless framework sets logs configuration, it sets it on the stage, and by default, endpoints would inherit the settings for accessLogging and executionLogging.
However, this plugin overrides throttling settings for each endpoint that has configured custom throttling settings. For some reason, when custom throttling settings are configured, API Gateway assumes custom settings for logging and metrics should also apply - therefore, they are no longer inherited from the stage. This happens in the UI as well, which gives you either this option:
image

or this option:
image

Since many other things can configure custom settings for an endpoint (the serverless framework itself, or some other plugins, and at different points in the deployment lifecycle), building a fix into the current workflow of the throttling plugin didn't seem like the right solution.
Instead, I added a command in the latest version of this plugin which can reset endpoint custom settings so that they inherit from stage.
It can be used like this:
sls reset-all-endpoint-settings
This will make it so that all endpoints in the project are in this state:
image

From here, once you redeploy your project, both throttling and logs configurations should be properly set for each endpoint.
Since it's just been built, I would advise you test it out in a lower environment first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants