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

transmit log rotation max size to nydus daemon #507

Merged
merged 4 commits into from
Jul 14, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ type DaemonConfig struct {
RecoverPolicy string `toml:"recover_policy"`
FsDriver string `toml:"fs_driver"`
ThreadsNumber int `toml:"threads_number"`
LogRotationSize int `toml:"log_rotation_size"`
}

type LoggingConfig struct {
Expand Down Expand Up @@ -227,6 +228,7 @@ func LoadSnapshotterConfig(path string) (*SnapshotterConfig, error) {
if err != nil {
return nil, errors.Wrapf(err, "load toml configuration from file %q", path)
}

if err = tree.Unmarshal(&config); err != nil {
return nil, errors.Wrap(err, "unmarshal snapshotter configuration")
}
Expand Down
3 changes: 2 additions & 1 deletion config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func TestLoadSnapshotterTOMLConfig(t *testing.T) {
RecoverPolicy: "restart",
NydusdConfigPath: "/etc/nydus/nydusd-config.fusedev.json",
ThreadsNumber: 4,
LogRotationSize: 100,
},
SnapshotsConfig: SnapshotConfig{
EnableNydusOverlayFS: false,
Expand Down Expand Up @@ -77,7 +78,7 @@ func TestLoadSnapshotterTOMLConfig(t *testing.T) {
RotateLogLocalTime: true,
RotateLogMaxAge: 7,
RotateLogMaxBackups: 5,
RotateLogMaxSize: 1,
RotateLogMaxSize: 100,
LogToStdout: false,
},
MetricsConfig: MetricsConfig{
Expand Down
1 change: 1 addition & 0 deletions config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func (c *SnapshotterConfig) FillUpWithDefaults() error {
}
daemonConfig.RecoverPolicy = RecoverPolicyRestart.String()
daemonConfig.FsDriver = constant.DefaultFsDriver
daemonConfig.LogRotationSize = constant.DefaultDaemonRotateLogMaxSize

// cache configuration
cacheConfig := &c.CacheManagerConfig
Expand Down
4 changes: 4 additions & 0 deletions config/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ func GetLogLevel() string {
return globalConfig.origin.LoggingConfig.LogLevel
}

func GetDaemonLogRotationSize() int {
return globalConfig.origin.DaemonConfig.LogRotationSize
}

func GetDaemonThreadsNumber() int {
return globalConfig.origin.DaemonConfig.ThreadsNumber
}
Expand Down
11 changes: 6 additions & 5 deletions internal/constant/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ const (
DefaultSystemControllerAddress = "/run/containerd-nydus/system.sock"

// Log rotation
DefaultRotateLogMaxSize = 200 // 200 megabytes
DefaultRotateLogMaxBackups = 10
DefaultRotateLogMaxAge = 0 // days
DefaultRotateLogLocalTime = true
DefaultRotateLogCompress = true
DefaultDaemonRotateLogMaxSize = 100 // 100 megabytes
DefaultRotateLogMaxSize = 200 // 200 megabytes
DefaultRotateLogMaxBackups = 5
DefaultRotateLogMaxAge = 0 // days
DefaultRotateLogLocalTime = true
DefaultRotateLogCompress = true
)
5 changes: 4 additions & 1 deletion misc/snapshotter/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ recover_policy = "restart"
# Nydusd worker thread number to handle FUSE or fscache requests, [0-1024].
# Setting to 0 will use the default configuration of nydusd.
threads_number = 4
# Log rotation size for nydusd, in unit MB(megabytes)
log_rotation_size = 100


[cgroup]
# Whether to use separate cgroup for nydusd.
Expand All @@ -52,7 +55,7 @@ log_rotation_local_time = true
log_rotation_max_age = 7
log_rotation_max_backups = 5
# In unit MB(megabytes)
log_rotation_max_size = 1
log_rotation_max_size = 100

[metrics]
# Enable by assigning an address, empty indicates metrics server is disabled
Expand Down
25 changes: 16 additions & 9 deletions pkg/daemon/command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ type DaemonCommand struct {
Upgrade bool `type:"flag" name:"upgrade" default:""`
ThreadNum string `type:"param" name:"thread-num"`
// `--id` is required by `--supervisor` when starting nydusd
ID string `type:"param" name:"id"`
Config string `type:"param" name:"config"`
Bootstrap string `type:"param" name:"bootstrap"`
Mountpoint string `type:"param" name:"mountpoint"`
APISock string `type:"param" name:"apisock"`
LogLevel string `type:"param" name:"log-level"`
Supervisor string `type:"param" name:"supervisor"`
LogFile string `type:"param" name:"log-file"`
ID string `type:"param" name:"id"`
Config string `type:"param" name:"config"`
Bootstrap string `type:"param" name:"bootstrap"`
Mountpoint string `type:"param" name:"mountpoint"`
APISock string `type:"param" name:"apisock"`
LogLevel string `type:"param" name:"log-level"`
LogRotationSize int `type:"param" name:"log-rotation-size"`
Supervisor string `type:"param" name:"supervisor"`
LogFile string `type:"param" name:"log-file"`
}

// Build exec style command line
Expand Down Expand Up @@ -62,7 +63,7 @@ func BuildCommand(opts []Opt) ([]string, error) {

value := v.Field(i).Interface()

pair := []string{fmt.Sprintf("--%s", tag.Get("name")), fmt.Sprintf("%s", value)}
pair := []string{fmt.Sprintf("--%s", tag.Get("name")), fmt.Sprintf("%v", value)}
args = append(args, pair...)
case "subcommand":
// Zero value will be skipped appending to command line
Expand Down Expand Up @@ -158,6 +159,12 @@ func WithLogLevel(l string) Opt {
}
}

func WithLogRotationSize(l int) Opt {
return func(cmd *DaemonCommand) {
cmd.LogRotationSize = l
}
}

func WithSupervisor(s string) Opt {
return func(cmd *DaemonCommand) {
cmd.Supervisor = s
Expand Down
7 changes: 7 additions & 0 deletions pkg/daemon/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ func WithLogLevel(logLevel string) NewDaemonOpt {
}
}

func WithLogRotationSize(logRotationSize int) NewDaemonOpt {
return func(d *Daemon) error {
d.States.LogRotationSize = logRotationSize
return nil
}
}

func WithConfigDir(dir string) NewDaemonOpt {
return func(d *Daemon) error {
s := filepath.Join(dir, d.ID())
Expand Down
17 changes: 9 additions & 8 deletions pkg/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,15 @@ type NewDaemonOpt func(d *Daemon) error

type States struct {
// A unique ID generated by daemon manager to identify the nydusd instance.
ID string
ProcessID int
APISocket string
LogDir string
LogLevel string
LogToStdout bool
DaemonMode config.DaemonMode
FsDriver string
ID string
ProcessID int
APISocket string
LogDir string
LogLevel string
LogRotationSize int
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does rotation size need to be persisted ? can it come from the global configs set each time nydusd runs

Copy link
Member Author

@sctb512 sctb512 Jul 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to follow the store way of LogLevel. So I added it into this structure. This is a parameter for the daemon. So I believe this is also reasonable.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fine. By adding LogRotationSize to the DB record, we have to consider compatibility. It's possible to be zero when loading from an old nydusd record, and how do you make it apply to an old running nydusd if you never update its DB record. Moverover, if it's zero we don't have to append the argument log-rotation-size to CLI

Copy link
Member Author

@sctb512 sctb512 Jul 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it's zero we don't have to append the argument log-rotation-size to CLI

Yes, you are right. Fixed. Now, the LogRotationSize will be omitted if it is zero when building command arguments.

LogToStdout bool
DaemonMode config.DaemonMode
FsDriver string
// Fusedev mountpoint on host kernel, the fscache fs driver doesn't need a host kernel mountpoint.
Mountpoint string
ThreadNum int
Expand Down
1 change: 1 addition & 0 deletions pkg/filesystem/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,7 @@ func (fs *Filesystem) createDaemon(fsManager *manager.Manager, daemonMode config
daemon.WithConfigDir(config.GetConfigRoot()),
daemon.WithLogDir(config.GetLogDir()),
daemon.WithLogLevel(config.GetLogLevel()),
daemon.WithLogRotationSize(config.GetDaemonLogRotationSize()),
daemon.WithLogToStdout(config.GetLogToStdout()),
daemon.WithNydusdThreadNum(config.GetDaemonThreadsNumber()),
daemon.WithFsDriver(fsManager.FsDriver),
Expand Down
4 changes: 4 additions & 0 deletions pkg/manager/daemon_adaptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ func (m *Manager) BuildDaemonCommand(d *daemon.Daemon, bin string, upgrade bool)
command.WithLogLevel(d.States.LogLevel),
command.WithAPISock(d.GetAPISock()))

if d.States.LogRotationSize > 0 {
cmdOpts = append(cmdOpts, command.WithLogRotationSize(d.States.LogRotationSize))
}

if upgrade {
cmdOpts = append(cmdOpts, command.WithUpgrade())
}
Expand Down