Skip to content

Commit

Permalink
fix replication bandwidth unit conversion (#4922)
Browse files Browse the repository at this point in the history
  • Loading branch information
kanagarajkm authored May 9, 2024
1 parent 62b1104 commit 45ae315
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 30 deletions.
40 changes: 20 additions & 20 deletions cmd/admin-bucket-remote-add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
want: 1000000,
},
{
name: "1GigaBit",
name: "1GigaByte",
args: args{
bandwidthStr: "1G",
},
want: 1000000000 / 8,
want: 1000000000,
},
{
name: "1GigaByte",
name: "1GibiByte",
args: args{
bandwidthStr: "1Gi",
},
want: 1024 * 1024 * 1024 / 8,
want: 1024 * 1024 * 1024,
},
{
name: "FractionalMegaBits",
name: "FractionalMegaBytes",
args: args{
bandwidthStr: "999.123456789123456789M",
},
want: 999123457 / 8,
want: 999123456,
},
{
name: "FractionalGigaBits",
name: "FractionalGigaBytes",
args: args{
bandwidthStr: "10.123456789123456789123456G",
},
want: 10123456789 / 8,
want: 10123456789,
},
{
name: "FractionalBigGigaBits",
name: "FractionalBigGigaBytes",
args: args{
bandwidthStr: "10000.123456789123456789123456G",
},
want: 10000123456789 / 8,
want: 10000123456789,
},
{
name: "FractionalMegaBytes",
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",
},
Expand All @@ -116,7 +116,7 @@ func TestGetBandwidthInBytes(t *testing.T) {
args: args{
bandwidthStr: "1024Ki",
},
want: 1024 * 1024 / 8,
want: 1024 * 1024,
},
}
t.Parallel()
Expand Down
4 changes: 2 additions & 2 deletions cmd/admin-replicate-info.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
2 changes: 1 addition & 1 deletion cmd/admin-replicate-update.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 1 addition & 2 deletions cmd/replicate-add.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -267,7 +267,6 @@ func getBandwidthInBytes(bandwidthStr string) (bandwidth uint64, err error) {
if err != nil {
return
}
bandwidth = bandwidth / 8
}
return
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/replicate-status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/replicate-update.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 45ae315

Please sign in to comment.