From 8a8d6abaae313e37c5a7a7ce40b2bd88f6cce09c Mon Sep 17 00:00:00 2001 From: dlut_xz <52518280+fcgxz2003@users.noreply.github.com> Date: Fri, 16 Jun 2023 14:27:46 +0800 Subject: [PATCH] feat: move probe interval from scheduler config to client config (#2462) Signed-off-by: XZ <834756128@qq.com> --- client/config/constants.go | 5 +++ client/config/peerhost.go | 44 ++++++++++++++++------- client/config/peerhost_darwin.go | 6 ++++ client/config/peerhost_linux.go | 6 ++++ client/config/peerhost_test.go | 24 +++++++++++++ client/config/testdata/config/daemon.yaml | 5 +++ scheduler/config/config.go | 8 ----- scheduler/config/config_test.go | 15 -------- scheduler/config/constants.go | 3 -- scheduler/config/testdata/scheduler.yaml | 1 - scheduler/networktopology/probes_test.go | 1 - scheduler/service/service_v1_test.go | 1 - 12 files changed, 78 insertions(+), 41 deletions(-) diff --git a/client/config/constants.go b/client/config/constants.go index 2c467f3f9..4ad3074ce 100644 --- a/client/config/constants.go +++ b/client/config/constants.go @@ -111,3 +111,8 @@ var ( // DefaultAnnouncerSchedulerInterval is default interface of announcing scheduler. DefaultAnnouncerSchedulerInterval = 30 * time.Second ) + +const ( + // DefaultProbeInterval is the default interval of probing host. + DefaultProbeInterval = 20 * time.Minute +) diff --git a/client/config/peerhost.go b/client/config/peerhost.go index 82b7e69b3..a72b397aa 100644 --- a/client/config/peerhost.go +++ b/client/config/peerhost.go @@ -62,18 +62,19 @@ type DaemonOption struct { DataDirMode uint32 `mapstructure:"dataDirMode" yaml:"dataDirMode"` KeepStorage bool `mapstructure:"keepStorage" yaml:"keepStorage"` - Security GlobalSecurityOption `mapstructure:"security" yaml:"security"` - Scheduler SchedulerOption `mapstructure:"scheduler" yaml:"scheduler"` - Host HostOption `mapstructure:"host" yaml:"host"` - Download DownloadOption `mapstructure:"download" yaml:"download"` - Proxy *ProxyOption `mapstructure:"proxy" yaml:"proxy"` - Upload UploadOption `mapstructure:"upload" yaml:"upload"` - ObjectStorage ObjectStorageOption `mapstructure:"objectStorage" yaml:"objectStorage"` - Storage StorageOption `mapstructure:"storage" yaml:"storage"` - Health *HealthOption `mapstructure:"health" yaml:"health"` - Reload ReloadOption `mapstructure:"reload" yaml:"reload"` - Network *NetworkOption `mapstructure:"network" yaml:"network"` - Announcer AnnouncerOption `mapstructure:"announcer" yaml:"announcer"` + Security GlobalSecurityOption `mapstructure:"security" yaml:"security"` + Scheduler SchedulerOption `mapstructure:"scheduler" yaml:"scheduler"` + Host HostOption `mapstructure:"host" yaml:"host"` + Download DownloadOption `mapstructure:"download" yaml:"download"` + Proxy *ProxyOption `mapstructure:"proxy" yaml:"proxy"` + Upload UploadOption `mapstructure:"upload" yaml:"upload"` + ObjectStorage ObjectStorageOption `mapstructure:"objectStorage" yaml:"objectStorage"` + Storage StorageOption `mapstructure:"storage" yaml:"storage"` + Health *HealthOption `mapstructure:"health" yaml:"health"` + Reload ReloadOption `mapstructure:"reload" yaml:"reload"` + Network *NetworkOption `mapstructure:"network" yaml:"network"` + Announcer AnnouncerOption `mapstructure:"announcer" yaml:"announcer"` + NetworkTopology NetworkTopologyOption `mapstructure:"networkTopology" yaml:"networkTopology"` } func NewDaemonConfig() *DaemonOption { @@ -216,6 +217,12 @@ func (p *DaemonOption) Validate() error { } } + if p.NetworkTopology.Enable { + if p.NetworkTopology.Probe.Interval <= 0 { + return errors.New("probe requires parameter interval") + } + } + return nil } @@ -938,3 +945,16 @@ type AnnouncerOption struct { // SchedulerInterval is the interval of announcing scheduler. SchedulerInterval time.Duration `mapstructure:"schedulerInterval" yaml:"schedulerInterval"` } + +type NetworkTopologyOption struct { + // Enable network topology service. + Enable bool `mapstructure:"enable" yaml:"enable"` + + // Probe is the configuration of probe. + Probe ProbeOption `mapstructure:"probe" yaml:"probe"` +} + +type ProbeOption struct { + // Interval is the interval of probing hosts. + Interval time.Duration `mapstructure:"interval" yaml:"interval"` +} diff --git a/client/config/peerhost_darwin.go b/client/config/peerhost_darwin.go index ae2abbd61..7938cc8e3 100644 --- a/client/config/peerhost_darwin.go +++ b/client/config/peerhost_darwin.go @@ -179,5 +179,11 @@ var peerHostConfig = func() *DaemonOption { Announcer: AnnouncerOption{ SchedulerInterval: DefaultAnnouncerSchedulerInterval, }, + NetworkTopology: NetworkTopologyOption{ + Enable: false, + Probe: ProbeOption{ + Interval: DefaultProbeInterval, + }, + }, } } diff --git a/client/config/peerhost_linux.go b/client/config/peerhost_linux.go index 11285a543..2ff73d14b 100644 --- a/client/config/peerhost_linux.go +++ b/client/config/peerhost_linux.go @@ -179,5 +179,11 @@ var peerHostConfig = func() *DaemonOption { Announcer: AnnouncerOption{ SchedulerInterval: DefaultAnnouncerSchedulerInterval, }, + NetworkTopology: NetworkTopologyOption{ + Enable: false, + Probe: ProbeOption{ + Interval: DefaultProbeInterval, + }, + }, } } diff --git a/client/config/peerhost_test.go b/client/config/peerhost_test.go index 7ea5b1cb0..e184438e1 100644 --- a/client/config/peerhost_test.go +++ b/client/config/peerhost_test.go @@ -515,6 +515,12 @@ func TestPeerHostOption_Load(t *testing.T) { Announcer: AnnouncerOption{ SchedulerInterval: 1000000000, }, + NetworkTopology: NetworkTopologyOption{ + Enable: true, + Probe: ProbeOption{ + Interval: 20 * time.Minute, + }, + }, } peerHostOptionYAML := &DaemonOption{} @@ -754,6 +760,24 @@ func TestPeerHostOption_Validate(t *testing.T) { assert.EqualError(err, "certSpec requires parameter validityPeriod") }, }, + { + name: "probe requires parameter interval", + config: NewDaemonConfig(), + mock: func(cfg *DaemonConfig) { + cfg.Scheduler.NetAddrs = []dfnet.NetAddr{ + { + Type: dfnet.TCP, + Addr: "127.0.0.1:8002", + }, + } + cfg.NetworkTopology.Enable = true + cfg.NetworkTopology.Probe.Interval = 0 + }, + expect: func(t *testing.T, err error) { + assert := assert.New(t) + assert.EqualError(err, "probe requires parameter interval") + }, + }, } for _, tc := range tests { diff --git a/client/config/testdata/config/daemon.yaml b/client/config/testdata/config/daemon.yaml index 5034101f7..9ad880b70 100644 --- a/client/config/testdata/config/daemon.yaml +++ b/client/config/testdata/config/daemon.yaml @@ -189,3 +189,8 @@ network: announcer: schedulerInterval: 1s + +networkTopology: + enable: true + probe: + interval: 20m diff --git a/scheduler/config/config.go b/scheduler/config/config.go index d50e43690..860a1f0da 100644 --- a/scheduler/config/config.go +++ b/scheduler/config/config.go @@ -312,9 +312,6 @@ type ProbeConfig struct { // QueueLength is the length of probe queue. QueueLength int `mapstructure:"queueLength" yaml:"queueLength"` - // Interval is the interval of probing hosts. - Interval time.Duration `mapstructure:"interval" yaml:"interval"` - // Count is the number of probing hosts. Count int `mapstructure:"count" yaml:"count"` } @@ -410,7 +407,6 @@ func New() *Config { CollectInterval: DefaultNetworkTopologyCollectInterval, Probe: ProbeConfig{ QueueLength: DefaultProbeQueueLength, - Interval: DefaultProbeInterval, Count: DefaultProbeCount, }, }, @@ -579,10 +575,6 @@ func (cfg *Config) Validate() error { return errors.New("probe requires parameter queueLength") } - if cfg.NetworkTopology.Probe.Interval <= 0 { - return errors.New("probe requires parameter interval") - } - if cfg.NetworkTopology.Probe.Count <= 0 { return errors.New("probe requires parameter count") } diff --git a/scheduler/config/config_test.go b/scheduler/config/config_test.go index 873a59706..cd470017d 100644 --- a/scheduler/config/config_test.go +++ b/scheduler/config/config_test.go @@ -165,7 +165,6 @@ func TestConfig_Load(t *testing.T) { CollectInterval: 60 * time.Second, Probe: ProbeConfig{ QueueLength: 5, - Interval: 30 * time.Second, Count: 10, }, }, @@ -710,20 +709,6 @@ func TestConfig_Validate(t *testing.T) { assert.EqualError(err, "probe requires parameter queueLength") }, }, - { - name: "probe requires parameter interval", - config: New(), - mock: func(cfg *Config) { - cfg.Manager = mockManagerConfig - cfg.Database.Redis = mockRedisConfig - cfg.Job = mockJobConfig - cfg.NetworkTopology.Probe.Interval = 0 - }, - expect: func(t *testing.T, err error) { - assert := assert.New(t) - assert.EqualError(err, "probe requires parameter interval") - }, - }, { name: "probe requires parameter count", config: New(), diff --git a/scheduler/config/constants.go b/scheduler/config/constants.go index 55b034126..f452e1321 100644 --- a/scheduler/config/constants.go +++ b/scheduler/config/constants.go @@ -169,9 +169,6 @@ const ( // DefaultProbeQueueLength is the default length of probe queue. DefaultProbeQueueLength = 5 - // DefaultProbeInterval is the default interval of probing host. - DefaultProbeInterval = 20 * time.Minute - // DefaultProbeCount is the default number of probing hosts. DefaultProbeCount = 5 ) diff --git a/scheduler/config/testdata/scheduler.yaml b/scheduler/config/testdata/scheduler.yaml index 8fccb4802..3053bbbd8 100644 --- a/scheduler/config/testdata/scheduler.yaml +++ b/scheduler/config/testdata/scheduler.yaml @@ -87,7 +87,6 @@ networkTopology: collectInterval: 60s probe: queueLength: 5 - interval: 30s count: 10 trainer: diff --git a/scheduler/networktopology/probes_test.go b/scheduler/networktopology/probes_test.go index 24fea3fab..ed0f65c63 100644 --- a/scheduler/networktopology/probes_test.go +++ b/scheduler/networktopology/probes_test.go @@ -154,7 +154,6 @@ var ( CollectInterval: 2 * time.Hour, Probe: config.ProbeConfig{ QueueLength: 5, - Interval: 15 * time.Minute, Count: 10, }, } diff --git a/scheduler/service/service_v1_test.go b/scheduler/service/service_v1_test.go index da79afb74..032ad43ba 100644 --- a/scheduler/service/service_v1_test.go +++ b/scheduler/service/service_v1_test.go @@ -79,7 +79,6 @@ var ( CollectInterval: 2 * time.Hour, Probe: config.ProbeConfig{ QueueLength: 5, - Interval: 15 * time.Minute, Count: 10, }, }