Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ require (
github.com/tidwall/gjson v1.19.0
github.com/tkuchiki/go-timezone v0.2.3
github.com/travelaudience/go-promhttp v1.0.1
github.com/vbauerster/mpb/v4 v4.12.2
github.com/vbauerster/mpb/v8 v8.12.0
go.uber.org/atomic v1.11.0
go.uber.org/goleak v1.3.0
go.uber.org/mock v0.6.0
Expand Down Expand Up @@ -234,7 +234,7 @@ require (
github.com/cenkalti/backoff/v5 v5.0.3 // indirect
github.com/chai2010/gettext-go v1.0.2 // indirect
github.com/clipperhouse/displaywidth v0.10.0 // indirect
github.com/clipperhouse/uax29/v2 v2.6.0 // indirect
github.com/clipperhouse/uax29/v2 v2.7.0 // indirect
github.com/cloudflare/circl v1.6.3 // indirect
github.com/cncf/xds/go v0.0.0-20260202195803-dba9d589def2 // indirect
github.com/cockroachdb/crlib v0.0.0-20250617202621-0794c595bbe6 // indirect
Expand Down Expand Up @@ -355,7 +355,7 @@ require (
github.com/mattermost/xml-roundtrip-validator v0.1.0 // indirect
github.com/mattn/go-colorable v0.1.14 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.19 // indirect
github.com/mattn/go-runewidth v0.0.20 // indirect
github.com/mdlayher/socket v0.6.0 // indirect
github.com/mholt/archiver/v3 v3.5.1 // indirect
github.com/microcosm-cc/bluemonday v1.0.23 // indirect
Expand Down
15 changes: 6 additions & 9 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions roxctl/central/db/restore/statusline.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"strings"

"github.com/stackrox/rox/pkg/sync"
"github.com/vbauerster/mpb/v4/decor"
"github.com/vbauerster/mpb/v8/decor"
)

// statusLine is an mpb.Filler implementation that can be used to display a status, along with an optional spinner.
Expand Down Expand Up @@ -71,6 +71,7 @@ func (l *statusLine) currentLine(width int) string {
return line
}

func (l *statusLine) Fill(w io.Writer, width int, _ *decor.Statistics) {
_, _ = fmt.Fprint(w, l.currentLine(width))
func (l *statusLine) Fill(w io.Writer, st decor.Statistics) error {
_, err := fmt.Fprint(w, l.currentLine(st.AvailableWidth))
return err
}
12 changes: 8 additions & 4 deletions roxctl/central/db/restore/v2_restorer.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import (
"github.com/stackrox/rox/pkg/v2backuprestore"
"github.com/stackrox/rox/roxctl/common"
"github.com/stackrox/rox/roxctl/common/environment"
"github.com/vbauerster/mpb/v4"
"github.com/vbauerster/mpb/v4/decor"
"github.com/vbauerster/mpb/v8"
"github.com/vbauerster/mpb/v8/decor"
"golang.org/x/term"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
Expand Down Expand Up @@ -180,8 +180,12 @@ func (r *v2Restorer) Run(ctx context.Context, file *os.File) (*http.Response, er
),
)

progressBarContainer.Add(0, &r.errorLine)
progressBarContainer.Add(0, &r.statusLine)
if _, err := progressBarContainer.Add(0, &r.errorLine); err != nil {
return nil, errors.Wrap(err, "adding error line to progress bar")
}
if _, err := progressBarContainer.Add(0, &r.statusLine); err != nil {
return nil, errors.Wrap(err, "adding status line to progress bar")
}

// In case we resumed, initialized the transfer progress bar with the refill.
pos, err := r.dataReader.Seek(0, io.SeekCurrent)
Expand Down
54 changes: 31 additions & 23 deletions roxctl/central/db/transfer/progress_bar.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"time"

"github.com/stackrox/rox/pkg/concurrency"
"github.com/vbauerster/mpb/v4"
"github.com/vbauerster/mpb/v4/decor"
"github.com/vbauerster/mpb/v8"
"github.com/vbauerster/mpb/v8/decor"
"golang.org/x/term"
)

Expand All @@ -33,19 +33,19 @@ func newSingleCounterDecorator(fmt string) decor.Decorator {
}
}

func (d *singleCounterDecorator) Decor(st *decor.Statistics) string {
func (d *singleCounterDecorator) Decor(st decor.Statistics) (string, int) {
str := fmt.Sprintf(d.fmt, decor.SizeB1024(st.Current))
return d.FormatMsg(str)
return d.WC.Format(str)
}

type unknownTotalSizeFiller struct {
tick int
}

func (f *unknownTotalSizeFiller) Fill(w io.Writer, width int, _ *decor.Statistics) {
func (f *unknownTotalSizeFiller) Fill(w io.Writer, st decor.Statistics) error {
f.tick++

effectiveWidth := width - 2
effectiveWidth := st.AvailableWidth - 2

arrowWidth := 5
arrowSpace := 10
Expand All @@ -61,7 +61,8 @@ func (f *unknownTotalSizeFiller) Fill(w io.Writer, width int, _ *decor.Statistic
}
}
_, _ = bar.WriteRune(']')
_, _ = w.Write([]byte(bar.String()))
_, err := w.Write([]byte(bar.String()))
return err
}

func createProgressBars(_ context.Context, name string, totalSize int64) (*mpb.Bar, func()) {
Expand All @@ -75,9 +76,9 @@ func createProgressBars(_ context.Context, name string, totalSize int64) (*mpb.B
shutdownSig := concurrency.NewSignal()

if !term.IsTerminal(int(outFile.Fd())) {
refreshC := make(chan time.Time, 1)
refreshC := make(chan interface{}, 1)
refreshC <- time.Now() // first tick right away
shutdownNotifyC := make(chan struct{})
shutdownNotifyC := make(chan interface{})
shutdownC := shutdownSig.Done()

go func() {
Expand All @@ -104,28 +105,35 @@ func createProgressBars(_ context.Context, name string, totalSize int64) (*mpb.B

progressBars := mpb.New(opts...)

var filler mpb.Filler
var progressBar *mpb.Bar
var counterDecorator decor.Decorator
if totalSize == 0 {
filler = &unknownTotalSizeFiller{}
counterDecorator = newSingleCounterDecorator("% 10.1f")
} else {
counterDecorator = decor.CountersKibiByte("% 10.1f / % 10.1f")
}

appendedDecorators := []decor.Decorator{
decor.AverageSpeed(decor.UnitKiB, "% 11.1f"),
decor.AverageSpeed(decor.SizeB1024(0), "% 11.1f"),
decor.Name(fmt.Sprintf(" %s ", name)),
}
if totalSize != 0 {

if totalSize == 0 {
filler := &unknownTotalSizeFiller{}
counterDecorator = newSingleCounterDecorator("% 10.1f")
var err error
progressBar, err = progressBars.Add(totalSize, filler,
mpb.PrependDecorators(counterDecorator),
mpb.AppendDecorators(appendedDecorators...),
)
if err != nil {
// Should not happen unless progressBars.Wait() was already called
panic(err)
}
} else {
counterDecorator = decor.CountersKibiByte("% 10.1f / % 10.1f")
appendedDecorators = append(appendedDecorators, decor.AverageETA(decor.ET_STYLE_MMSS))
progressBar = progressBars.AddBar(totalSize,
mpb.PrependDecorators(counterDecorator),
mpb.AppendDecorators(appendedDecorators...),
)
}

progressBar := progressBars.Add(totalSize, filler,
mpb.PrependDecorators(counterDecorator),
mpb.AppendDecorators(appendedDecorators...),
)

shutdownFunc := func() {
if totalSize == 0 && !progressBar.Completed() {
progressBar.Abort(false)
Expand Down
2 changes: 1 addition & 1 deletion roxctl/central/db/transfer/transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/stackrox/rox/pkg/errox"
"github.com/stackrox/rox/pkg/timestamp"
"github.com/stackrox/rox/roxctl/common"
"github.com/vbauerster/mpb/v4"
"github.com/vbauerster/mpb/v8"
)

type progressWatchReader struct {
Expand Down
Loading