Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client: add status http interface #7903

Merged
merged 3 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@
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 @@
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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it would be better to associate to the original type place?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

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