From 45ae31533dafc6f9231370f6396b0cc2cfa39567 Mon Sep 17 00:00:00 2001 From: Kanagaraj M Date: Thu, 9 May 2024 15:34:18 +0530 Subject: [PATCH] fix replication bandwidth unit conversion (#4922) --- cmd/admin-bucket-remote-add_test.go | 76 ++++++++++++++--------------- cmd/admin-replicate-info.go | 4 +- cmd/admin-replicate-update.go | 2 +- cmd/replicate-add.go | 3 +- cmd/replicate-status.go | 8 +-- cmd/replicate-update.go | 2 +- 6 files changed, 47 insertions(+), 48 deletions(-) diff --git a/cmd/admin-bucket-remote-add_test.go b/cmd/admin-bucket-remote-add_test.go index 6425eff8..07be4d6f 100644 --- a/cmd/admin-bucket-remote-add_test.go +++ b/cmd/admin-bucket-remote-add_test.go @@ -25,10 +25,10 @@ func TestGetBandwidthInBytes(t *testing.T) { type args struct { bandwidthStr string } - f1 := 999.123457 * 1024 * 1024 / 8 - f2 := 10.123456790 * 1024 * 1024 * 1024 / 8 - f3 := 10000.123456790 * 1024 * 1024 * 1024 / 8 - f4 := (0.001*1024*1024*1024 + 1) / 8 // round up + f1 := 999.1234567 * 1024 * 1024 + f2 := 10.123456789 * 1024 * 1024 * 1024 + f3 := 10000.123456789 * 1024 * 1024 * 1024 + f4 := 0.001 * 1024 * 1024 * 1024 tests := []struct { name string args args @@ -39,66 +39,66 @@ func TestGetBandwidthInBytes(t *testing.T) { args: args{ bandwidthStr: "1Mi", }, - want: 1024 * 1024 / 8, + want: 1024 * 1024, }, { name: "1MegaBit", args: args{ bandwidthStr: "1M", }, - want: 1000000 / 8, - }, - { - name: "1GigaBit", - args: args{ - bandwidthStr: "1G", - }, - want: 1000000000 / 8, + want: 1000000, }, { name: "1GigaByte", + args: args{ + bandwidthStr: "1G", + }, + want: 1000000000, + }, + { + name: "1GibiByte", args: args{ bandwidthStr: "1Gi", }, - want: 1024 * 1024 * 1024 / 8, - }, - { - name: "FractionalMegaBits", - args: args{ - bandwidthStr: "999.123456789123456789M", - }, - want: 999123457 / 8, - }, - { - name: "FractionalGigaBits", - args: args{ - bandwidthStr: "10.123456789123456789123456G", - }, - want: 10123456789 / 8, - }, - { - name: "FractionalBigGigaBits", - args: args{ - bandwidthStr: "10000.123456789123456789123456G", - }, - want: 10000123456789 / 8, + want: 1024 * 1024 * 1024, }, { name: "FractionalMegaBytes", + args: args{ + bandwidthStr: "999.123456789123456789M", + }, + want: 999123456, + }, + { + name: "FractionalGigaBytes", + args: args{ + bandwidthStr: "10.123456789123456789123456G", + }, + want: 10123456789, + }, + { + name: "FractionalBigGigaBytes", + args: args{ + bandwidthStr: "10000.123456789123456789123456G", + }, + want: 10000123456789, + }, + { + name: "FractionalMebiBytes", args: args{ bandwidthStr: "999.123456789123456789Mi", }, want: uint64(f1), }, { - name: "FractionalGigaBytes", + name: "FractionalGibiBytes", args: args{ bandwidthStr: "10.123456789123456789123456Gi", }, want: uint64(f2), }, { - name: "FractionalBigGigaBytes", + name: "FractionalBigGibiBytes", args: args{ bandwidthStr: "10000.123456789123456789123456Gi", }, @@ -116,7 +116,7 @@ func TestGetBandwidthInBytes(t *testing.T) { args: args{ bandwidthStr: "1024Ki", }, - want: 1024 * 1024 / 8, + want: 1024 * 1024, }, } t.Parallel() diff --git a/cmd/admin-replicate-info.go b/cmd/admin-replicate-info.go index 5a606c00..f2f47774 100644 --- a/cmd/admin-replicate-info.go +++ b/cmd/admin-replicate-info.go @@ -97,8 +97,8 @@ func (i srInfo) String() string { } limit := "N/A" // N/A means cluster bandwidth is not configured if peer.DefaultBandwidth.Limit > 0 { - limit = humanize.Bytes(uint64(peer.DefaultBandwidth.Limit * 8)) - limit = fmt.Sprintf("%sb/s", limit[:len(limit)-1]) + limit = humanize.Bytes(uint64(peer.DefaultBandwidth.Limit)) + limit = fmt.Sprintf("%s/s", limit) } r := console.Colorize("TDetail", newPrettyTable(" | ", Field{"Deployment ID", 36}, diff --git a/cmd/admin-replicate-update.go b/cmd/admin-replicate-update.go index 7e9acebf..2b4c4c26 100644 --- a/cmd/admin-replicate-update.go +++ b/cmd/admin-replicate-update.go @@ -51,7 +51,7 @@ var adminReplicateUpdateFlags = []cli.Flag{ }, cli.StringFlag{ Name: "bucket-bandwidth", - Usage: "Set default bandwidth limit for bucket in bits per second (K,B,G,T for metric and Ki,Bi,Gi,Ti for IEC units)", + Usage: "Set default bandwidth limit for bucket in bytes per second (K,B,G,T for metric and Ki,Bi,Gi,Ti for IEC units)", }, cli.BoolFlag{ Name: "disable-ilm-expiry-replication", diff --git a/cmd/replicate-add.go b/cmd/replicate-add.go index 563676ba..d6cf2f86 100644 --- a/cmd/replicate-add.go +++ b/cmd/replicate-add.go @@ -83,7 +83,7 @@ var replicateAddFlags = []cli.Flag{ }, cli.StringFlag{ Name: "bandwidth", - Usage: "set bandwidth limit in bits per second (K,B,G,T for metric and Ki,Bi,Gi,Ti for IEC units)", + Usage: "set bandwidth limit in bytes per second (K,B,G,T for metric and Ki,Bi,Gi,Ti for IEC units)", }, cli.BoolFlag{ Name: "sync", @@ -267,7 +267,6 @@ func getBandwidthInBytes(bandwidthStr string) (bandwidth uint64, err error) { if err != nil { return } - bandwidth = bandwidth / 8 } return } diff --git a/cmd/replicate-status.go b/cmd/replicate-status.go index 5f3fe376..c9a90d40 100644 --- a/cmd/replicate-status.go +++ b/cmd/replicate-status.go @@ -244,12 +244,12 @@ func (s replicateStatusMessage) String() string { limit := "N/A" // N/A means cluster bandwidth is not configured current := "N/A" // N/A means cluster bandwidth is not configured if bwStat.CurrentBandwidthInBytesPerSecond > 0 { - current = humanize.Bytes(uint64(bwStat.CurrentBandwidthInBytesPerSecond * 8)) - current = fmt.Sprintf("%sb/s", current[:len(current)-1]) + current = humanize.Bytes(uint64(bwStat.CurrentBandwidthInBytesPerSecond)) + current = fmt.Sprintf("%s/s", current) } if bwStat.BandWidthLimitInBytesPerSecond > 0 { - limit = humanize.Bytes(uint64(bwStat.BandWidthLimitInBytesPerSecond * 8)) - limit = fmt.Sprintf("%sb/s", limit[:len(limit)-1]) + limit = humanize.Bytes(uint64(bwStat.BandWidthLimitInBytesPerSecond)) + limit = fmt.Sprintf("%s/s", limit) } addRowF(titleui("Configured Max Bandwidth (Bps): ")+"%s"+titleui(" Current Bandwidth (Bps): ")+"%s", valueui(limit), valueui(current)) } diff --git a/cmd/replicate-update.go b/cmd/replicate-update.go index 74c3cd46..a2a21fd4 100644 --- a/cmd/replicate-update.go +++ b/cmd/replicate-update.go @@ -76,7 +76,7 @@ var replicateUpdateFlags = []cli.Flag{ }, cli.StringFlag{ Name: "bandwidth", - Usage: "Set bandwidth limit in bits per second (K,B,G,T for metric and Ki,Bi,Gi,Ti for IEC units)", + Usage: "Set bandwidth limit in bytes per second (K,B,G,T for metric and Ki,Bi,Gi,Ti for IEC units)", }, cli.UintFlag{ Name: "healthcheck-seconds",