Skip to content

Commit

Permalink
Merge branch 'master' into fix-cannot-find-capture
Browse files Browse the repository at this point in the history
  • Loading branch information
nexustar authored Oct 25, 2022
2 parents 433accc + fb0be5e commit 76cc7db
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 26 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ require (
github.com/pingcap/errors v0.11.5-0.20201126102027-b0a155152ca3
github.com/pingcap/failpoint v0.0.0-20220801062533-2eaa32854a6c
github.com/pingcap/fn v1.0.0
github.com/pingcap/kvproto v0.0.0-20220525022339-6aaebf466305
github.com/pingcap/kvproto v0.0.0-20220913050750-f6d05706948a
github.com/pingcap/tidb-insight/collector v0.0.0-20220902034607-fb5ae0ddc8c1
github.com/pkg/errors v0.9.1
github.com/prometheus/client_model v0.2.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,8 @@ github.com/pingcap/failpoint v0.0.0-20220801062533-2eaa32854a6c h1:CgbKAHto5CQgW
github.com/pingcap/failpoint v0.0.0-20220801062533-2eaa32854a6c/go.mod h1:4qGtCB0QK0wBzKtFEGDhxXnSnbQApw1gc9siScUl8ew=
github.com/pingcap/fn v1.0.0 h1:CyA6AxcOZkQh52wIqYlAmaVmF6EvrcqFywP463pjA8g=
github.com/pingcap/fn v1.0.0/go.mod h1:u9WZ1ZiOD1RpNhcI42RucFh/lBuzTu6rw88a+oF2Z24=
github.com/pingcap/kvproto v0.0.0-20220525022339-6aaebf466305 h1:TZ0teMZoKHnZDlJxNkWrp5Sgv3w+ruNbrqtBYKsfaNw=
github.com/pingcap/kvproto v0.0.0-20220525022339-6aaebf466305/go.mod h1:OYtxs0786qojVTmkVeufx93xe+jUgm56GUYRIKnmaGI=
github.com/pingcap/kvproto v0.0.0-20220913050750-f6d05706948a h1:LCtkOPEzjWk86NclzxdZ42nNtbhuIN1p6cpd/FYUqkU=
github.com/pingcap/kvproto v0.0.0-20220913050750-f6d05706948a/go.mod h1:OYtxs0786qojVTmkVeufx93xe+jUgm56GUYRIKnmaGI=
github.com/pingcap/log v0.0.0-20191012051959-b742a5d432e9/go.mod h1:4rbK1p9ILyIfb6hU7OG2CiWSqMXnp3JMbiaVJ6mvoY8=
github.com/pingcap/log v0.0.0-20200511115504-543df19646ad/go.mod h1:4rbK1p9ILyIfb6hU7OG2CiWSqMXnp3JMbiaVJ6mvoY8=
github.com/pingcap/log v1.1.0 h1:ELiPxACz7vdo1qAvvaWJg1NrYFoY6gqAh/+Uo6aXdD8=
Expand Down
43 changes: 32 additions & 11 deletions pkg/cluster/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ type StoreStatus struct {
RegionWeight float64 `json:"region_weight"`
RegionScore float64 `json:"region_score"`
RegionSize int64 `json:"region_size"`
SlowScore uint64 `json:"slow_score,omitempty"` // added omitempty
SendingSnapCount uint32 `json:"sending_snap_count,omitempty"`
ReceivingSnapCount uint32 `json:"receiving_snap_count,omitempty"`
ApplyingSnapCount uint32 `json:"applying_snap_count,omitempty"`
Expand Down Expand Up @@ -98,23 +99,43 @@ type ReplicationStatus struct {
StateID uint64 `json:"state_id"`
}

// MetaPeer is api compatible with *metapb.Peer.
type MetaPeer struct {
*metapb.Peer
// RoleName is `Role.String()`.
// Since Role is serialized as int by json by default,
// introducing it will make the output of pd-ctl easier to identify Role.
RoleName string `json:"role_name"`
// IsLearner is `Role == "Learner"`.
// Since IsLearner was changed to Role in kvproto in 5.0, this field was introduced to ensure api compatibility.
IsLearner bool `json:"is_learner,omitempty"`
}

// PDPeerStats is api compatible with *pdpb.PeerStats.
// NOTE: This type is exported by HTTP API. Please pay more attention when modifying it.
type PDPeerStats struct {
*pdpb.PeerStats
Peer MetaPeer `json:"peer"`
}

// RegionInfo records detail region info for api usage.
type RegionInfo struct {
ID uint64 `json:"id"`
StartKey string `json:"start_key"`
EndKey string `json:"end_key"`
RegionEpoch *metapb.RegionEpoch `json:"epoch,omitempty"`
Peers []*metapb.Peer `json:"peers,omitempty"`

Leader *metapb.Peer `json:"leader,omitempty"`
DownPeers []*pdpb.PeerStats `json:"down_peers,omitempty"`
PendingPeers []*metapb.Peer `json:"pending_peers,omitempty"`
WrittenBytes uint64 `json:"written_bytes"`
ReadBytes uint64 `json:"read_bytes"`
WrittenKeys uint64 `json:"written_keys"`
ReadKeys uint64 `json:"read_keys"`
ApproximateSize int64 `json:"approximate_size"`
ApproximateKeys int64 `json:"approximate_keys"`
Peers []MetaPeer `json:"peers,omitempty"`

Leader MetaPeer `json:"leader,omitempty"`
DownPeers []PDPeerStats `json:"down_peers,omitempty"`
PendingPeers []MetaPeer `json:"pending_peers,omitempty"`
WrittenBytes uint64 `json:"written_bytes"`
ReadBytes uint64 `json:"read_bytes"`
WrittenKeys uint64 `json:"written_keys"`
ReadKeys uint64 `json:"read_keys"`
ApproximateSize int64 `json:"approximate_size"`
ApproximateKeys int64 `json:"approximate_keys"`
Buckets []string `json:"buckets,omitempty"`

ReplicationStatus *ReplicationStatus `json:"replication_status,omitempty"`
}
Expand Down
10 changes: 10 additions & 0 deletions pkg/cluster/api/typeutil/size.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ import (
// ByteSize is a retype uint64 for TOML and JSON.
type ByteSize uint64

// ParseMBFromText parses MB from text.
func ParseMBFromText(text string, value uint64) uint64 {
b := ByteSize(0)
err := b.UnmarshalText([]byte(text))
if err != nil {
return value
}
return uint64(b / units.MiB)
}

// MarshalJSON returns the size as a JSON string.
func (b ByteSize) MarshalJSON() ([]byte, error) {
return []byte(`"` + units.BytesSize(float64(b)) + `"`), nil
Expand Down
45 changes: 34 additions & 11 deletions pkg/cluster/api/typeutil/size_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,49 @@ package typeutil

import (
"encoding/json"
"testing"

. "github.com/pingcap/check"
"github.com/docker/go-units"
"github.com/stretchr/testify/require"
)

var _ = Suite(&testSizeSuite{})

type testSizeSuite struct {
}

func (s *testSizeSuite) TestJSON(c *C) {
func TestSizeJSON(t *testing.T) {
t.Parallel()
re := require.New(t)
b := ByteSize(265421587)
o, err := json.Marshal(b)
c.Assert(err, IsNil)
re.NoError(err)

var nb ByteSize
err = json.Unmarshal(o, &nb)
c.Assert(err, IsNil)
re.NoError(err)

b = ByteSize(1756821276000)
o, err = json.Marshal(b)
c.Assert(err, IsNil)
c.Assert(string(o), Equals, `"1.598TiB"`)
re.NoError(err)
re.Equal(`"1.598TiB"`, string(o))
}

func TestParseMbFromText(t *testing.T) {
t.Parallel()
re := require.New(t)
testCases := []struct {
body []string
size uint64
}{{
body: []string{"10Mib", "10MiB", "10M", "10MB"},
size: uint64(10),
}, {
body: []string{"10GiB", "10Gib", "10G", "10GB"},
size: uint64(10 * units.GiB / units.MiB),
}, {
body: []string{"10yiB", "10aib"},
size: uint64(1),
}}

for _, testCase := range testCases {
for _, b := range testCase.body {
re.Equal(int(testCase.size), int(ParseMBFromText(b, 1)))
}
}
}
2 changes: 1 addition & 1 deletion pkg/cluster/manager/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ func (m *Manager) Display(dopt DisplayOption, opt operator.Options) error {
if m.logger.GetDisplayMode() == logprinter.DisplayModeJSON {
grafanaURLs := getGrafanaURL(clusterInstInfos)
if len(grafanaURLs) != 0 {
j.ClusterMetaInfo.GrafanaURLS = grafanaURLs
j.ClusterMetaInfo.GrafanaURLS = grafanaURLs
}
} else {
urls, exist := getGrafanaURLStr(clusterInstInfos)
Expand Down

0 comments on commit 76cc7db

Please sign in to comment.