Skip to content

Commit

Permalink
Merge pull request #2822 from openziti/db-du-options
Browse files Browse the repository at this point in the history
Add --human-readable and --max-depth options to ziti ops db du Fixes #2821
  • Loading branch information
plorenz authored Feb 25, 2025
2 parents 548fa51 + 73b74df commit bfa5ff2
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 11 deletions.
1 change: 0 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ jobs:
run: |
$(go env GOPATH)/bin/ziti-ci configure-git
$(go env GOPATH)/bin/ziti-ci generate-build-info common/version/info_generated.go version
go test ./...
pushd zititest && go mod tidy && go install ./... && popd
go install -tags=all,tests ./...
Expand Down
20 changes: 20 additions & 0 deletions common/outputz/units.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package outputz

import "fmt"

var units = []string{"B", "K", "M", "G", "T", "P"}

func FormatBytes(val uint64) string {
var i int
var target uint64
for i = range units {
target = 1 << uint(10*(i+1))
if val < target {
break
}
}
if i > 0 {
return fmt.Sprintf("%0.2f%s", float64(val)/(float64(target)/1024), units[i])
}
return fmt.Sprintf("%dB", val)
}
8 changes: 4 additions & 4 deletions router/xlink_transport/xlink_split.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,12 @@ func (self *splitImpl) Close() error {
self.droppedMsgMeter.Dispose()
}
var err, err2 error
if self.payloadCh != nil {
err = self.payloadCh.Close()
if ch := self.payloadCh; ch != nil {
err = ch.Close()
}

if self.ackCh != nil {
err2 = self.ackCh.Close()
if ch := self.ackCh; ch != nil {
err2 = ch.Close()
}
if err == nil {
return err2
Expand Down
22 changes: 17 additions & 5 deletions ziti/cmd/database/du.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ package database
import (
"fmt"
"github.com/openziti/storage/boltz"
"github.com/openziti/ziti/common/outputz"
"github.com/spf13/cobra"
"go.etcd.io/bbolt"
)

type DiskUsageAction struct {
humanReadable bool
outputDepth uint32
}

func NewDiskUsageAction() *cobra.Command {
Expand All @@ -36,11 +39,14 @@ func NewDiskUsageAction() *cobra.Command {
RunE: action.Run,
}

cmd.Flags().BoolVarP(&action.humanReadable, "human-readable", "H", false, "human readable sizes")
cmd.Flags().Uint32VarP(&action.outputDepth, "max-depth", "d", 0, "how many levels deep to output")

return cmd
}

// Run implements this command
func (o *DiskUsageAction) Run(cmd *cobra.Command, args []string) error {
func (self *DiskUsageAction) Run(cmd *cobra.Command, args []string) error {
srcOptions := *bbolt.DefaultOptions
srcOptions.ReadOnly = true

Expand Down Expand Up @@ -69,7 +75,7 @@ func (o *DiskUsageAction) Run(cmd *cobra.Command, args []string) error {
}

root.calcSize()
root.dump()
root.dump(self.humanReadable, self.outputDepth, 1)

return nil
}
Expand All @@ -87,12 +93,18 @@ func (self *sizeNode) calcSize() {
}
}

func (self *sizeNode) dump() {
func (self *sizeNode) dump(humanReadable bool, maxDepth uint32, currentDepth uint32) {
for _, child := range self.children {
child.dump()
child.dump(humanReadable, maxDepth, currentDepth+1)
}

fmt.Printf("%v: %v\n", self.path, self.size)
if maxDepth == 0 || currentDepth <= maxDepth {
if humanReadable {
fmt.Printf("%v: %v\n", self.path, outputz.FormatBytes(self.size))
} else {
fmt.Printf("%v: %v\n", self.path, self.size)
}
}
}

type sizeVisitor struct {
Expand Down
2 changes: 1 addition & 1 deletion zititest/zitilab/actions/edge/ctrl_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (init *raftInit) Execute(run model.Run) error {
return errors.Errorf("component %s is not a controller", c.Id)
}

tmpl := "set -o pipefail; %s agent cluster init %s %s default.admin 2>&1 | tee logs/controller.edge.init.log"
tmpl := "set -o pipefail; %s agent cluster init --timeout 20s %s %s default.admin 2>&1 | tee logs/controller.edge.init.log"
if err := host.Exec(c.GetHost(), fmt.Sprintf(tmpl, ctrlType.GetBinaryPath(c), username, password)).Execute(run); err != nil {
return err
}
Expand Down

0 comments on commit bfa5ff2

Please sign in to comment.