From b3c33fdcecb900cef8f31b059d025fb3b8c48671 Mon Sep 17 00:00:00 2001 From: Hridoy Roy Date: Mon, 2 Aug 2021 10:06:04 -0700 Subject: [PATCH] Fix Diagnose Formatting In Disk Usage Checks (#12229) * save * fix diagnose formatting errors * fix diagnose formatting errors * change powers * change powers * use humanize instead of doing the conversion to mb manually * cl --- changelog/12229.txt | 3 +++ go.mod | 1 + vault/diagnose/os_common.go | 11 ++++++----- 3 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 changelog/12229.txt diff --git a/changelog/12229.txt b/changelog/12229.txt new file mode 100644 index 0000000000000..6503ba5e97c9f --- /dev/null +++ b/changelog/12229.txt @@ -0,0 +1,3 @@ +```release-note:bug +core: fix byte printing for diagnose disk checks +``` diff --git a/go.mod b/go.mod index d53d2c7278764..abc6d597fd431 100644 --- a/go.mod +++ b/go.mod @@ -41,6 +41,7 @@ require ( github.com/docker/go-connections v0.4.0 github.com/dsnet/compress v0.0.1 // indirect github.com/duosecurity/duo_api_golang v0.0.0-20190308151101-6c680f768e74 + github.com/dustin/go-humanize v1.0.0 github.com/elazarl/go-bindata-assetfs v1.0.1-0.20200509193318-234c15e7648f github.com/fatih/color v1.11.0 github.com/fatih/structs v1.1.0 diff --git a/vault/diagnose/os_common.go b/vault/diagnose/os_common.go index 6d4658c006629..fac2789f92be7 100644 --- a/vault/diagnose/os_common.go +++ b/vault/diagnose/os_common.go @@ -7,6 +7,7 @@ import ( "fmt" "strings" + "github.com/dustin/go-humanize" "github.com/shirou/gopsutil/disk" ) @@ -31,11 +32,11 @@ partLoop: Warn(ctx, fmt.Sprintf("Could not obtain partition usage for %s: %v.", partition.Mountpoint, err)) } else { if usage.UsedPercent > 95 { - SpotWarn(ctx, testName, fmt.Sprintf(partition.Mountpoint+" is %d percent full.", usage.UsedPercent), - Advice("It is recommended to have more than five percent of the partition free.")) - } else if usage.Free < 2<<30 { - SpotWarn(ctx, testName, partition.Mountpoint+" has %d bytes full.", - Advice("It is recommended to have at least 1 GB of space free per partition.")) + SpotWarn(ctx, testName, fmt.Sprintf(partition.Mountpoint+" is %.2f percent full.", usage.UsedPercent)) + Advise(ctx, "It is recommended to have more than five percent of the partition free.") + } else if usage.Free < 1<<30 { + SpotWarn(ctx, testName, fmt.Sprintf(partition.Mountpoint+" has %s free.", humanize.Bytes(usage.Free))) + Advise(ctx, "It is recommended to have at least 1 GB of space free per partition.") } else { SpotOk(ctx, testName, partition.Mountpoint+" usage ok.") }