Skip to content

Commit 378d199

Browse files
committed
fix: PR comments
fix: PR comments fix: PR comments fix: PR comments fix: PR comments fix: PR comments fix: PR comments
1 parent 70ecc3e commit 378d199

File tree

5 files changed

+31
-25
lines changed

5 files changed

+31
-25
lines changed

cmd/base/options/generic.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,9 @@ limitations under the License.
1717
package options
1818

1919
import (
20-
"flag"
21-
"os"
22-
2320
"k8s.io/apimachinery/pkg/util/errors"
2421
cliflag "k8s.io/component-base/cli/flag"
2522
componentbaseconfig "k8s.io/component-base/config"
26-
"k8s.io/klog/v2"
2723

2824
"github.com/kubewharf/katalyst-core/pkg/config/generic"
2925
"github.com/kubewharf/katalyst-core/pkg/util/process"
@@ -72,12 +68,6 @@ func NewGenericOptions() *GenericOptions {
7268
func (o *GenericOptions) AddFlags(fss *cliflag.NamedFlagSets) {
7369
fs := fss.FlagSet("generic")
7470

75-
local := flag.NewFlagSet(os.Args[0], flag.ExitOnError)
76-
klog.InitFlags(local)
77-
local.VisitAll(func(fl *flag.Flag) {
78-
fs.AddGoFlag(fl)
79-
})
80-
8171
fs.BoolVar(&o.DryRun, "dry-run", o.DryRun, "A bool to enable and disable dry-run.")
8272
fs.BoolVar(&o.EnableHealthzCheck, "enable-healthz-check", o.EnableHealthzCheck, "A bool to enable and disable healthz check.")
8373

cmd/base/options/log.go

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ limitations under the License.
1717
package options
1818

1919
import (
20+
"flag"
21+
"os"
22+
2023
"github.com/spf13/pflag"
24+
"k8s.io/klog/v2"
2125

2226
"github.com/kubewharf/katalyst-core/pkg/config/generic"
2327
"github.com/kubewharf/katalyst-core/pkg/util/general"
@@ -28,7 +32,7 @@ type LogsOptions struct {
2832
LogFileMaxSizeInMB uint64
2933
SupportAsyncLogging bool
3034
LogDir string
31-
LogBufferSizeMB int
35+
LogBufferSize int
3236
LogFileMaxAge int
3337
LogFileMaxBackups int
3438
}
@@ -37,19 +41,28 @@ func NewLogsOptions() *LogsOptions {
3741
return &LogsOptions{
3842
LogPackageLevel: general.LoggingPKGFull,
3943
LogFileMaxSizeInMB: 1800,
40-
LogBufferSizeMB: 10000,
44+
LogBufferSize: 10000,
4145
LogFileMaxAge: 7,
4246
LogFileMaxBackups: 10,
4347
}
4448
}
4549

4650
// AddFlags adds flags to the specified FlagSet.
4751
func (o *LogsOptions) AddFlags(fs *pflag.FlagSet) {
52+
fs.BoolVar(&o.SupportAsyncLogging, "support-async-logging", o.SupportAsyncLogging, "whether to support async logging")
53+
// If async logging is enabled, we do not call klog.InitFlags to avoid conflicting with klog flags.
54+
if !o.SupportAsyncLogging {
55+
local := flag.NewFlagSet(os.Args[0], flag.ExitOnError)
56+
klog.InitFlags(local)
57+
local.VisitAll(func(fl *flag.Flag) {
58+
fs.AddGoFlag(fl)
59+
})
60+
} else {
61+
fs.StringVar(&o.LogDir, "log_dir", o.LogDir, "directory to store logs")
62+
}
4863
fs.Var(&o.LogPackageLevel, "logs-package-level", "the default package level for logging")
4964
fs.Uint64Var(&o.LogFileMaxSizeInMB, "log-file-max-size", o.LogFileMaxSizeInMB, "Max size of klog file in MB.")
50-
fs.BoolVar(&o.SupportAsyncLogging, "support-async-logging", o.SupportAsyncLogging, "whether to support async logging")
51-
fs.StringVar(&o.LogDir, "log-dir", o.LogDir, "directory of log file")
52-
fs.IntVar(&o.LogBufferSizeMB, "log-buffer-size", o.LogBufferSizeMB, "size of the ring buffer to store async logs")
65+
fs.IntVar(&o.LogBufferSize, "log-buffer-size", o.LogBufferSize, "size of the ring buffer to store async logs")
5366
fs.IntVar(&o.LogFileMaxAge, "log-file-max-age", o.LogFileMaxAge, "max age of klog log file in days")
5467
fs.IntVar(&o.LogFileMaxBackups, "log-file-max-backups", o.LogFileMaxBackups, "max number of klog log file backups")
5568
}
@@ -59,8 +72,8 @@ func (o *LogsOptions) ApplyTo(c *generic.LogConfiguration) error {
5972
general.SetLogFileMaxSize(o.LogFileMaxSizeInMB)
6073
c.SupportAsyncLogging = o.SupportAsyncLogging
6174
c.LogDir = o.LogDir
75+
c.LogBufferSize = o.LogBufferSize
6276
c.LogFileMaxSize = int(o.LogFileMaxSizeInMB)
63-
c.LogBufferSizeMB = o.LogBufferSizeMB
6477
c.LogFileMaxAge = o.LogFileMaxAge
6578
c.LogFileMaxBackups = o.LogFileMaxBackups
6679
return nil

cmd/katalyst-agent/app/agent.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func Run(
6464
}
6565

6666
if conf.SupportAsyncLogging {
67-
asyncLogger := logging.NewAsyncLogger(genericCtx, conf.LogDir, conf.LogFileMaxSize, conf.LogFileMaxAge, conf.LogFileMaxBackups, conf.LogBufferSizeMB)
67+
asyncLogger := logging.NewAsyncLogger(genericCtx, conf.LogDir, conf.LogFileMaxSize, conf.LogFileMaxAge, conf.LogFileMaxBackups, conf.LogBufferSize)
6868
defer asyncLogger.Shutdown()
6969
}
7070

pkg/config/generic/log.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type LogConfiguration struct {
2020
SupportAsyncLogging bool
2121
LogDir string
2222
LogFileMaxSize int
23-
LogBufferSizeMB int
23+
LogBufferSize int
2424
LogFileMaxAge int
2525
LogFileMaxBackups int
2626
}

pkg/util/logging/logger.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ limitations under the License.
1717
package logging
1818

1919
import (
20+
"fmt"
21+
"os"
2022
"path"
23+
"path/filepath"
2124
"time"
2225

2326
"github.com/rs/zerolog/diode"
@@ -44,11 +47,11 @@ const (
4447
metricsNameNumDroppedFatalLogs = "number_of_dropped_fatal_logs"
4548
)
4649

47-
const (
48-
defaultInfoLogFileName = "agent.info.log"
49-
defaultWarningLogFileName = "agent.warning.log"
50-
defaultErrorLogFileName = "agent.error.log"
51-
defaultFatalLogFileName = "agent.fatal.log"
50+
var (
51+
defaultInfoLogFileName = fmt.Sprintf("%s.%s.log", filepath.Base(os.Args[0]), InfoSeverity)
52+
defaultWarningLogFileName = fmt.Sprintf("%s.%s.log", filepath.Base(os.Args[0]), WarningSeverity)
53+
defaultErrorLogFileName = fmt.Sprintf("%s.%s.log", filepath.Base(os.Args[0]), ErrorSeverity)
54+
defaultFatalLogFileName = fmt.Sprintf("%s.%s.log", filepath.Base(os.Args[0]), FatalSeverity)
5255
)
5356

5457
type logInfo struct {
@@ -70,7 +73,7 @@ type AsyncLogger struct {
7073
// NewAsyncLogger creates an async logger that produces an async writer for each of the severity levels.
7174
// The async writer spins up a goroutine that periodically flushes the buffered logs to disk.
7275
func NewAsyncLogger(
73-
agentCtx *agent.GenericContext, logDir string, maxSizeMB, maxAge, maxBackups, bufferSizeMB int,
76+
agentCtx *agent.GenericContext, logDir string, maxSizeMB, maxAge, maxBackups, bufferSize int,
7477
) *AsyncLogger {
7578
wrappedEmitter := agentCtx.EmitterPool.GetDefaultMetricsEmitter()
7679

@@ -85,7 +88,7 @@ func NewAsyncLogger(
8588
}
8689

8790
// diodeWriter is a writer that stores logs in a ring buffer and asynchronously flushes them
88-
diodeWriter := diode.NewWriter(lumberjackLogger, bufferSizeMB, 10*time.Millisecond, func(missed int) {
91+
diodeWriter := diode.NewWriter(lumberjackLogger, bufferSize, 10*time.Millisecond, func(missed int) {
8992
_ = wrappedEmitter.StoreInt64(logInfo.metricsName, int64(missed), metrics.MetricTypeNameRaw)
9093
})
9194
// Overrides the default synchronous writer with the diode writer

0 commit comments

Comments
 (0)