Skip to content

Commit

Permalink
minor fix up and format work.
Browse files Browse the repository at this point in the history
  • Loading branch information
jrasell committed Jun 5, 2024
1 parent f4fe471 commit d879055
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
23 changes: 12 additions & 11 deletions command/operator_snapshot_inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"time"

humanize "github.com/dustin/go-humanize"
"github.com/hashicorp/go-msgpack/codec"
"github.com/hashicorp/go-msgpack/v2/codec"
"github.com/hashicorp/nomad/helper/snapshot"
"github.com/hashicorp/nomad/nomad"
"github.com/hashicorp/raft"
Expand All @@ -38,8 +38,9 @@ type SnapshotInspectFormat struct {
// SnapshotInfo is used for passing snapshot stat
// information between functions
type SnapshotInfo struct {
Stats map[nomad.SnapshotType]typeStats
TotalSize int
Stats map[nomad.SnapshotType]typeStats
TotalSize int
TotalCount int
}

// countingReader helps keep track of the bytes we have read
Expand Down Expand Up @@ -141,7 +142,7 @@ func (c *OperatorSnapshotInspectCommand) Run(args []string) int {
}

// print human-readable output
c.Ui.Output(formatListWithSpaces([]string{
c.Ui.Output(formatKV([]string{
fmt.Sprintf("Created|%s", extractTimeFromName(meta.ID)),
fmt.Sprintf("ID|%s", meta.ID),
fmt.Sprintf("Size|%s", humanize.IBytes(uint64(meta.Size))),
Expand All @@ -151,18 +152,17 @@ func (c *OperatorSnapshotInspectCommand) Run(args []string) int {
}))
c.Ui.Output("")

output := []string{
"Type|Count|Size",
"----|-----|----",
}
output := []string{"Type|Count|Size"}

for _, stat := range stats {
output = append(output, fmt.Sprintf("%s|%d|%s", stat.Name, stat.Count, humanize.IBytes(uint64(stat.Sum))))
}
output = append(output, "----|-----|----")
output = append(output, fmt.Sprintf("Total|-|%s", humanize.IBytes(uint64(info.TotalSize))))
output = append(output,
" | | ",
fmt.Sprintf("Total|%v|%s", info.TotalCount, humanize.IBytes(uint64(info.TotalSize))),
)

c.Ui.Output(formatList(output))
c.Ui.Output(formatListWithSpaces(output))
return 0
}

Expand Down Expand Up @@ -205,6 +205,7 @@ func inspect(file io.Reader) (*raft.SnapshotMeta, *SnapshotInfo, error) {
stat.Sum += size
stat.Count++
info.TotalSize = cr.read
info.TotalCount++
info.Stats[snapType] = stat

return nil
Expand Down
1 change: 1 addition & 0 deletions nomad/fsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ var snapshotTypeStrings = map[SnapshotType]string{
ACLAuthMethodSnapshot: "ACLAuthMethod",
ACLBindingRuleSnapshot: "ACLBindingRule",
NodePoolSnapshot: "NodePool",
JobSubmissionSnapshot: "JobSubmission",
NamespaceSnapshot: "Namespace",
}

Expand Down

0 comments on commit d879055

Please sign in to comment.