Skip to content

Commit

Permalink
mcs: change the get member return value (#7819)
Browse files Browse the repository at this point in the history
ref #5839

Signed-off-by: Ryan Leung <[email protected]>

Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
  • Loading branch information
rleungx and ti-chi-bot[bot] committed Feb 20, 2024
1 parent 1772ad0 commit 46fd313
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 13 deletions.
6 changes: 3 additions & 3 deletions client/http/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ type Client interface {
GetMinResolvedTSByStoresIDs(context.Context, []uint64) (uint64, map[uint64]uint64, error)
GetPDVersion(context.Context) (string, error)
/* Micro Service interfaces */
GetMicroServiceMembers(context.Context, string) ([]string, error)
GetMicroServiceMembers(context.Context, string) ([]MicroServiceMember, error)
GetMicroServicePrimary(context.Context, string) (string, error)
DeleteOperators(context.Context) error

Expand Down Expand Up @@ -856,8 +856,8 @@ func (c *client) GetMinResolvedTSByStoresIDs(ctx context.Context, storeIDs []uin
}

// GetMicroServiceMembers gets the members of the microservice.
func (c *client) GetMicroServiceMembers(ctx context.Context, service string) ([]string, error) {
var members []string
func (c *client) GetMicroServiceMembers(ctx context.Context, service string) ([]MicroServiceMember, error) {
var members []MicroServiceMember
err := c.request(ctx, newRequestInfo().
WithName(getMicroServiceMembersName).
WithURI(MicroServiceMembers(service)).
Expand Down
9 changes: 9 additions & 0 deletions client/http/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -592,3 +592,12 @@ type MembersInfo struct {
Leader *pdpb.Member `json:"leader,omitempty"`
EtcdLeader *pdpb.Member `json:"etcd_leader,omitempty"`
}

// MicroServiceMember is the member info of a micro service.
type MicroServiceMember struct {
ServiceAddr string `json:"service-addr"`
Version string `json:"version"`
GitHash string `json:"git-hash"`
DeployPath string `json:"deploy-path"`
StartTimestamp int64 `json:"start-timestamp"`
}
8 changes: 4 additions & 4 deletions pkg/mcs/discovery/discover.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func Discover(cli *clientv3.Client, clusterID, serviceName string) ([]string, er
}

// GetMSMembers returns all the members of the specified service name.
func GetMSMembers(name string, client *clientv3.Client) ([]string, error) {
func GetMSMembers(name string, client *clientv3.Client) ([]ServiceRegistryEntry, error) {
switch name {
case utils.TSOServiceName, utils.SchedulingServiceName, utils.ResourceManagerServiceName:
clusterID, err := etcdutil.GetClusterID(client, utils.ClusterIDPath)
Expand All @@ -61,18 +61,18 @@ func GetMSMembers(name string, client *clientv3.Client) ([]string, error) {
return nil, errs.ErrEtcdTxnConflict.FastGenByArgs()
}

var addrs []string
var entries []ServiceRegistryEntry
for _, resp := range resps.Responses {
for _, keyValue := range resp.GetResponseRange().GetKvs() {
var entry ServiceRegistryEntry
if err = entry.Deserialize(keyValue.Value); err != nil {
log.Error("try to deserialize service registry entry failed", zap.String("key", string(keyValue.Key)), zap.Error(err))
continue
}
addrs = append(addrs, entry.ServiceAddr)
entries = append(entries, entry)
}
}
return addrs, nil
return entries, nil
}

return nil, errors.Errorf("unknown service name %s", name)
Expand Down
6 changes: 5 additions & 1 deletion pkg/mcs/discovery/registry_entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ import (

// ServiceRegistryEntry is the registry entry of a service
type ServiceRegistryEntry struct {
ServiceAddr string `json:"service-addr"`
ServiceAddr string `json:"service-addr"`
Version string `json:"version"`
GitHash string `json:"git-hash"`
DeployPath string `json:"deploy-path"`
StartTimestamp int64 `json:"start-timestamp"`
}

// Serialize this service registry entry
Expand Down
12 changes: 11 additions & 1 deletion pkg/mcs/scheduling/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,17 @@ func (s *Server) startServer() (err error) {
// different service modes provided by the same pd-server binary
bs.ServerInfoGauge.WithLabelValues(versioninfo.PDReleaseVersion, versioninfo.PDGitHash).Set(float64(time.Now().Unix()))
bs.ServerMaxProcsGauge.Set(float64(runtime.GOMAXPROCS(0)))
s.serviceID = &discovery.ServiceRegistryEntry{ServiceAddr: s.cfg.AdvertiseListenAddr}
deployPath, err := os.Executable()
if err != nil {
deployPath = ""
}
s.serviceID = &discovery.ServiceRegistryEntry{
ServiceAddr: s.cfg.AdvertiseListenAddr,
Version: versioninfo.PDReleaseVersion,
GitHash: versioninfo.PDGitHash,
DeployPath: deployPath,
StartTimestamp: s.StartTimestamp(),
}
uniqueName := s.cfg.GetAdvertiseListenAddr()
uniqueID := memberutil.GenerateUniqueID(uniqueName)
log.Info("joining primary election", zap.String("participant-name", uniqueName), zap.Uint64("participant-id", uniqueID))
Expand Down
12 changes: 11 additions & 1 deletion pkg/mcs/tso/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,17 @@ func (s *Server) startServer() (err error) {
s.serverLoopCtx, s.serverLoopCancel = context.WithCancel(s.Context())
legacySvcRootPath := endpoint.LegacyRootPath(s.clusterID)
tsoSvcRootPath := endpoint.TSOSvcRootPath(s.clusterID)
s.serviceID = &discovery.ServiceRegistryEntry{ServiceAddr: s.cfg.AdvertiseListenAddr}
deployPath, err := os.Executable()
if err != nil {
deployPath = ""
}
s.serviceID = &discovery.ServiceRegistryEntry{
ServiceAddr: s.cfg.AdvertiseListenAddr,
Version: versioninfo.PDReleaseVersion,
GitHash: versioninfo.PDGitHash,
DeployPath: deployPath,
StartTimestamp: s.StartTimestamp(),
}
s.keyspaceGroupManager = tso.NewKeyspaceGroupManager(
s.serverLoopCtx, s.serviceID, s.GetClient(), s.GetHTTPClient(), s.cfg.AdvertiseListenAddr,
discovery.TSOPath(s.clusterID), legacySvcRootPath, tsoSvcRootPath, s.cfg)
Expand Down
6 changes: 3 additions & 3 deletions server/apiv2/handlers/micro_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func RegisterMicroService(r *gin.RouterGroup) {
// @Tags members
// @Summary Get all members of the cluster for the specified service.
// @Produce json
// @Success 200 {object} []string
// @Success 200 {object} []discovery.ServiceRegistryEntry
// @Router /ms/members/{service} [get]
func GetMembers(c *gin.Context) {
svr := c.MustGet(middlewares.ServerContextKey).(*server.Server)
Expand All @@ -45,12 +45,12 @@ func GetMembers(c *gin.Context) {
}

if service := c.Param("service"); len(service) > 0 {
addrs, err := discovery.GetMSMembers(service, svr.GetClient())
entries, err := discovery.GetMSMembers(service, svr.GetClient())
if err != nil {
c.AbortWithStatusJSON(http.StatusInternalServerError, err.Error())
return
}
c.IndentedJSON(http.StatusOK, addrs)
c.IndentedJSON(http.StatusOK, entries)
return
}

Expand Down

0 comments on commit 46fd313

Please sign in to comment.