Skip to content

Commit

Permalink
*: fix log level (#8118) (#8151)
Browse files Browse the repository at this point in the history
close #8117

Signed-off-by: Ryan Leung <rleungx@gmail.com>

Co-authored-by: Ryan Leung <rleungx@gmail.com>
Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
  • Loading branch information
3 people committed May 20, 2024
1 parent 01a8f3f commit 00487a4
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 20 deletions.
8 changes: 4 additions & 4 deletions cmd/pd-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ 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-level", "L", "", "log level: debug, info, warn, error, fatal (default 'info')")
cmd.Flags().StringP("log-file", "", "", "log file path")
return cmd
}
Expand All @@ -122,7 +122,7 @@ func NewSchedulingServiceCommand() *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-level", "L", "", "log level: debug, info, warn, error, fatal (default 'info')")
cmd.Flags().StringP("log-file", "", "", "log file path")
return cmd
}
Expand All @@ -142,7 +142,7 @@ 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-level", "L", "", "log level: debug, info, warn, error, fatal (default 'info')")
cmd.Flags().StringP("log-file", "", "", "log file path")
return cmd
}
Expand Down Expand Up @@ -171,7 +171,7 @@ func addFlags(cmd *cobra.Command) {
cmd.Flags().StringP("initial-cluster", "", "", "initial cluster configuration for bootstrapping, e,g. pd=http://127.0.0.1:2380")
cmd.Flags().StringP("join", "", "", "join to an existing cluster (usage: cluster's '${advertise-client-urls}'")
cmd.Flags().StringP("metrics-addr", "", "", "prometheus pushgateway address, leaves it empty will disable prometheus push")
cmd.Flags().StringP("log-level", "L", "info", "log level: debug, info, warn, error, fatal (default 'info')")
cmd.Flags().StringP("log-level", "L", "", "log level: debug, info, warn, error, fatal (default 'info')")
cmd.Flags().StringP("log-file", "", "", "log file path")
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")
Expand Down
6 changes: 2 additions & 4 deletions pkg/mcs/resourcemanager/server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,6 @@ func (c *Config) Adjust(meta *toml.MetaData, reloading bool) error {
c.adjustLog(configMetaData.Child("log"))
c.Security.Encryption.Adjust()

if len(c.Log.Format) == 0 {
c.Log.Format = utils.DefaultLogFormat
}

c.Controller.Adjust(configMetaData.Child("controller"))
configutil.AdjustInt64(&c.LeaderLease, utils.DefaultLeaderLease)

Expand All @@ -251,6 +247,8 @@ func (c *Config) adjustLog(meta *configutil.ConfigMetaData) {
if !meta.IsDefined("disable-error-verbose") {
c.Log.DisableErrorVerbose = utils.DefaultDisableErrorVerbose
}
configutil.AdjustString(&c.Log.Format, utils.DefaultLogFormat)
configutil.AdjustString(&c.Log.Level, utils.DefaultLogLevel)
}

// GetTLSConfig returns the TLS config.
Expand Down
6 changes: 2 additions & 4 deletions pkg/mcs/scheduling/server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,6 @@ func (c *Config) adjust(meta *toml.MetaData) error {
c.adjustLog(configMetaData.Child("log"))
c.Security.Encryption.Adjust()

if len(c.Log.Format) == 0 {
c.Log.Format = utils.DefaultLogFormat
}

configutil.AdjustInt64(&c.LeaderLease, utils.DefaultLeaderLease)

if err := c.Schedule.Adjust(configMetaData.Child("schedule"), false); err != nil {
Expand All @@ -161,6 +157,8 @@ func (c *Config) adjustLog(meta *configutil.ConfigMetaData) {
if !meta.IsDefined("disable-error-verbose") {
c.Log.DisableErrorVerbose = utils.DefaultDisableErrorVerbose
}
configutil.AdjustString(&c.Log.Format, utils.DefaultLogFormat)
configutil.AdjustString(&c.Log.Level, utils.DefaultLogLevel)
}

// GetListenAddr returns the ListenAddr
Expand Down
6 changes: 2 additions & 4 deletions pkg/mcs/tso/server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,17 +226,15 @@ func (c *Config) Adjust(meta *toml.MetaData, reloading bool) error {
c.adjustLog(configMetaData.Child("log"))
c.Security.Encryption.Adjust()

if len(c.Log.Format) == 0 {
c.Log.Format = utils.DefaultLogFormat
}

return nil
}

func (c *Config) adjustLog(meta *configutil.ConfigMetaData) {
if !meta.IsDefined("disable-error-verbose") {
c.Log.DisableErrorVerbose = utils.DefaultDisableErrorVerbose
}
configutil.AdjustString(&c.Log.Format, utils.DefaultLogFormat)
configutil.AdjustString(&c.Log.Level, utils.DefaultLogLevel)
}

// Validate is used to validate if some configurations are right.
Expand Down
2 changes: 2 additions & 0 deletions pkg/mcs/utils/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ const (
DefaultHTTPGracefulShutdownTimeout = 5 * time.Second
// DefaultLogFormat is the default log format
DefaultLogFormat = "text"
// DefaultLogLevel is the default log level
DefaultLogLevel = "info"
// DefaultDisableErrorVerbose is the default value of DisableErrorVerbose
DefaultDisableErrorVerbose = true
// DefaultLeaderLease is the default value of LeaderLease
Expand Down
7 changes: 3 additions & 4 deletions server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ const (
minTSOUpdatePhysicalInterval = 1 * time.Millisecond

defaultLogFormat = "text"
defaultLogLevel = "info"

defaultServerMemoryLimit = 0
minServerMemoryLimit = 0
Expand Down Expand Up @@ -462,10 +463,6 @@ func (c *Config) Adjust(meta *toml.MetaData, reloading bool) error {

c.Security.Encryption.Adjust()

if len(c.Log.Format) == 0 {
c.Log.Format = defaultLogFormat
}

c.Controller.Adjust(configMetaData.Child("controller"))

return nil
Expand All @@ -475,6 +472,8 @@ func (c *Config) adjustLog(meta *configutil.ConfigMetaData) {
if !meta.IsDefined("disable-error-verbose") {
c.Log.DisableErrorVerbose = defaultDisableErrorVerbose
}
configutil.AdjustString(&c.Log.Format, defaultLogFormat)
configutil.AdjustString(&c.Log.Level, defaultLogLevel)
}

// Clone returns a cloned configuration.
Expand Down
16 changes: 16 additions & 0 deletions server/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,22 @@ tso-update-physical-interval = "15s"
re.NoError(err)

re.Equal(maxTSOUpdatePhysicalInterval, cfg.TSOUpdatePhysicalInterval.Duration)

cfgData = `
[log]
level = "debug"
`
flagSet = pflag.NewFlagSet("testlog", pflag.ContinueOnError)
flagSet.StringP("log-level", "L", "info", "log level: debug, info, warn, error, fatal (default 'info')")
flagSet.Parse(nil)
cfg = NewConfig()
err = cfg.Parse(flagSet)
re.NoError(err)
meta, err = toml.Decode(cfgData, &cfg)
re.NoError(err)
err = cfg.Adjust(&meta, false)
re.NoError(err)
re.Equal("debug", cfg.Log.Level)
}

func TestMigrateFlags(t *testing.T) {
Expand Down

0 comments on commit 00487a4

Please sign in to comment.