Skip to content

Commit

Permalink
http: add GetVersion API (#7648)
Browse files Browse the repository at this point in the history
ref #7300

Signed-off-by: lance6716 <lance6716@gmail.com>

Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
Co-authored-by: Hu# <ihusharp@gmail.com>
  • Loading branch information
3 people authored Jan 3, 2024
1 parent 3ef40bd commit 335bd1e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
14 changes: 14 additions & 0 deletions client/http/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ type Client interface {
AccelerateScheduleInBatch(context.Context, []*KeyRange) error
/* Other interfaces */
GetMinResolvedTSByStoresIDs(context.Context, []uint64) (uint64, map[uint64]uint64, error)
GetPDVersion(context.Context) (string, error)
/* Micro Service interfaces */
GetMicroServiceMembers(context.Context, string) ([]string, error)

Expand Down Expand Up @@ -723,3 +724,16 @@ func (c *client) GetMicroServiceMembers(ctx context.Context, service string) ([]
}
return members, nil
}

// GetPDVersion gets the release version of the PD binary.
func (c *client) GetPDVersion(ctx context.Context) (string, error) {
var ver struct {
Version string `json:"version"`
}
err := c.request(ctx, newRequestInfo().
WithName(getPDVersionName).
WithURI(Version).
WithMethod(http.MethodGet).
WithResp(&ver))
return ver.Version, err
}
1 change: 1 addition & 0 deletions client/http/request_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const (
accelerateScheduleInBatchName = "AccelerateScheduleInBatch"
getMinResolvedTSByStoresIDsName = "GetMinResolvedTSByStoresIDs"
getMicroServiceMembersName = "GetMicroServiceMembers"
getPDVersionName = "GetPDVersion"
)

type requestInfo struct {
Expand Down
8 changes: 8 additions & 0 deletions tests/integrations/client/http_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/tikv/pd/pkg/schedule/placement"
"github.com/tikv/pd/pkg/utils/testutil"
"github.com/tikv/pd/pkg/utils/tsoutil"
"github.com/tikv/pd/pkg/versioninfo"
"github.com/tikv/pd/tests"
)

Expand Down Expand Up @@ -478,3 +479,10 @@ func (suite *httpClientTestSuite) TestTransferLeader() {
re.Len(members.Members, 2)
re.Equal(leader.GetName(), members.Leader.GetName())
}

func (suite *httpClientTestSuite) TestVersion() {
re := suite.Require()
ver, err := suite.client.GetPDVersion(suite.ctx)
re.NoError(err)
re.Equal(versioninfo.PDReleaseVersion, ver)
}

0 comments on commit 335bd1e

Please sign in to comment.