diff --git a/pkg/mcs/discovery/discover.go b/pkg/mcs/discovery/discover.go index 89c45497a876..1ce5ecda51dd 100644 --- a/pkg/mcs/discovery/discover.go +++ b/pkg/mcs/discovery/discover.go @@ -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) @@ -61,7 +61,7 @@ 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 @@ -69,10 +69,10 @@ func GetMSMembers(name string, client *clientv3.Client) ([]string, error) { 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) diff --git a/pkg/mcs/discovery/registry_entry.go b/pkg/mcs/discovery/registry_entry.go index 52751b430c44..bf11ae5c8a40 100644 --- a/pkg/mcs/discovery/registry_entry.go +++ b/pkg/mcs/discovery/registry_entry.go @@ -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 diff --git a/pkg/mcs/scheduling/server/server.go b/pkg/mcs/scheduling/server/server.go index 0ee6003e2f94..738140612b86 100644 --- a/pkg/mcs/scheduling/server/server.go +++ b/pkg/mcs/scheduling/server/server.go @@ -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)) diff --git a/pkg/mcs/tso/server/server.go b/pkg/mcs/tso/server/server.go index 92ffc6603c32..4df43e1ebfcd 100644 --- a/pkg/mcs/tso/server/server.go +++ b/pkg/mcs/tso/server/server.go @@ -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) diff --git a/server/apiv2/handlers/micro_service.go b/server/apiv2/handlers/micro_service.go index 48310d26deab..51668ab9ea80 100644 --- a/server/apiv2/handlers/micro_service.go +++ b/server/apiv2/handlers/micro_service.go @@ -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) @@ -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 }