Skip to content

Commit

Permalink
mcs: add log flags (tikv#6777)
Browse files Browse the repository at this point in the history
ref tikv#5766

Signed-off-by: Ryan Leung <[email protected]>
  • Loading branch information
rleungx authored Jul 10, 2023
1 parent dbc9366 commit b2a9768
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
4 changes: 4 additions & 0 deletions cmd/pd-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}

Expand Down
7 changes: 4 additions & 3 deletions pkg/mcs/resourcemanager/server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,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
Expand Down Expand Up @@ -196,11 +199,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()
Expand Down
26 changes: 16 additions & 10 deletions pkg/mcs/resourcemanager/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion pkg/mcs/resourcemanager/server/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit b2a9768

Please sign in to comment.