Skip to content

Commit

Permalink
change the get member return value
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Leung <rleungx@gmail.com>
  • Loading branch information
rleungx committed Feb 18, 2024
1 parent 5a37b80 commit 97ee263
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 10 deletions.
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 97ee263

Please sign in to comment.