-
Notifications
You must be signed in to change notification settings - Fork 143
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
Show installation progress #3338
Merged
Merged
Changes from 10 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
4423d96
Show installation progress
ycombinator c819e88
Adding CHANGELOG fragment
ycombinator 634febf
Adding unit tests
ycombinator b036b02
Add progress dots
ycombinator 3369dff
Add randomization to tick intervals
ycombinator 7b7b1dc
Increase tick interval
ycombinator a25ffa4
Fix randomization
ycombinator 0adf4f2
Adjust randomization bounds
ycombinator be1206b
Regenerate NOTICE.txt
ycombinator cbfe0e3
Increasing margins with times to avoid flakiness
ycombinator 4afae51
Doubling time intervals again
ycombinator 66475d4
Make test less reliant on timing
ycombinator File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6193,6 +6193,43 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
|
||
-------------------------------------------------------------------------------- | ||
Dependency : golang.org/x/exp | ||
Version: v0.0.0-20220722155223-a9213eeb770e | ||
Licence type (autodetected): BSD-3-Clause | ||
-------------------------------------------------------------------------------- | ||
|
||
Contents of probable licence file $GOMODCACHE/golang.org/x/[email protected]/LICENSE: | ||
|
||
Copyright (c) 2009 The Go Authors. All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are | ||
met: | ||
|
||
* Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above | ||
copyright notice, this list of conditions and the following disclaimer | ||
in the documentation and/or other materials provided with the | ||
distribution. | ||
* Neither the name of Google Inc. nor the names of its | ||
contributors may be used to endorse or promote products derived from | ||
this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
|
||
-------------------------------------------------------------------------------- | ||
Dependency : golang.org/x/lint | ||
Version: v0.0.0-20210508222113-6edffad5e616 | ||
|
@@ -17161,43 +17198,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
THE SOFTWARE. | ||
|
||
|
||
-------------------------------------------------------------------------------- | ||
Dependency : golang.org/x/exp | ||
Version: v0.0.0-20220722155223-a9213eeb770e | ||
Licence type (autodetected): BSD-3-Clause | ||
-------------------------------------------------------------------------------- | ||
|
||
Contents of probable licence file $GOMODCACHE/golang.org/x/[email protected]/LICENSE: | ||
|
||
Copyright (c) 2009 The Go Authors. All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are | ||
met: | ||
|
||
* Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above | ||
copyright notice, this list of conditions and the following disclaimer | ||
in the documentation and/or other materials provided with the | ||
distribution. | ||
* Neither the name of Google Inc. nor the names of its | ||
contributors may be used to endorse or promote products derived from | ||
this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
|
||
-------------------------------------------------------------------------------- | ||
Dependency : golang.org/x/mod | ||
Version: v0.9.0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Kind can be one of: | ||
# - breaking-change: a change to previously-documented behavior | ||
# - deprecation: functionality that is being removed in a later release | ||
# - bug-fix: fixes a problem in a previous version | ||
# - enhancement: extends functionality but does not break or fix existing behavior | ||
# - feature: new functionality | ||
# - known-issue: problems that we are aware of in a given version | ||
# - security: impacts on the security of a product or a user’s deployment. | ||
# - upgrade: important information for someone upgrading from a prior version | ||
# - other: does not fit into any of the other categories | ||
kind: feature | ||
|
||
# Change summary; a 80ish characters long description of the change. | ||
summary: Print out Elastic Agent installation steps to show progress | ||
|
||
# Long description; in case the summary is not enough to describe the change | ||
# this field accommodate a description without length limits. | ||
# NOTE: This field will be rendered only for breaking-change and known-issue kinds at the moment. | ||
#description: | ||
|
||
# Affected component; usually one of "elastic-agent", "fleet-server", "filebeat", "metricbeat", "auditbeat", "all", etc. | ||
component: elastic-agent | ||
|
||
# PR URL; optional; the PR number that added the changeset. | ||
# If not present is automatically filled by the tooling finding the PR where this changelog fragment has been added. | ||
# NOTE: the tooling supports backports, so it's able to fill the original PR number instead of the backport PR number. | ||
# Please provide it if you are adding a fragment for a different PR. | ||
pr: https://github.com/elastic/elastic-agent/pull/3338 | ||
|
||
# Issue URL; optional; the GitHub issue related to this changeset (either closes or is part of). | ||
# If not present is automatically filled by the tooling with the issue linked to the PR number. | ||
#issue: https://github.com/owner/repo/1234 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
package install | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"math" | ||
"strings" | ||
"sync" | ||
"time" | ||
|
||
"golang.org/x/exp/rand" | ||
) | ||
|
||
type ProgressTracker struct { | ||
writer io.Writer | ||
|
||
tickInterval time.Duration | ||
randomizeTickInterval bool | ||
|
||
stepInProgress bool | ||
mu sync.RWMutex | ||
stop chan struct{} | ||
} | ||
|
||
func NewProgressTracker(writer io.Writer) *ProgressTracker { | ||
return &ProgressTracker{ | ||
writer: writer, | ||
tickInterval: 200 * time.Millisecond, | ||
randomizeTickInterval: true, | ||
stop: make(chan struct{}), | ||
} | ||
} | ||
|
||
func (pt *ProgressTracker) SetTickInterval(d time.Duration) { | ||
pt.tickInterval = d | ||
} | ||
|
||
func (pt *ProgressTracker) DisableRandomizedTickIntervals() { | ||
pt.randomizeTickInterval = false | ||
} | ||
|
||
func (pt *ProgressTracker) Start() { | ||
timer := time.NewTimer(pt.calculateTickInterval()) | ||
go func() { | ||
defer timer.Stop() | ||
for { | ||
select { | ||
case <-pt.stop: | ||
return | ||
case <-timer.C: | ||
pt.mu.RLock() | ||
if pt.stepInProgress { | ||
_, _ = pt.writer.Write([]byte(".")) | ||
} | ||
pt.mu.RUnlock() | ||
|
||
timer = time.NewTimer(pt.calculateTickInterval()) | ||
} | ||
} | ||
}() | ||
} | ||
|
||
func (pt *ProgressTracker) StepStart(msg string) { | ||
pt.mu.Lock() | ||
defer pt.mu.Unlock() | ||
|
||
pt.stepInProgress = true | ||
fmt.Fprintf(pt.writer, strings.TrimSpace(msg)+"...") | ||
} | ||
|
||
func (pt *ProgressTracker) StepSucceeded() { | ||
pt.mu.Lock() | ||
defer pt.mu.Unlock() | ||
|
||
fmt.Fprintln(pt.writer, " DONE") | ||
pt.stepInProgress = false | ||
} | ||
|
||
func (pt *ProgressTracker) StepFailed() { | ||
pt.mu.Lock() | ||
defer pt.mu.Unlock() | ||
|
||
fmt.Fprintln(pt.writer, " FAILED") | ||
pt.stepInProgress = false | ||
} | ||
|
||
func (pt *ProgressTracker) Stop() { | ||
pt.stop <- struct{}{} | ||
} | ||
|
||
func (pt *ProgressTracker) calculateTickInterval() time.Duration { | ||
if !pt.randomizeTickInterval { | ||
return pt.tickInterval | ||
} | ||
|
||
// Randomize interval between 65% and 250% of configured interval | ||
// to make it look like the progress is non-linear. :) | ||
floor := int64(math.Floor(float64(pt.tickInterval.Milliseconds()) * 0.65)) | ||
ceiling := int64(math.Floor(float64(pt.tickInterval.Milliseconds()) * 2.5)) | ||
|
||
randomDuration := rand.Int63() % ceiling | ||
if randomDuration < floor { | ||
randomDuration = floor | ||
} | ||
|
||
return time.Duration(randomDuration) * time.Millisecond | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Haha, I don't know if this is really needed but okay! Why not.
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.
This whole deal is just to show some random progress to make things appear more realistic ;)