Skip to content

Commit

Permalink
add status http interface
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Leung <[email protected]>
  • Loading branch information
rleungx committed Mar 11, 2024
1 parent 1d77b25 commit ec751db
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
15 changes: 15 additions & 0 deletions client/http/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ type Client interface {
GetClusterVersion(context.Context) (string, error)
GetCluster(context.Context) (*metapb.Cluster, error)
GetClusterStatus(context.Context) (*ClusterState, error)
GetStatus(context.Context) (*State, error)
GetReplicateConfig(context.Context) (map[string]any, error)
/* Scheduler-related interfaces */
GetSchedulers(context.Context) ([]string, error)
Expand Down Expand Up @@ -459,6 +460,20 @@ func (c *client) GetClusterStatus(ctx context.Context) (*ClusterState, error) {
return clusterStatus, nil
}

// GetStatus gets the status of PD.
func (c *client) GetStatus(ctx context.Context) (*State, error) {
var status *State
err := c.request(ctx, newRequestInfo().
WithName(getStatusName).
WithURI(Status).
WithMethod(http.MethodGet).
WithResp(&status))
if err != nil {
return nil, err

Check warning on line 472 in client/http/interface.go

View check run for this annotation

Codecov / codecov/patch

client/http/interface.go#L472

Added line #L472 was not covered by tests
}
return status, nil
}

// GetReplicateConfig gets the replication configurations.
func (c *client) GetReplicateConfig(ctx context.Context) (map[string]any, error) {
var config map[string]any
Expand Down
1 change: 1 addition & 0 deletions client/http/request_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const (
getClusterVersionName = "GetClusterVersion"
getClusterName = "GetCluster"
getClusterStatusName = "GetClusterStatus"
getStatusName = "GetStatus"
getReplicateConfigName = "GetReplicateConfig"
getSchedulersName = "GetSchedulers"
createSchedulerName = "CreateScheduler"
Expand Down
9 changes: 9 additions & 0 deletions client/http/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ type ClusterState struct {
ReplicationStatus string `json:"replication_status"`
}

// State is the status of PD server.
// NOTE: This type is exported by HTTP API. Please pay more attention when modifying it.
type State struct {
BuildTS string `json:"build_ts"`
Version string `json:"version"`
GitHash string `json:"git_hash"`
StartTimestamp int64 `json:"start_timestamp"`
}

// KeyRange defines a range of keys in bytes.
type KeyRange struct {
startKey []byte
Expand Down
16 changes: 16 additions & 0 deletions tests/integrations/client/http_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,22 @@ func (suite *httpClientTestSuite) checkVersion(mode mode, client pd.Client) {
re.Equal(versioninfo.PDReleaseVersion, ver)
}

func (suite *httpClientTestSuite) TestStatus() {
suite.RunTestInTwoModes(suite.checkStatus)
}

func (suite *httpClientTestSuite) checkStatus(mode mode, client pd.Client) {
re := suite.Require()
env := suite.env[mode]

status, err := client.GetStatus(env.ctx)
re.NoError(err)
re.Equal(versioninfo.PDReleaseVersion, status.Version)
re.Equal(versioninfo.PDGitHash, status.GitHash)
re.Equal(versioninfo.PDBuildTS, status.BuildTS)
re.GreaterOrEqual(time.Now().Unix(), status.StartTimestamp)
}

func (suite *httpClientTestSuite) TestAdmin() {
suite.RunTestInTwoModes(suite.checkAdmin)
}
Expand Down

0 comments on commit ec751db

Please sign in to comment.