From 335bd1e100aab9e466ef72f4e68aa77068ab4a71 Mon Sep 17 00:00:00 2001 From: lance6716 Date: Wed, 3 Jan 2024 14:14:02 +0800 Subject: [PATCH] http: add GetVersion API (#7648) ref tikv/pd#7300 Signed-off-by: lance6716 Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com> Co-authored-by: Hu# --- client/http/interface.go | 14 ++++++++++++++ client/http/request_info.go | 1 + tests/integrations/client/http_client_test.go | 8 ++++++++ 3 files changed, 23 insertions(+) diff --git a/client/http/interface.go b/client/http/interface.go index 46db7cb6fd8..300ab39d0a5 100644 --- a/client/http/interface.go +++ b/client/http/interface.go @@ -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) @@ -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 +} diff --git a/client/http/request_info.go b/client/http/request_info.go index 1d64197b051..5c003de1bef 100644 --- a/client/http/request_info.go +++ b/client/http/request_info.go @@ -61,6 +61,7 @@ const ( accelerateScheduleInBatchName = "AccelerateScheduleInBatch" getMinResolvedTSByStoresIDsName = "GetMinResolvedTSByStoresIDs" getMicroServiceMembersName = "GetMicroServiceMembers" + getPDVersionName = "GetPDVersion" ) type requestInfo struct { diff --git a/tests/integrations/client/http_client_test.go b/tests/integrations/client/http_client_test.go index 0d527198935..3ba22e664d8 100644 --- a/tests/integrations/client/http_client_test.go +++ b/tests/integrations/client/http_client_test.go @@ -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" ) @@ -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) +}