diff --git a/api/init.go b/api/init.go index 484bf2e81..6bfa8138c 100644 --- a/api/init.go +++ b/api/init.go @@ -47,11 +47,8 @@ func InitWithConfigFile(configPath string) error { // initCoreComponents init core components with default config // it's better SetDefaultConfig before initCoreComponents func initCoreComponents() error { - if config.EnableMetricLog() { - err := metric.InitTask() - if err != nil { - return err - } + if err := metric.InitTask(); err != nil { + return err } system.InitCollector(config.SystemStatCollectIntervalMs()) diff --git a/core/config/config.go b/core/config/config.go index 265f637d8..60b84f1c7 100644 --- a/core/config/config.go +++ b/core/config/config.go @@ -191,7 +191,3 @@ func SystemStatCollectIntervalMs() uint32 { func UseCacheTime() bool { return globalCfg.UseCacheTime() } - -func EnableMetricLog() bool { - return globalCfg.EnableMetricLog() -} diff --git a/core/config/entity.go b/core/config/entity.go index b91b14727..1ad020a6d 100644 --- a/core/config/entity.go +++ b/core/config/entity.go @@ -19,8 +19,6 @@ type SentinelConfig struct { // Type indicates the classification of the service (e.g. web service, API gateway). Type int32 } - // EnableMetricLog represents whether to enable metric monitor log - EnableMetricLog bool `yaml:"enableMetricLog"` // Log represents configuration items related to logging. Log LogConfig // Stat represents configuration items related to statistics. @@ -83,8 +81,7 @@ func NewDefaultConfig() *Entity { CollectIntervalMs: DefaultSystemStatCollectIntervalMs, }, }, - EnableMetricLog: true, - UseCacheTime: true, + UseCacheTime: true, }, } } @@ -155,7 +152,3 @@ func (entity *Entity) SystemStatCollectIntervalMs() uint32 { func (entity *Entity) UseCacheTime() bool { return entity.Sentinel.UseCacheTime } - -func (entity *Entity) EnableMetricLog() bool { - return entity.Sentinel.EnableMetricLog -} diff --git a/core/log/metric/aggregator.go b/core/log/metric/aggregator.go index 1f660b2ad..641bc9d21 100644 --- a/core/log/metric/aggregator.go +++ b/core/log/metric/aggregator.go @@ -31,6 +31,11 @@ var ( func InitTask() (err error) { initOnce.Do(func() { + flushInterval := config.MetricLogFlushIntervalSec() + if flushInterval == 0 { + return + } + metricWriter, err = NewDefaultMetricLogWriter(config.MetricLogSingleFileMaxSize(), config.MetricLogMaxFileAmount()) if err != nil { logger.Errorf("Failed to initialize the MetricLogWriter: %+v", err) @@ -40,10 +45,6 @@ func InitTask() (err error) { // Schedule the log flushing task go util.RunWithRecover(writeTaskLoop, logger) // Schedule the log aggregating task - flushInterval := config.MetricLogFlushIntervalSec() - if flushInterval == 0 { - return - } ticker := time.NewTicker(time.Duration(flushInterval) * time.Second) go util.RunWithRecover(func() { for {