diff --git a/cmd/pd-server/main.go b/cmd/pd-server/main.go index 7f42c5b4adc..d54779e53e4 100644 --- a/cmd/pd-server/main.go +++ b/cmd/pd-server/main.go @@ -86,6 +86,8 @@ func NewTSOServiceCommand() *cobra.Command { cmd.Flags().StringP("cacert", "", "", "path of file that contains list of trusted TLS CAs") cmd.Flags().StringP("cert", "", "", "path of file that contains X509 certificate in PEM format") cmd.Flags().StringP("key", "", "", "path of file that contains X509 key in PEM format") + cmd.Flags().StringP("log-level", "L", "info", "log level: debug, info, warn, error, fatal (default 'info')") + cmd.Flags().StringP("log-file", "", "", "log file path") return cmd } @@ -104,6 +106,8 @@ func NewResourceManagerServiceCommand() *cobra.Command { cmd.Flags().StringP("cacert", "", "", "path of file that contains list of trusted TLS CAs") cmd.Flags().StringP("cert", "", "", "path of file that contains X509 certificate in PEM format") cmd.Flags().StringP("key", "", "", "path of file that contains X509 key in PEM format") + cmd.Flags().StringP("log-level", "L", "info", "log level: debug, info, warn, error, fatal (default 'info')") + cmd.Flags().StringP("log-file", "", "", "log file path") return cmd } diff --git a/pkg/mcs/resource_manager/server/config.go b/pkg/mcs/resource_manager/server/config.go index 9f7ee63231b..be442381d9c 100644 --- a/pkg/mcs/resource_manager/server/config.go +++ b/pkg/mcs/resource_manager/server/config.go @@ -71,6 +71,9 @@ type Config struct { Security configutil.SecurityConfig `toml:"security" json:"security"` + // WarningMsgs contains all warnings during parsing. + WarningMsgs []string + // LeaderLease defines the time within which a Resource Manager primary/leader must // update its TTL in etcd, otherwise etcd will expire the leader key and other servers // can campaign the primary/leader again. Etcd only supports seconds TTL, so here is @@ -179,11 +182,9 @@ func (c *Config) Parse(flagSet *pflag.FlagSet) error { // Adjust is used to adjust the resource manager configurations. func (c *Config) Adjust(meta *toml.MetaData, reloading bool) error { configMetaData := configutil.NewConfigMetadata(meta) - warningMsgs := make([]string, 0) if err := configMetaData.CheckUndecoded(); err != nil { - warningMsgs = append(warningMsgs, err.Error()) + c.WarningMsgs = append(c.WarningMsgs, err.Error()) } - configutil.PrintConfigCheckMsg(os.Stdout, warningMsgs) if c.Name == "" { hostname, err := os.Hostname() diff --git a/pkg/mcs/resource_manager/server/server.go b/pkg/mcs/resource_manager/server/server.go index a4a1423ee40..1ec0e912fda 100644 --- a/pkg/mcs/resource_manager/server/server.go +++ b/pkg/mcs/resource_manager/server/server.go @@ -32,7 +32,9 @@ import ( "time" grpcprometheus "github.com/grpc-ecosystem/go-grpc-prometheus" + "github.com/pingcap/kvproto/pkg/diagnosticspb" "github.com/pingcap/log" + "github.com/pingcap/sysutil" "github.com/soheilhy/cmux" "github.com/spf13/cobra" "github.com/tikv/pd/pkg/errs" @@ -53,8 +55,11 @@ import ( // Server is the resource manager server, and it implements bs.Server. type Server struct { + diagnosticspb.DiagnosticsServer // Server state. 0 is not running, 1 is running. isRunning int64 + // Server start timestamp + startTimestamp int64 ctx context.Context serverLoopCtx context.Context @@ -419,13 +424,15 @@ func (s *Server) startServer() (err error) { return nil } -// NewServer creates a new resource manager server. -func NewServer(ctx context.Context, cfg *Config) *Server { - return &Server{ - name: cfg.Name, - ctx: ctx, - cfg: cfg, +// CreateServer creates the Server +func CreateServer(ctx context.Context, cfg *Config) *Server { + svr := &Server{ + DiagnosticsServer: sysutil.NewDiagnosticsServer(cfg.Log.File.Filename), + startTimestamp: time.Now().Unix(), + cfg: cfg, + ctx: ctx, } + return svr } // CreateServerWrapper encapsulates the configuration/log/metrics initialization and create the server @@ -459,15 +466,14 @@ func CreateServerWrapper(cmd *cobra.Command, args []string) { // Flushing any buffered log entries defer log.Sync() - versioninfo.Log("resource manager") - log.Info("resource manager config", zap.Reflect("config", cfg)) + versioninfo.Log("Resource Manager") + log.Info("Resource Manager config", zap.Reflect("config", cfg)) grpcprometheus.EnableHandlingTimeHistogram() - metricutil.Push(&cfg.Metric) ctx, cancel := context.WithCancel(context.Background()) - svr := NewServer(ctx, cfg) + svr := CreateServer(ctx, cfg) sc := make(chan os.Signal, 1) signal.Notify(sc, diff --git a/pkg/mcs/resource_manager/server/testutil.go b/pkg/mcs/resource_manager/server/testutil.go index 77228763327..3de0e32c0ab 100644 --- a/pkg/mcs/resource_manager/server/testutil.go +++ b/pkg/mcs/resource_manager/server/testutil.go @@ -34,7 +34,7 @@ func NewTestServer(ctx context.Context, re *require.Assertions, cfg *Config) (*S // Flushing any buffered log entries defer log.Sync() - s := NewServer(ctx, cfg) + s := CreateServer(ctx, cfg) if err = s.Run(); err != nil { return nil, nil, err }