Skip to content

Commit

Permalink
Merge branch 'release-3.0' into cherry-pick-1740
Browse files Browse the repository at this point in the history
  • Loading branch information
rleungx authored Sep 30, 2019
2 parents 3d66356 + 1796883 commit 1ec15d5
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 5 deletions.
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ require (
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1 // indirect
github.com/coreos/go-semver v0.2.0
github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf
github.com/dustin/go-humanize v0.0.0-20180421182945-02af3965c54e
github.com/docker/go-units v0.4.0
github.com/dustin/go-humanize v0.0.0-20180421182945-02af3965c54e // indirect
github.com/eknkc/amber v0.0.0-20171010120322-cdade1c07385 // indirect
github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32
github.com/gogo/protobuf v1.0.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/docker/go-units v0.4.0 h1:3uh0PgVws3nIA0Q+MwDC8yjEPf9zjRfZZWXZYDct3Tw=
github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/dustin/go-humanize v0.0.0-20180421182945-02af3965c54e h1:Fw7ZmgiklsLh5EQWyHh1sumKSCG1+yjEctIpGKib87s=
github.com/dustin/go-humanize v0.0.0-20180421182945-02af3965c54e/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
Expand Down
8 changes: 4 additions & 4 deletions pkg/typeutil/size.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ package typeutil
import (
"strconv"

gh "github.com/dustin/go-humanize"
"github.com/docker/go-units"
"github.com/pkg/errors"
)

Expand All @@ -25,7 +25,7 @@ type ByteSize uint64

// MarshalJSON returns the size as a JSON string.
func (b ByteSize) MarshalJSON() ([]byte, error) {
return []byte(`"` + gh.IBytes(uint64(b)) + `"`), nil
return []byte(`"` + units.BytesSize(float64(b)) + `"`), nil
}

// UnmarshalJSON parses a JSON string into the bytesize.
Expand All @@ -34,7 +34,7 @@ func (b *ByteSize) UnmarshalJSON(text []byte) error {
if err != nil {
return errors.WithStack(err)
}
v, err := gh.ParseBytes(s)
v, err := units.RAMInBytes(s)
if err != nil {
return errors.WithStack(err)
}
Expand All @@ -44,7 +44,7 @@ func (b *ByteSize) UnmarshalJSON(text []byte) error {

// UnmarshalText parses a Toml string into the bytesize.
func (b *ByteSize) UnmarshalText(text []byte) error {
v, err := gh.ParseBytes(string(text))
v, err := units.RAMInBytes(string(text))
if err != nil {
return errors.WithStack(err)
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/typeutil/size_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,9 @@ func (s *testSizeSuite) TestJSON(c *C) {
var nb ByteSize
err = json.Unmarshal(o, &nb)
c.Assert(err, IsNil)

b = ByteSize(1756821276000)
o, err = json.Marshal(b)
c.Assert(err, IsNil)
c.Assert(string(o), Equals, `"1.598TiB"`)
}
19 changes: 19 additions & 0 deletions server/api/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package api

import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
Expand All @@ -22,6 +23,7 @@ import (
"strings"
"time"

"github.com/docker/go-units"
. "github.com/pingcap/check"
"github.com/pingcap/kvproto/pkg/metapb"
"github.com/pingcap/kvproto/pkg/pdpb"
Expand Down Expand Up @@ -134,9 +136,26 @@ func (s *testStoreSuite) TestStoresList(c *C) {

func (s *testStoreSuite) TestStoreGet(c *C) {
url := fmt.Sprintf("%s/store/1", s.urlPrefix)
s.svr.StoreHeartbeat(
context.Background(), &pdpb.StoreHeartbeatRequest{
Header: &pdpb.RequestHeader{ClusterId: s.svr.ClusterID()},
Stats: &pdpb.StoreStats{
StoreId: 1,
Capacity: 1798985089024,
Available: 1709868695552,
UsedSize: 85150956358,
},
},
)

info := new(StoreInfo)
err := readJSONWithURL(url, info)

c.Assert(err, IsNil)
capacity, _ := units.RAMInBytes("1.636TiB")
available, _ := units.RAMInBytes("1.555TiB")
c.Assert(int64(info.Status.Capacity), Equals, capacity)
c.Assert(int64(info.Status.Available), Equals, available)
checkStoresInfo(c, []*StoreInfo{info}, s.stores[:1])
}

Expand Down

0 comments on commit 1ec15d5

Please sign in to comment.