diff --git a/client/http/interface.go b/client/http/interface.go index c7bfc37958d..06beba85a45 100644 --- a/client/http/interface.go +++ b/client/http/interface.go @@ -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 @@ -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)). diff --git a/client/http/types.go b/client/http/types.go index aaf7e1c0027..56ad0427f12 100644 --- a/client/http/types.go +++ b/client/http/types.go @@ -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"` +} diff --git a/pkg/mcs/discovery/discover.go b/pkg/mcs/discovery/discover.go index 89c45497a87..1ce5ecda51d 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 52751b430c4..bf11ae5c8a4 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 0ee6003e2f9..738140612b8 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 92ffc6603c3..4df43e1ebfc 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 48310d26dea..51668ab9ea8 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 }