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

Use third-party library for reporting install/uninstall progress #3623

Merged
merged 14 commits into from
Oct 25, 2023

Conversation

fearful-symmetry
Copy link
Contributor

@fearful-symmetry fearful-symmetry commented Oct 17, 2023

What does this PR do?

fixes #3607

This uses a third-party library for creating a spinner that reports progress during install/uninstall operations.

Why is it important?

The old code was causing some flaky tests, and for such a small bit of code, it was a bit easier to just use a third-party library.

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have added tests that prove my fix is effective or that my feature works
  • I have added an entry in ./changelog/fragments using the changelog tool
  • I have added an integration test or an E2E test

@fearful-symmetry fearful-symmetry requested a review from a team as a code owner October 17, 2023 18:28
@fearful-symmetry fearful-symmetry self-assigned this Oct 17, 2023
@fearful-symmetry fearful-symmetry added the Team:Elastic-Agent Label for the Agent team label Oct 17, 2023
@elasticmachine
Copy link
Contributor

Pinging @elastic/elastic-agent (Team:Elastic-Agent)

@mergify
Copy link
Contributor

mergify bot commented Oct 17, 2023

This pull request does not have a backport label. Could you fix it @fearful-symmetry? 🙏
To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-v./d./d./d is the label to automatically backport to the 8./d branch. /d is the digit

NOTE: backport-skip has been added to this pull request.

@elasticmachine
Copy link
Contributor

elasticmachine commented Oct 17, 2023

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2023-10-23T15:52:48.457+0000

  • Duration: 28 min 11 sec

Test stats 🧪

Test Results
Failed 0
Passed 6553
Skipped 59
Total 6612

💚 Flaky test report

Tests succeeded.

🤖 GitHub comments

Expand to view the GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

  • /package : Generate the packages.

  • run integration tests : Run the Elastic Agent Integration tests.

  • run end-to-end tests : Generate the packages and run the E2E Tests.

  • run elasticsearch-ci/docs : Re-trigger the docs validation. (use unformatted text in the comment!)

@elasticmachine
Copy link
Contributor

elasticmachine commented Oct 17, 2023

🌐 Coverage report

Name Metrics % (covered/total) Diff
Packages 98.824% (84/85) 👍
Files 67.105% (204/304) 👍
Classes 66.068% (368/557) 👎 -0.121
Methods 53.284% (1160/2177) 👎 -0.299
Lines 39.586% (13657/34500) 👎 -0.213
Conditionals 100.0% (0/0) 💚

@ycombinator
Copy link
Contributor

ycombinator commented Oct 17, 2023

At that point we're getting kind of complicated for what this is, and we might just want to find a third-party library like https://github.com/schollz/progressbar to just do this for us, which is also an option here. Honestly open to the third-party library idea for a follow-up to this; not sure why we're DIY'ing this.

I'm ++ to using a third-party library here. I've been thinking along the same lines myself.

The initial implementation was done as one of three OnWeek projects (so, pretty quickly) and, at the time, I thought it would be simpler to DIY this especially since we weren't doing anything too fancy like repainting the screen (like some third party progress trackers can do). I honestly hadn't thought it would introduce so much flakiness and headache. But after seeing that over the past few weeks, I'm very much in favor of just replacing this with a third-party library at this point.

@fearful-symmetry fearful-symmetry changed the title More aggressive mutexes and flags in progress tracker Use third-party library for reporting install/uninstall progress Oct 18, 2023
@fearful-symmetry
Copy link
Contributor Author

Alright, so, it looks like SonarQube is counting all the one-line log statements I added towards the code coverage percentage, which is...not great.

@ycombinator
Copy link
Contributor

I like the new progress bar and the time counter too!

There are two things I was wondering if we could change:

  1. Would it be possible to display all the steps? That is, when a step completes, would it be possible to leave it on the screen without it being replaced by the next step?

  2. The install ends like so:

    $ sudo ./elastic-agent install
    Elastic Agent will be installed at /Library/Elastic/Agent and will run as a service. Do you want to continue? [Y/n]:y
    Do you want to enroll this Agent into Fleet? [Y/n]:n
    [=   ] Service Started  [11s] Elastic Agent has been successfully installed.
    

    The looks a bit odd. I think we're missing a newline?

@fearful-symmetry
Copy link
Contributor Author

@ycombinator added the newline. However, printing each message to a newline isn't quite something we can trivially do.

@ycombinator
Copy link
Contributor

Right after sudo ./elastic-agent install is called, there's a spinner but no text is shown next to it. I managed to capture a screenshot of the moment:

Screenshot 2023-10-19 at 09 14 19

Seems like there should be some text there about the work being done?

I'm not seeing the same behavior during uninstall, though, which is good.

@fearful-symmetry
Copy link
Contributor Author

@ycombinator wow, that happens too fast on my machine to even notice. Should be fixed now.

@ycombinator
Copy link
Contributor

Thanks @fearful-symmetry, I see the initial message during sudo elastic-agent install now.

One nit:

During uninstallation (sudo elastic-agent uninstall), when uninstallation succeeds, the last progress message that's printed is "Done".

$ sudo elastic-agent uninstall -f
[ ===] Done  [1s]
Elastic Agent has been uninstalled.

However, during installation (sudo ./elastic-agent install), when installation succeeds, the last progress message that's printed is the last actual installation step.

$ sudo ./elastic-agent install -n
Installing in non-interactive mode.
[==  ] Service Started  [11s]
Elastic Agent has been successfully installed.

Could we make these behaviors consistent? I'm not sure which direction makes more sense but I'm leaning slightly towards the way uninstallation behaves.

Copy link
Contributor

@ycombinator ycombinator left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for fixing this, Alex — much needed!

@mergify
Copy link
Contributor

mergify bot commented Oct 23, 2023

This pull request is now in conflicts. Could you fix it? 🙏
To fixup this pull request, you can check out it locally. See documentation: https://help.github.com/articles/checking-out-pull-requests-locally/

git fetch upstream
git checkout -b race-cond-check-progress upstream/race-cond-check-progress
git merge upstream/main
git push upstream race-cond-check-progress

@@ -51,7 +51,7 @@ would like the Agent to operate.
func installCmd(streams *cli.IOStreams, cmd *cobra.Command) error {
err := validateEnrollFlags(cmd)
if err != nil {
return err
return fmt.Errorf("could not validate flags: %w", err)
Copy link
Member

Choose a reason for hiding this comment

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

❤️

Copy link
Member

@pchila pchila left a comment

Choose a reason for hiding this comment

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

LGTM

@elastic-sonarqube
Copy link

SonarQube Quality Gate

Quality Gate failed

Failed condition 9.5% 9.5% Coverage on New Code (is less than 40%)

See analysis details on SonarQube

@cmacknz
Copy link
Member

cmacknz commented Oct 25, 2023

I am going to force merge this. Looking at the code that is missing coverage, some of it is covered by integration tests and I don't see value in simulating the 10+ error conditions we can hit just to verify a log line gets printed as expected.

@cmacknz cmacknz merged commit 13e1fe4 into elastic:main Oct 25, 2023
7 of 8 checks passed
@orestisfl
Copy link

Just noticed this on a snapshot and it looks amazing 🤩 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-skip Team:Elastic-Agent Label for the Agent team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Flaky Test: TestProgress/nested_step_delayed_success
7 participants