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
feat(CLI): Modern logs for package
command
#9956
Conversation
lib/plugins/aws/package/index.js
Outdated
@@ -102,6 +117,11 @@ class AwsPackage { | |||
await this.saveServiceState(); | |||
return this.serverless.pluginManager.spawn('aws:common:moveArtifactsToPackage'); | |||
}, | |||
|
|||
'after:aws:package:finalize:saveServiceState': () => { |
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'm a bit on the fence here - I was thinking about adding a new lifecycle hook that runs last instead of attaching with after
- what is your opinion @medikoo ?
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.
Yes, maybe let's add finalize
lifecycle hook (sort of counterpart of initialize
), it'll be run only in case of command success (otherwise we have error
)
Codecov Report
@@ Coverage Diff @@
## master #9956 +/- ##
==========================================
- Coverage 86.20% 86.15% -0.05%
==========================================
Files 329 330 +1
Lines 13032 13047 +15
==========================================
+ Hits 11234 11241 +7
- Misses 1798 1806 +8
Continue to review full report at Codecov.
|
lib/plugins/aws/package/index.js
Outdated
const isPackageCommand = | ||
this.serverless.processedInput.commands.length === 1 && | ||
this.serverless.processedInput.commands[0] === 'package'; |
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.
Shorter form could be: this.serverless.processedInput.commands.join(" ") === "package"
lib/plugins/aws/package/index.js
Outdated
@@ -102,6 +117,11 @@ class AwsPackage { | |||
await this.saveServiceState(); | |||
return this.serverless.pluginManager.spawn('aws:common:moveArtifactsToPackage'); | |||
}, | |||
|
|||
'after:aws:package:finalize:saveServiceState': () => { |
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.
Yes, maybe let's add finalize
lifecycle hook (sort of counterpart of initialize
), it'll be run only in case of command success (otherwise we have error
)
a6ff0b7
to
5eeb541
Compare
lib/plugins/aws/package/index.js
Outdated
@@ -102,6 +114,11 @@ class AwsPackage { | |||
await this.saveServiceState(); | |||
return this.serverless.pluginManager.spawn('aws:common:moveArtifactsToPackage'); | |||
}, | |||
|
|||
'success': () => { |
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've added a success
hook as finalize
is already very widely used and I didn't want to create confusion. I'm not fully sold on the name though so I'm up for suggestions
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.
Yes finalize
is used as a token for many lifecycle event groups, but technically it's similar to initialize
(it's used less, as doesn't have as many use cases, but it's used)
Having I think it'll be consistent to follow global initialize
with global finalize
as it follows terminology that's used with hooks. success
is something new and its semantics doesn't necessarily indicate it's about something to be invoked at the end.
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.
changed to finalize
👍
lib/classes/PluginManager.js
Outdated
@@ -638,6 +638,7 @@ class PluginManager { | |||
|
|||
try { | |||
await this.invoke(commandsArray); | |||
for (const { hook } of this.getHooks(['success'])) await hook(); |
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'm not sure about placement of this - I wanted to makes sure that it's only ran if there are not errors, but also ensure that we run error
hooks if success
hook fails. Do you think we should handle it this way or not run error
hook on success
hook failure?
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.
Good point.
I think it should be consistent with how we handle initialize
hook, so error in it should not trigger error
hook.
And as I inspect current logic, I find a bit surprising that we're processing backend request (showing notification) also when deploy crashes. Was that intended? Or was it accidentally added?
As look into it, I think proper logic should be as:
await runInitializeHooks();
deferredBackendNotificationRequest = handleTelemetry()
try {
await runNormalHooks();
} catch (error) {
try {
await runErrorHooks();
} catch {
await deferredBackendNotificationRequest;
throw error;
}
}
try {
await runFinalizeHooks();
} catch (error) {
await deferredBackendNotificationRequest;
throw error;
}
await processBackendNotificationRequest(await deferredBackendNotificationRequest);
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.
That's good point that you bring up here with notifications - I think this might've been introduced by a mistake as I don't remember that we wanted to show notifications in case of errors - I'm also not sure how it behaved previously, do you remember?
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.
As I check notifications were shown only on success, although logic may not look that clear:
serverless/lib/plugins/deploy.js
Lines 55 to 63 in bd4e792
} finally { | |
this.deferredBackendNotificationRequest = telemetryStoreLocally( | |
Object.assign(await generateTelemetryPayload(this.serverless), { command: 'deploy' }) | |
); | |
} | |
}, | |
'after:deploy:finalize': async () => { | |
if (!this.deferredBackendNotificationRequest) return null; | |
return this.deferredBackendNotificationRequest.then(processBackendNotificationRequest); |
We were reporting telemetry before deploy logic (but unconditionally after packaging no matter if it succeeded or not), and the result was passed to backend notifications processor with last hook (and that one is not triggered if there's an error on the way)
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.
Also logic we're discussing here, takes place only if there's a local fallback from older major release.
In other cases telemetry is handled in main script, and over there notification is only shown on success.
So we can treat it as bug here, that we're doing otherwise
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.
Thanks for the clarification, that sounds like a bug to me then - should I adjust it here to only show notification in situations where the command did not throw an error?
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.
Yes I would definitely do it. It can be two commits (one that fixes issue, and second that adds handling of final hook)
3aeaded
to
eaa1030
Compare
eaa1030
to
f407287
Compare
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've changed a bit logic in pluginManager.run
to something afaik bit cleaner (more comprehensible)
Additionally I've merged commits related to package logging into one commit
Addresses: #9860