From 730dcbf2bc2af31ad814e5d02e9d9fdce37f1585 Mon Sep 17 00:00:00 2001 From: Gaius Date: Fri, 26 May 2023 14:14:51 +0800 Subject: [PATCH] feat: optimize field name of ProbeConfig (#2391) Signed-off-by: Gaius --- scheduler/config/config.go | 26 ++++++++++++------------ scheduler/config/config_test.go | 18 ++++++++-------- scheduler/config/constants.go | 15 ++++++-------- scheduler/config/testdata/scheduler.yaml | 4 ++-- 4 files changed, 30 insertions(+), 33 deletions(-) diff --git a/scheduler/config/config.go b/scheduler/config/config.go index 8aea8c6ed..d50e43690 100644 --- a/scheduler/config/config.go +++ b/scheduler/config/config.go @@ -298,7 +298,7 @@ type NetworkConfig struct { } type NetworkTopologyConfig struct { - // Enable network topology service, including probe, network topology collection and synchronization service. + // Enable network topology service, including probe, network topology collection. Enable bool `yaml:"enable" mapstructure:"enable"` // CollectInterval is the interval of collecting network topology. @@ -309,14 +309,14 @@ type NetworkTopologyConfig struct { } type ProbeConfig struct { - // QueueLength is the length of probe queue in directed graph. + // QueueLength is the length of probe queue. QueueLength int `mapstructure:"queueLength" yaml:"queueLength"` - // SyncInterval is the interval of synchronizing host's probes. - SyncInterval time.Duration `mapstructure:"syncInterval" yaml:"syncInterval"` + // Interval is the interval of probing hosts. + Interval time.Duration `mapstructure:"interval" yaml:"interval"` - // SyncCount is the number of probing hosts. - SyncCount int `mapstructure:"syncCount" yaml:"syncCount"` + // Count is the number of probing hosts. + Count int `mapstructure:"count" yaml:"count"` } type TrainerConfig struct { @@ -409,9 +409,9 @@ func New() *Config { Enable: true, CollectInterval: DefaultNetworkTopologyCollectInterval, Probe: ProbeConfig{ - QueueLength: DefaultProbeQueueLength, - SyncInterval: DefaultProbeSyncInterval, - SyncCount: DefaultProbeSyncCount, + QueueLength: DefaultProbeQueueLength, + Interval: DefaultProbeInterval, + Count: DefaultProbeCount, }, }, Trainer: TrainerConfig{ @@ -579,12 +579,12 @@ func (cfg *Config) Validate() error { return errors.New("probe requires parameter queueLength") } - if cfg.NetworkTopology.Probe.SyncInterval <= 0 { - return errors.New("probe requires parameter syncInterval") + if cfg.NetworkTopology.Probe.Interval <= 0 { + return errors.New("probe requires parameter interval") } - if cfg.NetworkTopology.Probe.SyncCount <= 0 { - return errors.New("probe requires parameter syncCount") + if cfg.NetworkTopology.Probe.Count <= 0 { + return errors.New("probe requires parameter count") } if cfg.Trainer.Enable { diff --git a/scheduler/config/config_test.go b/scheduler/config/config_test.go index 92217a88c..873a59706 100644 --- a/scheduler/config/config_test.go +++ b/scheduler/config/config_test.go @@ -164,9 +164,9 @@ func TestConfig_Load(t *testing.T) { Enable: true, CollectInterval: 60 * time.Second, Probe: ProbeConfig{ - QueueLength: 5, - SyncInterval: 30 * time.Second, - SyncCount: 10, + QueueLength: 5, + Interval: 30 * time.Second, + Count: 10, }, }, Trainer: TrainerConfig{ @@ -711,31 +711,31 @@ func TestConfig_Validate(t *testing.T) { }, }, { - name: "probe requires parameter SyncInterval", + name: "probe requires parameter interval", config: New(), mock: func(cfg *Config) { cfg.Manager = mockManagerConfig cfg.Database.Redis = mockRedisConfig cfg.Job = mockJobConfig - cfg.NetworkTopology.Probe.SyncInterval = 0 + cfg.NetworkTopology.Probe.Interval = 0 }, expect: func(t *testing.T, err error) { assert := assert.New(t) - assert.EqualError(err, "probe requires parameter syncInterval") + assert.EqualError(err, "probe requires parameter interval") }, }, { - name: "probe requires parameter SyncCount", + name: "probe requires parameter count", config: New(), mock: func(cfg *Config) { cfg.Manager = mockManagerConfig cfg.Database.Redis = mockRedisConfig cfg.Job = mockJobConfig - cfg.NetworkTopology.Probe.SyncCount = 0 + cfg.NetworkTopology.Probe.Count = 0 }, expect: func(t *testing.T, err error) { assert := assert.New(t) - assert.EqualError(err, "probe requires parameter syncCount") + assert.EqualError(err, "probe requires parameter count") }, }, { diff --git a/scheduler/config/constants.go b/scheduler/config/constants.go index 9ee8813d6..c1c5054ea 100644 --- a/scheduler/config/constants.go +++ b/scheduler/config/constants.go @@ -163,20 +163,17 @@ const ( ) const ( - // TODO(fcgxz2003): The default setting needs to be changed after testing. // DefaultNetworkTopologyCollectInterval is the default interval of collecting network topology. - DefaultNetworkTopologyCollectInterval = 60 * time.Second + DefaultNetworkTopologyCollectInterval = 2 * time.Hour - // DefaultProbeQueueLength is the default length of probe queue in directed graph. + // DefaultProbeQueueLength is the default length of probe queue. DefaultProbeQueueLength = 5 - // TODO(fcgxz2003): The default setting needs to be changed after testing. - // DefaultProbeSyncInterval is the default interval of synchronizing host's probes. - DefaultProbeSyncInterval = 30 * time.Second + // DefaultProbeInterval is the default interval of probing host. + DefaultProbeInterval = 15 * time.Minute - // TODO(fcgxz2003): The default setting needs to be changed after testing. - // DefaultProbeSyncCount is the default number of probing hosts. - DefaultProbeSyncCount = 10 + // DefaultProbeCount is the default number of probing hosts. + DefaultProbeCount = 10 ) const ( diff --git a/scheduler/config/testdata/scheduler.yaml b/scheduler/config/testdata/scheduler.yaml index 0fa376d17..8fccb4802 100644 --- a/scheduler/config/testdata/scheduler.yaml +++ b/scheduler/config/testdata/scheduler.yaml @@ -87,8 +87,8 @@ networkTopology: collectInterval: 60s probe: queueLength: 5 - syncInterval: 30s - syncCount: 10 + interval: 30s + count: 10 trainer: enable: false