feat: optimize network topology comment (#2415)
Signed-off-by: Gaius <gaius.qi@gmail.com>
This commit is contained in:
parent
5bc465f7d8
commit
989f658544
|
|
@ -35,18 +35,18 @@ func (m *MockNetworkTopology) EXPECT() *MockNetworkTopologyMockRecorder {
|
|||
return m.recorder
|
||||
}
|
||||
|
||||
// Delete mocks base method.
|
||||
func (m *MockNetworkTopology) Delete(arg0, arg1 string) error {
|
||||
// DeleteHost mocks base method.
|
||||
func (m *MockNetworkTopology) DeleteHost(arg0 string) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Delete", arg0, arg1)
|
||||
ret := m.ctrl.Call(m, "DeleteHost", arg0)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// Delete indicates an expected call of Delete.
|
||||
func (mr *MockNetworkTopologyMockRecorder) Delete(arg0, arg1 interface{}) *gomock.Call {
|
||||
// DeleteHost indicates an expected call of DeleteHost.
|
||||
func (mr *MockNetworkTopologyMockRecorder) DeleteHost(arg0 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Delete", reflect.TypeOf((*MockNetworkTopology)(nil).Delete), arg0, arg1)
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteHost", reflect.TypeOf((*MockNetworkTopology)(nil).DeleteHost), arg0)
|
||||
}
|
||||
|
||||
// Has mocks base method.
|
||||
|
|
|
|||
|
|
@ -38,13 +38,13 @@ const (
|
|||
|
||||
// NetworkTopology is an interface for network topology.
|
||||
type NetworkTopology interface {
|
||||
// Has checks whether src host and destination host exist.
|
||||
// Has to check if there is a connection between source host and destination host.
|
||||
Has(string, string) bool
|
||||
|
||||
// Store stores src host and destination host.
|
||||
// Store stores source host and destination host.
|
||||
Store(string, string) error
|
||||
|
||||
// DeleteHost deletes src host and destination hosts of the src host.
|
||||
// DeleteHost deletes source host and all destination host connected to source host.
|
||||
DeleteHost(string) error
|
||||
|
||||
// Probes loads probes interface by source host id and destination host id.
|
||||
|
|
@ -53,7 +53,7 @@ type NetworkTopology interface {
|
|||
// ProbedCount is the number of times the host has been probed.
|
||||
ProbedCount(string) (uint64, error)
|
||||
|
||||
// ProbedAt is the time of the last probe.
|
||||
// ProbedAt is the time when the host was last probed.
|
||||
ProbedAt(string) (time.Time, error)
|
||||
}
|
||||
|
||||
|
|
@ -82,7 +82,7 @@ func NewNetworkTopology(cfg config.NetworkTopologyConfig, rdb redis.UniversalCli
|
|||
}, nil
|
||||
}
|
||||
|
||||
// Has checks whether network topology between src host and destination host exists.
|
||||
// Has to check if there is a connection between source host and destination host.
|
||||
func (nt *networkTopology) Has(srcHostID string, destHostID string) bool {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), contextTimeout)
|
||||
defer cancel()
|
||||
|
|
@ -96,7 +96,7 @@ func (nt *networkTopology) Has(srcHostID string, destHostID string) bool {
|
|||
return networkTopologyCount == 1
|
||||
}
|
||||
|
||||
// Store stores network topology between src host and destination host.
|
||||
// Store stores source host and destination host.
|
||||
func (nt *networkTopology) Store(srcHostID string, destHostID string) error {
|
||||
// If the network topology already exists, skip it.
|
||||
if nt.Has(srcHostID, destHostID) {
|
||||
|
|
@ -117,7 +117,7 @@ func (nt *networkTopology) Store(srcHostID string, destHostID string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// DeleteHost deletes host.
|
||||
// DeleteHost deletes source host and all destination host connected to source host.
|
||||
func (nt *networkTopology) DeleteHost(hostID string) error {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), contextTimeout)
|
||||
defer cancel()
|
||||
|
|
@ -153,7 +153,7 @@ func (nt *networkTopology) ProbedAt(hostID string) (time.Time, error) {
|
|||
return nt.rdb.Get(ctx, pkgredis.MakeProbedAtKeyInScheduler(hostID)).Time()
|
||||
}
|
||||
|
||||
// Probes loads probes interface by source host id and destination host id.
|
||||
// ProbedAt is the time when the host was last probed.
|
||||
func (nt *networkTopology) Probes(srcHostID, destHostID string) Probes {
|
||||
return NewProbes(nt.config.Probe, nt.rdb, srcHostID, destHostID)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,143 +26,12 @@ import (
|
|||
"github.com/go-redis/redismock/v8"
|
||||
"github.com/golang/mock/gomock"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"go.uber.org/atomic"
|
||||
|
||||
"d7y.io/dragonfly/v2/pkg/idgen"
|
||||
pkgredis "d7y.io/dragonfly/v2/pkg/redis"
|
||||
"d7y.io/dragonfly/v2/pkg/types"
|
||||
"d7y.io/dragonfly/v2/scheduler/config"
|
||||
"d7y.io/dragonfly/v2/scheduler/resource"
|
||||
storagemocks "d7y.io/dragonfly/v2/scheduler/storage/mocks"
|
||||
)
|
||||
|
||||
var (
|
||||
mockHost = &resource.Host{
|
||||
ID: idgen.HostIDV2("127.0.0.1", "HostName"),
|
||||
Type: types.HostTypeNormal,
|
||||
Hostname: "hostname",
|
||||
IP: "127.0.0.1",
|
||||
Port: 8003,
|
||||
DownloadPort: 8001,
|
||||
OS: "darwin",
|
||||
Platform: "darwin",
|
||||
PlatformFamily: "Standalone Workstation",
|
||||
PlatformVersion: "11.1",
|
||||
KernelVersion: "20.2.0",
|
||||
ConcurrentUploadLimit: atomic.NewInt32(int32(300)),
|
||||
ConcurrentUploadCount: atomic.NewInt32(0),
|
||||
UploadCount: atomic.NewInt64(0),
|
||||
UploadFailedCount: atomic.NewInt64(0),
|
||||
CPU: mockCPU,
|
||||
Memory: mockMemory,
|
||||
Network: mockNetwork,
|
||||
Disk: mockDisk,
|
||||
Build: mockBuild,
|
||||
CreatedAt: atomic.NewTime(time.Now()),
|
||||
UpdatedAt: atomic.NewTime(time.Now()),
|
||||
}
|
||||
|
||||
mockSeedHost = &resource.Host{
|
||||
ID: idgen.HostIDV2("127.0.0.1", "HostName_seed"),
|
||||
Type: types.HostTypeSuperSeed,
|
||||
Hostname: "hostname_seed",
|
||||
IP: "127.0.0.1",
|
||||
Port: 8003,
|
||||
DownloadPort: 8001,
|
||||
OS: "darwin",
|
||||
Platform: "darwin",
|
||||
PlatformFamily: "Standalone Workstation",
|
||||
PlatformVersion: "11.1",
|
||||
KernelVersion: "20.2.0",
|
||||
ConcurrentUploadLimit: atomic.NewInt32(int32(300)),
|
||||
ConcurrentUploadCount: atomic.NewInt32(0),
|
||||
UploadCount: atomic.NewInt64(0),
|
||||
UploadFailedCount: atomic.NewInt64(0),
|
||||
CPU: mockCPU,
|
||||
Memory: mockMemory,
|
||||
Network: mockNetwork,
|
||||
Disk: mockDisk,
|
||||
Build: mockBuild,
|
||||
CreatedAt: atomic.NewTime(time.Now()),
|
||||
UpdatedAt: atomic.NewTime(time.Now()),
|
||||
}
|
||||
|
||||
mockCPU = resource.CPU{
|
||||
LogicalCount: 4,
|
||||
PhysicalCount: 2,
|
||||
Percent: 1,
|
||||
ProcessPercent: 0.5,
|
||||
Times: resource.CPUTimes{
|
||||
User: 240662.2,
|
||||
System: 317950.1,
|
||||
Idle: 3393691.3,
|
||||
Nice: 0,
|
||||
Iowait: 0,
|
||||
Irq: 0,
|
||||
Softirq: 0,
|
||||
Steal: 0,
|
||||
Guest: 0,
|
||||
GuestNice: 0,
|
||||
},
|
||||
}
|
||||
|
||||
mockMemory = resource.Memory{
|
||||
Total: 17179869184,
|
||||
Available: 5962813440,
|
||||
Used: 11217055744,
|
||||
UsedPercent: 65.291858,
|
||||
ProcessUsedPercent: 41.525125,
|
||||
Free: 2749598908,
|
||||
}
|
||||
|
||||
mockNetwork = resource.Network{
|
||||
TCPConnectionCount: 10,
|
||||
UploadTCPConnectionCount: 1,
|
||||
Location: mockHostLocation,
|
||||
IDC: mockHostIDC,
|
||||
}
|
||||
|
||||
mockDisk = resource.Disk{
|
||||
Total: 499963174912,
|
||||
Free: 37226479616,
|
||||
Used: 423809622016,
|
||||
UsedPercent: 91.92547406065952,
|
||||
InodesTotal: 4882452880,
|
||||
InodesUsed: 7835772,
|
||||
InodesFree: 4874617108,
|
||||
InodesUsedPercent: 0.1604884305611568,
|
||||
}
|
||||
|
||||
mockBuild = resource.Build{
|
||||
GitVersion: "v1.0.0",
|
||||
GitCommit: "221176b117c6d59366d68f2b34d38be50c935883",
|
||||
GoVersion: "1.18",
|
||||
Platform: "darwin",
|
||||
}
|
||||
|
||||
mockHostLocation = "location"
|
||||
mockHostIDC = "idc"
|
||||
|
||||
mockProbe = &Probe{
|
||||
Host: mockHost,
|
||||
RTT: 30 * time.Millisecond,
|
||||
CreatedAt: time.Now(),
|
||||
}
|
||||
|
||||
mockNetworkTopologyConfig = config.NetworkTopologyConfig{
|
||||
Enable: true,
|
||||
CollectInterval: 2 * time.Hour,
|
||||
Probe: config.ProbeConfig{
|
||||
QueueLength: 5,
|
||||
Interval: 15 * time.Minute,
|
||||
Count: 10,
|
||||
},
|
||||
}
|
||||
|
||||
mockProbesCreatedAt = time.Now()
|
||||
mockProbedCount = 10
|
||||
)
|
||||
|
||||
func Test_NewNetworkTopology(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
|
|
|
|||
|
|
@ -26,8 +26,140 @@ import (
|
|||
"github.com/go-redis/redismock/v8"
|
||||
"github.com/golang/mock/gomock"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"go.uber.org/atomic"
|
||||
|
||||
"d7y.io/dragonfly/v2/pkg/idgen"
|
||||
pkgredis "d7y.io/dragonfly/v2/pkg/redis"
|
||||
"d7y.io/dragonfly/v2/pkg/types"
|
||||
"d7y.io/dragonfly/v2/scheduler/config"
|
||||
"d7y.io/dragonfly/v2/scheduler/resource"
|
||||
)
|
||||
|
||||
var (
|
||||
mockHost = &resource.Host{
|
||||
ID: idgen.HostIDV2("127.0.0.1", "hostname"),
|
||||
Type: types.HostTypeNormal,
|
||||
Hostname: "hostname",
|
||||
IP: "127.0.0.1",
|
||||
Port: 8003,
|
||||
DownloadPort: 8001,
|
||||
OS: "darwin",
|
||||
Platform: "darwin",
|
||||
PlatformFamily: "Standalone Workstation",
|
||||
PlatformVersion: "11.1",
|
||||
KernelVersion: "20.2.0",
|
||||
ConcurrentUploadLimit: atomic.NewInt32(int32(300)),
|
||||
ConcurrentUploadCount: atomic.NewInt32(0),
|
||||
UploadCount: atomic.NewInt64(0),
|
||||
UploadFailedCount: atomic.NewInt64(0),
|
||||
CPU: mockCPU,
|
||||
Memory: mockMemory,
|
||||
Network: mockNetwork,
|
||||
Disk: mockDisk,
|
||||
Build: mockBuild,
|
||||
CreatedAt: atomic.NewTime(time.Now()),
|
||||
UpdatedAt: atomic.NewTime(time.Now()),
|
||||
}
|
||||
|
||||
mockSeedHost = &resource.Host{
|
||||
ID: idgen.HostIDV2("127.0.0.1", "hostname_seed"),
|
||||
Type: types.HostTypeSuperSeed,
|
||||
Hostname: "hostname_seed",
|
||||
IP: "127.0.0.1",
|
||||
Port: 8003,
|
||||
DownloadPort: 8001,
|
||||
OS: "darwin",
|
||||
Platform: "darwin",
|
||||
PlatformFamily: "Standalone Workstation",
|
||||
PlatformVersion: "11.1",
|
||||
KernelVersion: "20.2.0",
|
||||
ConcurrentUploadLimit: atomic.NewInt32(int32(300)),
|
||||
ConcurrentUploadCount: atomic.NewInt32(0),
|
||||
UploadCount: atomic.NewInt64(0),
|
||||
UploadFailedCount: atomic.NewInt64(0),
|
||||
CPU: mockCPU,
|
||||
Memory: mockMemory,
|
||||
Network: mockNetwork,
|
||||
Disk: mockDisk,
|
||||
Build: mockBuild,
|
||||
CreatedAt: atomic.NewTime(time.Now()),
|
||||
UpdatedAt: atomic.NewTime(time.Now()),
|
||||
}
|
||||
|
||||
mockCPU = resource.CPU{
|
||||
LogicalCount: 4,
|
||||
PhysicalCount: 2,
|
||||
Percent: 1,
|
||||
ProcessPercent: 0.5,
|
||||
Times: resource.CPUTimes{
|
||||
User: 240662.2,
|
||||
System: 317950.1,
|
||||
Idle: 3393691.3,
|
||||
Nice: 0,
|
||||
Iowait: 0,
|
||||
Irq: 0,
|
||||
Softirq: 0,
|
||||
Steal: 0,
|
||||
Guest: 0,
|
||||
GuestNice: 0,
|
||||
},
|
||||
}
|
||||
|
||||
mockMemory = resource.Memory{
|
||||
Total: 17179869184,
|
||||
Available: 5962813440,
|
||||
Used: 11217055744,
|
||||
UsedPercent: 65.291858,
|
||||
ProcessUsedPercent: 41.525125,
|
||||
Free: 2749598908,
|
||||
}
|
||||
|
||||
mockNetwork = resource.Network{
|
||||
TCPConnectionCount: 10,
|
||||
UploadTCPConnectionCount: 1,
|
||||
Location: mockHostLocation,
|
||||
IDC: mockHostIDC,
|
||||
}
|
||||
|
||||
mockDisk = resource.Disk{
|
||||
Total: 499963174912,
|
||||
Free: 37226479616,
|
||||
Used: 423809622016,
|
||||
UsedPercent: 91.92547406065952,
|
||||
InodesTotal: 4882452880,
|
||||
InodesUsed: 7835772,
|
||||
InodesFree: 4874617108,
|
||||
InodesUsedPercent: 0.1604884305611568,
|
||||
}
|
||||
|
||||
mockBuild = resource.Build{
|
||||
GitVersion: "v1.0.0",
|
||||
GitCommit: "221176b117c6d59366d68f2b34d38be50c935883",
|
||||
GoVersion: "1.18",
|
||||
Platform: "darwin",
|
||||
}
|
||||
|
||||
mockHostLocation = "location"
|
||||
mockHostIDC = "idc"
|
||||
|
||||
mockProbe = &Probe{
|
||||
Host: mockHost,
|
||||
RTT: 30 * time.Millisecond,
|
||||
CreatedAt: time.Now(),
|
||||
}
|
||||
|
||||
mockNetworkTopologyConfig = config.NetworkTopologyConfig{
|
||||
Enable: true,
|
||||
CollectInterval: 2 * time.Hour,
|
||||
Probe: config.ProbeConfig{
|
||||
QueueLength: 5,
|
||||
Interval: 15 * time.Minute,
|
||||
Count: 10,
|
||||
},
|
||||
}
|
||||
|
||||
mockProbesCreatedAt = time.Now()
|
||||
mockProbedCount = 10
|
||||
)
|
||||
|
||||
func Test_NewProbes(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue