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

CLI: Integrate CLI triage into this package #10131

Merged
merged 1 commit into from
Oct 27, 2021
Merged

Conversation

medikoo
Copy link
Contributor

@medikoo medikoo commented Oct 21, 2021

Addresses #9855

Integrates CLI triage logic found in:

It's covered by tests, and while I've ensured to replicate current logic, I've also applied a few optimization shortcuts. Please follow configured logic for details

Performance-wise this cuts down .5-.8s (on my machine) from the startup time of any command. Still, it's too early to open the champagne, as still, startup is slow on serverless CLI side (e.g. sls --version from taking 2s, got down to 1.2s, which is still not satisfactory)

@codecov
Copy link

codecov bot commented Oct 21, 2021

Codecov Report

Merging #10131 (1a10523) into master (204f205) will increase coverage by 0.01%.
The diff coverage is 86.59%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #10131      +/-   ##
==========================================
+ Coverage   85.35%   85.36%   +0.01%     
==========================================
  Files         337      338       +1     
  Lines       13722    13811      +89     
==========================================
+ Hits        11712    11790      +78     
- Misses       2010     2021      +11     
Impacted Files Coverage Δ
bin/serverless.js 39.13% <50.00%> (-10.87%) ⬇️
lib/cli/triage.js 90.80% <90.80%> (ø)
lib/plugins/aws/provider.js 94.29% <0.00%> (+0.01%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 204f205...1a10523. Read the comment docs.

pgrzesik
pgrzesik previously approved these changes Oct 22, 2021
Copy link
Contributor

@pgrzesik pgrzesik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing to add from me, looks great, great call with proper test coverage of the logic 👏

const componentsCommands = new Set(['registry', 'init', 'publish']);
if (componentsCommands.has(process.argv[2])) return '@serverless/components';
if (cliArgs.has('--help-components')) return '@serverless/components';
if (cliArgs.has('--target')) return '@serverless/components';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if a Framework or Tencent command is named registry, init or publish? Or has a --target option? Especially with plugins that could define these?

Copy link
Contributor Author

@medikoo medikoo Oct 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, we unconditionally run Components in such case (note Tencent is Components, as@serveless/components it's about both AWS and Tencent components engines here). --target is Tencent specific thing

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, so I guess the logic is: registry, init and publish are official commands. Plugins shouldn't override them.

Based on that statement, as long as we don't implement those commands in the Framework we can keep that if. The day we want to add these commands to the Framework, we can update/remove the if without problem (it's just an optimization).

So the last thing I see that is much less obvious is --target: that option is currently used by Tencent, but nothing forbids a plugin to add support for such an option, correct? It seems it might be safer to remove just this specific logic, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of this is controversial, but it's the price of attempting to host very different CLI programs under one name.

Currently, we do not forbid plugins from implementing registry, init, publish commands or add --target flag, yet it just won't work if they do, and definitely plugin author will be very confused seeing that.

We may implement some extra validation handling these specific cases (the same way we should probably add validation that forbids re-defining global aliases, as -h and -v), still, I'd create another issue for that, technically it's not in the scope of this PR (which just moves current triage logic into this repository)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand and agree.

What I'm focusing on is that for registry, init and publish, the compromise is reasonable. We already have that compromise with other CLI commands (deploy, package, etc.).

But for --target there is much more room for confusion, and the gain doesn't look obvious here. As such, the ratio gain/risk is lower: it seems that the compromise isn't worth it for that option.

Is there anything specific about that CLI option that I'm missing that makes it really really worth taking the risk?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mnapoli do this discussion belongs to this PR? Note this PR doesn't introduce any changes, all the goal is to move existing (as it works currently) triage logic into this repository.

Otherwise I totally agree, that it'll be great to rethink approach to --target, as it's quite dangerous to have such generic option taken over by Tencent completely

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So instead of removing the line here what should we do? Feel free to do a separate PR if you think that's better, I'm just saying we want to fix this, and you seem to agree on that…

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My point is, that any changes to triage, should rather be discussed separately, and I believe we also need consensus from @ole3021 on that.

e.g. now removing handling of --target here, and merging this, will change how triage works, and will change the experience for Tencent users

@medikoo
Copy link
Contributor Author

medikoo commented Oct 27, 2021

@pgrzesik can you re-review? @zongUMR helped to pick issues in initial version, and now after fixes it's confirmed to reflect current tirage logic.

What changed:

  • serverless.yml with top level component field is now recognized as @serverless/components project (in initial version it wasn't, it was recognized just in sub directories
  • SERVERLESS_PLATFORM_VENDOR was moved to be less significant as put initially. Initially I've configured it so value tencent unconditionally loads the @serverless/components but that was not right. This environment variable is used for triaging between AWS and Tencent on @serverless/components side, and not in CLI triage in general (it's also how it's configured currently in triage in components)

@medikoo medikoo requested a review from pgrzesik October 27, 2021 10:08
Copy link
Contributor

@pgrzesik pgrzesik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good 👍

@medikoo medikoo merged commit 415bdef into master Oct 27, 2021
@medikoo medikoo deleted the 1021-move-triage branch October 27, 2021 11:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants