Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pdms: Add the name field to the startup parameters #8461

Merged
merged 2 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cmd/pd-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ func NewTSOServiceCommand() *cobra.Command {
Short: "Run the TSO service",
Run: tso.CreateServerWrapper,
}
cmd.Flags().StringP("name", "", "", "human-readable name for this tso member")
cmd.Flags().BoolP("version", "V", false, "print version information and exit")
cmd.Flags().StringP("config", "", "", "config file")
cmd.Flags().StringP("backend-endpoints", "", "", "url for etcd client")
Expand All @@ -114,6 +115,7 @@ func NewSchedulingServiceCommand() *cobra.Command {
Short: "Run the scheduling service",
Run: scheduling.CreateServerWrapper,
}
cmd.Flags().StringP("name", "", "", "human-readable name for this scheduling member")
cmd.Flags().BoolP("version", "V", false, "print version information and exit")
cmd.Flags().StringP("config", "", "", "config file")
cmd.Flags().StringP("backend-endpoints", "", "", "url for etcd client")
Expand All @@ -134,6 +136,7 @@ func NewResourceManagerServiceCommand() *cobra.Command {
Short: "Run the resource manager service",
Run: resource_manager.CreateServerWrapper,
}
cmd.Flags().StringP("name", "", "", "human-readable name for this resource manager member")
cmd.Flags().BoolP("version", "V", false, "print version information and exit")
cmd.Flags().StringP("config", "", "", "config file")
cmd.Flags().StringP("backend-endpoints", "", "", "url for etcd client")
Expand Down
8 changes: 4 additions & 4 deletions pkg/mcs/discovery/discover.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@
}

// GetMSMembers returns all the members of the specified service name.
func GetMSMembers(name string, client *clientv3.Client) ([]ServiceRegistryEntry, error) {
switch name {
func GetMSMembers(serviceName string, client *clientv3.Client) ([]ServiceRegistryEntry, error) {
switch serviceName {
case utils.TSOServiceName, utils.SchedulingServiceName, utils.ResourceManagerServiceName:
clusterID, err := etcdutil.GetClusterID(client, utils.ClusterIDPath)
if err != nil {
return nil, err
}
servicePath := ServicePath(strconv.FormatUint(clusterID, 10), name)
servicePath := ServicePath(strconv.FormatUint(clusterID, 10), serviceName)
resps, err := kv.NewSlowLogTxn(client).Then(clientv3.OpGet(servicePath, clientv3.WithPrefix())).Commit()
if err != nil {
return nil, errs.ErrEtcdKVGet.Wrap(err).GenWithStackByCause()
Expand All @@ -75,5 +75,5 @@
return entries, nil
}

return nil, errors.Errorf("unknown service name %s", name)
return nil, errors.Errorf("unknown service name %s", serviceName)

Check warning on line 78 in pkg/mcs/discovery/discover.go

View check run for this annotation

Codecov / codecov/patch

pkg/mcs/discovery/discover.go#L78

Added line #L78 was not covered by tests
}
3 changes: 3 additions & 0 deletions pkg/mcs/discovery/registry_entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ import (

// ServiceRegistryEntry is the registry entry of a service
type ServiceRegistryEntry struct {
// The specific value will be assigned only if the startup parameter is added.
// If not assigned, the default value(service-hostname) will be used.
Name string `json:"name"`
ServiceAddr string `json:"service-addr"`
Version string `json:"version"`
GitHash string `json:"git-hash"`
Expand Down
1 change: 1 addition & 0 deletions pkg/mcs/resourcemanager/server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ func (c *Config) Parse(flagSet *pflag.FlagSet) error {
}

// Ignore the error check here
configutil.AdjustCommandLineString(flagSet, &c.Name, "name")
configutil.AdjustCommandLineString(flagSet, &c.Log.Level, "log-level")
configutil.AdjustCommandLineString(flagSet, &c.Log.File.Filename, "log-file")
configutil.AdjustCommandLineString(flagSet, &c.Metric.PushAddress, "metrics-addr")
Expand Down
2 changes: 1 addition & 1 deletion pkg/mcs/resourcemanager/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ func (s *Server) startServer() (err error) {
s.startServerLoop()

// Server has started.
entry := &discovery.ServiceRegistryEntry{ServiceAddr: s.cfg.AdvertiseListenAddr}
entry := &discovery.ServiceRegistryEntry{ServiceAddr: s.cfg.AdvertiseListenAddr, Name: s.Name()}
serializedEntry, err := entry.Serialize()
if err != nil {
return err
Expand Down
4 changes: 3 additions & 1 deletion pkg/mcs/resourcemanager/server/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,18 @@ func NewTestServer(ctx context.Context, re *require.Assertions, cfg *Config) (*S
// GenerateConfig generates a new config with the given options.
func GenerateConfig(c *Config) (*Config, error) {
arguments := []string{
"--name=" + c.Name,
"--listen-addr=" + c.ListenAddr,
"--advertise-listen-addr=" + c.AdvertiseListenAddr,
"--backend-endpoints=" + c.BackendEndpoints,
}

flagSet := pflag.NewFlagSet("test", pflag.ContinueOnError)
flagSet.StringP("name", "", "", "human-readable name for this resource manager member")
flagSet.BoolP("version", "V", false, "print version information and exit")
flagSet.StringP("config", "", "", "config file")
flagSet.StringP("backend-endpoints", "", "", "url for etcd client")
flagSet.StringP("listen-addr", "", "", "listen address for tso service")
flagSet.StringP("listen-addr", "", "", "listen address for resource manager service")
flagSet.StringP("advertise-listen-addr", "", "", "advertise urls for listen address (default '${listen-addr}')")
flagSet.StringP("cacert", "", "", "path of file that contains list of trusted TLS CAs")
flagSet.StringP("cert", "", "", "path of file that contains X509 certificate in PEM format")
Expand Down
1 change: 1 addition & 0 deletions pkg/mcs/scheduling/server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ func (c *Config) Parse(flagSet *pflag.FlagSet) error {
}

// Ignore the error check here
configutil.AdjustCommandLineString(flagSet, &c.Name, "name")
configutil.AdjustCommandLineString(flagSet, &c.Log.Level, "log-level")
configutil.AdjustCommandLineString(flagSet, &c.Log.File.Filename, "log-file")
configutil.AdjustCommandLineString(flagSet, &c.Metric.PushAddress, "metrics-addr")
Expand Down
1 change: 1 addition & 0 deletions pkg/mcs/scheduling/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ func (s *Server) startServer() (err error) {
GitHash: versioninfo.PDGitHash,
DeployPath: deployPath,
StartTimestamp: s.StartTimestamp(),
Name: s.Name(),
}
uniqueName := s.cfg.GetAdvertiseListenAddr()
uniqueID := memberutil.GenerateUniqueID(uniqueName)
Expand Down
1 change: 1 addition & 0 deletions pkg/mcs/tso/server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ func (c *Config) Parse(flagSet *pflag.FlagSet) error {
}

// Ignore the error check here
configutil.AdjustCommandLineString(flagSet, &c.Name, "name")
configutil.AdjustCommandLineString(flagSet, &c.Log.Level, "log-level")
configutil.AdjustCommandLineString(flagSet, &c.Log.File.Filename, "log-file")
configutil.AdjustCommandLineString(flagSet, &c.Metric.PushAddress, "metrics-addr")
Expand Down
1 change: 1 addition & 0 deletions pkg/mcs/tso/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ func (s *Server) startServer() (err error) {
GitHash: versioninfo.PDGitHash,
DeployPath: deployPath,
StartTimestamp: s.StartTimestamp(),
Name: s.Name(),
}
s.keyspaceGroupManager = tso.NewKeyspaceGroupManager(
s.serverLoopCtx, s.serviceID, s.GetClient(), s.GetHTTPClient(), s.cfg.AdvertiseListenAddr,
Expand Down
2 changes: 2 additions & 0 deletions pkg/mcs/tso/server/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ func MustNewGrpcClient(re *require.Assertions, addr string) (*grpc.ClientConn, t
// GenerateConfig generates a new config with the given options.
func GenerateConfig(c *Config) (*Config, error) {
arguments := []string{
"--name=" + c.Name,
"--listen-addr=" + c.ListenAddr,
"--advertise-listen-addr=" + c.AdvertiseListenAddr,
"--backend-endpoints=" + c.BackendEndpoints,
}

flagSet := pflag.NewFlagSet("test", pflag.ContinueOnError)
flagSet.StringP("name", "", "", "human-readable name for this tso member")
flagSet.BoolP("version", "V", false, "print version information and exit")
flagSet.StringP("config", "", "", "config file")
flagSet.StringP("backend-endpoints", "", "", "url for etcd client")
Expand Down
3 changes: 3 additions & 0 deletions tests/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ func StartSingleResourceManagerTestServer(ctx context.Context, re *require.Asser
cfg := rm.NewConfig()
cfg.BackendEndpoints = backendEndpoints
cfg.ListenAddr = listenAddrs
cfg.Name = cfg.ListenAddr
cfg, err := rm.GenerateConfig(cfg)
re.NoError(err)

Expand All @@ -127,6 +128,7 @@ func StartSingleTSOTestServerWithoutCheck(ctx context.Context, re *require.Asser
cfg := tso.NewConfig()
cfg.BackendEndpoints = backendEndpoints
cfg.ListenAddr = listenAddrs
cfg.Name = cfg.ListenAddr
cfg, err := tso.GenerateConfig(cfg)
re.NoError(err)
// Setup the logger.
Expand Down Expand Up @@ -164,6 +166,7 @@ func StartSingleSchedulingTestServer(ctx context.Context, re *require.Assertions
cfg := sc.NewConfig()
cfg.BackendEndpoints = backendEndpoints
cfg.ListenAddr = listenAddrs
cfg.Name = cfg.ListenAddr
cfg, err := scheduling.GenerateConfig(cfg)
re.NoError(err)

Expand Down