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

mcs: add log flags #6777

Merged
merged 1 commit into from
Jul 10, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@

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 @@
// 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())

Check warning on line 203 in pkg/mcs/resourcemanager/server/config.go

View check run for this annotation

Codecov / codecov/patch

pkg/mcs/resourcemanager/server/config.go#L203

Added line #L203 was not covered by tests
}
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 @@
"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 @@

// 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 @@
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 @@
// 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))

Check warning on line 470 in pkg/mcs/resourcemanager/server/server.go

View check run for this annotation

Codecov / codecov/patch

pkg/mcs/resourcemanager/server/server.go#L469-L470

Added lines #L469 - L470 were not covered by tests

grpcprometheus.EnableHandlingTimeHistogram()

metricutil.Push(&cfg.Metric)

ctx, cancel := context.WithCancel(context.Background())
svr := NewServer(ctx, cfg)
svr := CreateServer(ctx, cfg)

Check warning on line 476 in pkg/mcs/resourcemanager/server/server.go

View check run for this annotation

Codecov / codecov/patch

pkg/mcs/resourcemanager/server/server.go#L476

Added line #L476 was not covered by tests

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