Skip to content

CLOUDP-113344: Improve time of new version checker #1010

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

Merged
merged 20 commits into from
Mar 14, 2022
Merged

CLOUDP-113344: Improve time of new version checker #1010

merged 20 commits into from
Mar 14, 2022

Conversation

blva
Copy link
Collaborator

@blva blva commented Mar 1, 2022

Proposed changes

Jira ticket: CLOUDP-113344

  • Inspiration for the approach -> https://github.com/cli/cli/blob/trunk/cmd/gh/main.go
  • Save the latest retrieved version in /Users/<user>/.config/mongocli/rstate.yaml and update it every 24 hours.
  • Save the homebrew paths in /Users/<user>/.config/mongocli/brew.yaml and update it every 24 hours.
  • Discarted go routine change because 1) It didn't offer considerable time reduction 2) It didn't work for ops-manager/atlas commands.

Checklist

  • I have signed the MongoDB CLA
  • I have added tests that prove my fix is effective or that my feature works
  • I have added any necessary documentation in document requirements section listed in CONTRIBUTING.md (if appropriate)
  • I have addressed the @mongodb/docs-cloud-team comments (if appropriate)
  • I have updated e2e/E2E-TESTS.md (if an e2e test has been added)
  • I have run make fmt and formatted my code

Help me testing this on a non-M1 machine:

git fetch 
git checkout test-version-feature
make build
./bin/mongocli config list

Further comments

  • note: first run will still take time as files will be saved for the first time.

Before:

➜ mongocli git[CLOUDP-113344](https://jira.mongodb.org/browse/CLOUDP-113344)) ✗ ./bin/mongocli config list
PROFILE NAME
default
test

A new version of mongocli is available 'v1.23.0'!
To upgrade, see: https://dochub.mongodb.org/core/mongocli-install.

To disable this alert, run "mongocli config set skip_update_check true".
1.53327125s

After (M1)
1st run

➜  mongocli git:(CLOUDP-113344) ✗ mongoclidev config list
PROFILE NAME
default
test

A new version of mongocli is available 'v1.23.1'!
To upgrade, see: https://dochub.mongodb.org/core/mongocli-install.

To disable this alert, run "mongocli config set skip_update_check true".
Feature version checker time: 481.586334ms
➜  mongocli git:(CLOUDP-113344) ✗ mongoclidev config list
PROFILE NAME
default
test

A new version of mongocli is available 'v1.23.1'!
To upgrade, see: https://dochub.mongodb.org/core/mongocli-install.

To disable this alert, run "mongocli config set skip_update_check true".
Feature version checker time: 164.084µs

@blva blva marked this pull request as ready for review March 1, 2022 17:06
@blva blva requested a review from a team March 1, 2022 17:06
Copy link
Collaborator

@andreaangiolillo andreaangiolillo left a comment

Choose a reason for hiding this comment

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

Could you add in the description of the PR the strategy that you have used to improve the timing of this feature? Thanks! : )

@blva blva requested review from gssbzn and a team March 1, 2022 17:21
@blva blva requested a review from gssbzn March 2, 2022 10:58
Copy link
Collaborator

@gssbzn gssbzn left a comment

Choose a reason for hiding this comment

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

Thanks for tracking and trying to improve on the timing here, I left some comments on code organization.
I have a couple of recommendations based on what looks to be around abstractions, either premature or leaky.

File saving could be improved, either by relaying on viper, or by making the code less abstract.

I don't think a "printer" abstraction should have access to the file system, this seems to be a leaky abstraction, if the responsability of the interface is to "print" (based on name) it should jsut do that, consider ways to simplify printer and favour composition so that the dependency on the file system can be removed.
Finally lumping brew configs and latest release meta info in the same abstraction may not be the right call, consider if they can be split and just like with printer and the file system think of ways to favour composition over nested dependencies, these problems becomes somewhat evident by looking at this line:

func NewPrinterWithFinder(ctx context.Context, f VersionFinder) Printer {
	return &printer{c: ctx, finder: f, store: NewStore(afero.NewOsFs())}
}

your printer has a direct dependency on "Store" (whatever that may mean) which in turn has a direct dependency on afero, and encapsulating this chain of dependencies is one of the reasons reviewing this PR takes a while as it takes a bit of scrolling around to follow the dependencies and interactions

@blva blva requested a review from gssbzn March 3, 2022 15:20
@blva blva requested a review from andreaangiolillo March 4, 2022 14:32
@andreaangiolillo
Copy link
Collaborator

andreaangiolillo commented Mar 4, 2022

My machine (not M1):

./bin/mongocli config list

PROFILE NAME

A new version of mongocli is available 'v1.23.0'!
To upgrade, see: https://dochub.mongodb.org/core/mongocli-install.

To disable this alert, run "mongocli config set skip_update_check true".
2.29895842s
➜  ~/workspace/mongocli git:(test-version-feature) ./bin/mongocli config list

PROFILE NAME

A new version of mongocli is available 'v1.23.0'!
To upgrade, see: https://dochub.mongodb.org/core/mongocli-install.

To disable this alert, run "mongocli config set skip_update_check true".
343.049µs

Copy link
Collaborator

@andreaangiolillo andreaangiolillo left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Collaborator

@gssbzn gssbzn left a comment

Choose a reason for hiding this comment

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

Almost there

Comment on lines 28 to 29
ExecutablePath string `yaml:"path"`
HomePath string `yaml:"home_path"`
Copy link
Collaborator

@gssbzn gssbzn Mar 4, 2022

Choose a reason for hiding this comment

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

[q] I'm not sure I understand why we store these paths, wouldn't storing isHomebrew: <true|false> be enough?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, storing a boolean is enough, will update

Copy link
Collaborator Author

@blva blva Mar 14, 2022

Choose a reason for hiding this comment

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

During the pair programming we ended up leaving both for usage, LMK if you want to still have boolean only stored

@blva blva requested review from gssbzn and andreaangiolillo March 11, 2022 16:49
Copy link
Collaborator

@andreaangiolillo andreaangiolillo left a comment

Choose a reason for hiding this comment

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

LGTM. I would wait for Gustavo to review this PR as he paired with you. Thanks for all your work on this one!

gssbzn
gssbzn previously approved these changes Mar 14, 2022
Copy link
Collaborator

@gssbzn gssbzn left a comment

Choose a reason for hiding this comment

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

LGTM comments are not blcoking

@blva blva dismissed stale reviews from gssbzn and andreaangiolillo via fbeddc4 March 14, 2022 12:49
Copy link

@threebee threebee left a comment

Choose a reason for hiding this comment

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

restamp

@blva blva merged commit 9d57ffe into master Mar 14, 2022
@blva blva deleted the CLOUDP-113344 branch March 14, 2022 13:04
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

Successfully merging this pull request may close these issues.

4 participants