fix replication bandwidth unit conversion (#4922)
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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},
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user