-
Notifications
You must be signed in to change notification settings - Fork 9
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
fix: avoid logging the same resolved layer multiple times #33
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello! First, Thank you for your contribution. I'm so sorry for late - I've been super busy.
Before merging this, I need some changes. Let me know if you need any further assistance!
index.js
Outdated
@@ -199,6 +200,10 @@ class ServerlessPlugin { | |||
args.unshift(TAG); | |||
} | |||
|
|||
// Avoid logging the same resolved layer multiple times |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't place business logic for specific use-case here. Think log
method as console.log
. This method should be for general logging. Move this to replaceLayerVersions
method implementation instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- declare set which stores "resolved" layer arn
- if set does not contain given layer arn, log & store given layer arn, otherwise, just skip.
and It would be appreciated if you would implement "log level" option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, I've updated the PR.
I just didn't do anything about "log level" because I didn't quite get what this option would do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought we can implement a plugin option for controlling log output verbosity.
For example,
- INFO: Most verbose logging output. Prints any informational log (e.g. prints entire layer replacements without deduplication, with entire context including function name and layer arn)
- WARN: Prints warnings only. Prints warnings only (e.g. prints deduplicated layer replacements - which current PR does)
- ERROR: Prints errors only. Prints errors only (e.g. unknown layer arn)
Then, Users can control log verbosity like this:
// serverless.yml
// ... (truncated)
plugins:
- serverless-latest-layer-version
custom:
latestLayerVersion:
logLevel: WARN
Anyway this isn't mandatory for merging. You can ignore this request ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will happily ignore this request, but I think this would be a great addition to this plugin. I've created a new issue for this feature: #34.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for creating an issue for that 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One minor thing...
index.js
Outdated
@@ -12,6 +12,7 @@ class ServerlessPlugin { | |||
this.serverless = serverless; | |||
this.provider = serverless.getProvider("aws"); | |||
this.options = options; | |||
this.resolvedLayers = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer Set
over Array
to store unique items.
this.resolvedLayers = []; | |
this.resolvedLayerSet = new Set(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
index.js
Outdated
@@ -181,6 +182,9 @@ class ServerlessPlugin { | |||
const resolvedLayerArn = arnVersionMap.get(node); | |||
if (resolvedLayerArn) { | |||
this.update(resolvedLayerArn); | |||
// Avoid logging the same resolved layer multiple times | |||
if (self.resolvedLayers.some(item => item === resolvedLayerArn)) return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then this can be expressed as more cleaner way :)
if (self.resolvedLayers.some(item => item === resolvedLayerArn)) return | |
if (self.resolvedLayers.has(resolvedLayerArn)) { | |
return; | |
} | |
self.resolvedLayers.add(resolvedLayerArn); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Really appreciated it!
Just merged this PR and new release will be automatically published to npm. Stay tuned! |
## [2.1.2](v2.1.1...v2.1.2) (2022-11-08) ### Bug Fixes * avoid logging the same resolved layer multiple times ([#33](#33)) ([33f289f](33f289f))
🎉 This PR is included in version 2.1.2 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Okay, v2.1.2 just published to npm. Please let me know that release fixes your issue (or if you need anything further). |
In my use case, I have about 30 lambdas and each one of them have the same 2 layers, which makes the terminal look like this on every deploy:
This small fix caches the resolved layers and only log once for each one, making it look a little more pleasent.