diff --git a/pkg/redis/redis.go b/pkg/redis/redis.go index ed2f6f7da37..f01ad3bfd7f 100644 --- a/pkg/redis/redis.go +++ b/pkg/redis/redis.go @@ -55,9 +55,6 @@ const ( // ProbedCountNamespace prefix of probed count namespace cache key. ProbedCountNamespace = "probed-count" - - // ProbedAtNamespace prefix of last probed time namespace cache key. - ProbedAtNamespace = "probed-at" ) // NewRedis returns a new redis client. @@ -167,8 +164,3 @@ func ParseProbedCountKeyInScheduler(key string) (string, string, string, error) func MakeProbedCountKeyInScheduler(hostID string) string { return MakeKeyInScheduler(ProbedCountNamespace, hostID) } - -// MakeProbedAtKeyInScheduler make last probed time in scheduler. -func MakeProbedAtKeyInScheduler(hostID string) string { - return MakeKeyInScheduler(ProbedAtNamespace, hostID) -} diff --git a/pkg/redis/redis_test.go b/pkg/redis/redis_test.go index 33bb2396723..b6833e71e83 100644 --- a/pkg/redis/redis_test.go +++ b/pkg/redis/redis_test.go @@ -669,33 +669,3 @@ func Test_ParseProbedCountKeyInScheduler(t *testing.T) { }) } } - -func Test_MakeProbedAtKeyInScheduler(t *testing.T) { - tests := []struct { - name string - hostID string - expect func(t *testing.T, s string) - }{ - { - name: "make probed at key in scheduler", - hostID: "bas", - expect: func(t *testing.T, s string) { - assert := assert.New(t) - assert.Equal("scheduler:probed-at:bas", s) - }, - }, - { - name: "host id is empty", - hostID: "", - expect: func(t *testing.T, s string) { - assert := assert.New(t) - assert.Equal("scheduler:probed-at:", s) - }, - }, - } - for _, tc := range tests { - t.Run(tc.name, func(t *testing.T) { - tc.expect(t, MakeProbedAtKeyInScheduler(tc.hostID)) - }) - } -} diff --git a/scheduler/networktopology/mocks/network_topology_mock.go b/scheduler/networktopology/mocks/network_topology_mock.go index 841b637dc1e..97dce985026 100644 --- a/scheduler/networktopology/mocks/network_topology_mock.go +++ b/scheduler/networktopology/mocks/network_topology_mock.go @@ -6,7 +6,6 @@ package mocks import ( reflect "reflect" - time "time" networktopology "d7y.io/dragonfly/v2/scheduler/networktopology" resource "d7y.io/dragonfly/v2/scheduler/resource" @@ -79,21 +78,6 @@ func (mr *MockNetworkTopologyMockRecorder) Has(arg0, arg1 interface{}) *gomock.C return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Has", reflect.TypeOf((*MockNetworkTopology)(nil).Has), arg0, arg1) } -// ProbedAt mocks base method. -func (m *MockNetworkTopology) ProbedAt(arg0 string) (time.Time, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ProbedAt", arg0) - ret0, _ := ret[0].(time.Time) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// ProbedAt indicates an expected call of ProbedAt. -func (mr *MockNetworkTopologyMockRecorder) ProbedAt(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ProbedAt", reflect.TypeOf((*MockNetworkTopology)(nil).ProbedAt), arg0) -} - // ProbedCount mocks base method. func (m *MockNetworkTopology) ProbedCount(arg0 string) (uint64, error) { m.ctrl.T.Helper() diff --git a/scheduler/networktopology/network_topology.go b/scheduler/networktopology/network_topology.go index 743aa370394..d20581ba38d 100644 --- a/scheduler/networktopology/network_topology.go +++ b/scheduler/networktopology/network_topology.go @@ -74,9 +74,6 @@ type NetworkTopology interface { // ProbedCount is the number of times the host has been probed. ProbedCount(string) (uint64, error) - // ProbedAt is the time when the host was last probed. - ProbedAt(string) (time.Time, error) - // Snapshot writes the current network topology to the storage. Snapshot() error } @@ -218,7 +215,7 @@ func (nt *networkTopology) DeleteHost(hostID string) error { ctx, cancel := context.WithTimeout(context.Background(), contextTimeout) defer cancel() - deleteKeys := []string{pkgredis.MakeProbedAtKeyInScheduler(hostID), pkgredis.MakeProbedCountKeyInScheduler(hostID)} + deleteKeys := []string{pkgredis.MakeProbedCountKeyInScheduler(hostID)} srcNetworkTopologyKeys, _, err := nt.rdb.Scan(ctx, 0, pkgredis.MakeNetworkTopologyKeyInScheduler(hostID, "*"), math.MaxInt64).Result() if err != nil { return err @@ -263,14 +260,6 @@ func (nt *networkTopology) ProbedCount(hostID string) (uint64, error) { return nt.rdb.Get(ctx, pkgredis.MakeProbedCountKeyInScheduler(hostID)).Uint64() } -// ProbedAt is the time when the host was last probed. -func (nt *networkTopology) ProbedAt(hostID string) (time.Time, error) { - ctx, cancel := context.WithTimeout(context.Background(), contextTimeout) - defer cancel() - - return nt.rdb.Get(ctx, pkgredis.MakeProbedAtKeyInScheduler(hostID)).Time() -} - // Snapshot writes the current network topology to the storage. func (nt *networkTopology) Snapshot() error { ctx, cancel := context.WithTimeout(context.Background(), snapshotContextTimeout) diff --git a/scheduler/networktopology/network_topology_test.go b/scheduler/networktopology/network_topology_test.go index a5279fc2cef..2bbda4560db 100644 --- a/scheduler/networktopology/network_topology_test.go +++ b/scheduler/networktopology/network_topology_test.go @@ -481,16 +481,15 @@ func TestNetworkTopology_DeleteHost(t *testing.T) { }{ { name: "delete host", - deleteKeys: []string{pkgredis.MakeProbedAtKeyInScheduler(mockHost.ID), - pkgredis.MakeProbedCountKeyInScheduler(mockHost.ID), + deleteKeys: []string{pkgredis.MakeProbedCountKeyInScheduler(mockHost.ID), pkgredis.MakeNetworkTopologyKeyInScheduler(mockSeedHost.ID, mockHost.ID), pkgredis.MakeProbesKeyInScheduler(mockSeedHost.ID, mockHost.ID)}, mock: func(mockRDBClient redismock.ClientMock, keys []string) { mockRDBClient.MatchExpectationsInOrder(true) mockRDBClient.ExpectScan(0, pkgredis.MakeNetworkTopologyKeyInScheduler(mockHost.ID, "*"), math.MaxInt64).SetVal([]string{}, 0) - mockRDBClient.ExpectScan(0, pkgredis.MakeNetworkTopologyKeyInScheduler("*", mockHost.ID), math.MaxInt64).SetVal([]string{keys[2]}, 0) + mockRDBClient.ExpectScan(0, pkgredis.MakeNetworkTopologyKeyInScheduler("*", mockHost.ID), math.MaxInt64).SetVal([]string{keys[1]}, 0) mockRDBClient.ExpectScan(0, pkgredis.MakeProbesKeyInScheduler(mockHost.ID, "*"), math.MaxInt64).SetVal([]string{}, 0) - mockRDBClient.ExpectScan(0, pkgredis.MakeProbesKeyInScheduler("*", mockHost.ID), math.MaxInt64).SetVal([]string{keys[3]}, 0) + mockRDBClient.ExpectScan(0, pkgredis.MakeProbesKeyInScheduler("*", mockHost.ID), math.MaxInt64).SetVal([]string{keys[2]}, 0) mockRDBClient.ExpectDel(keys...).SetVal(4) }, expect: func(t *testing.T, networkTopology NetworkTopology, err error) { @@ -561,16 +560,15 @@ func TestNetworkTopology_DeleteHost(t *testing.T) { }, { name: "delete network topology and probes error", - deleteKeys: []string{pkgredis.MakeProbedAtKeyInScheduler(mockHost.ID), - pkgredis.MakeProbedCountKeyInScheduler(mockHost.ID), + deleteKeys: []string{pkgredis.MakeProbedCountKeyInScheduler(mockHost.ID), pkgredis.MakeNetworkTopologyKeyInScheduler(mockSeedHost.ID, mockHost.ID), pkgredis.MakeProbesKeyInScheduler(mockSeedHost.ID, mockHost.ID)}, mock: func(mockRDBClient redismock.ClientMock, keys []string) { mockRDBClient.MatchExpectationsInOrder(true) mockRDBClient.ExpectScan(0, pkgredis.MakeNetworkTopologyKeyInScheduler(mockHost.ID, "*"), math.MaxInt64).SetVal([]string{}, 0) - mockRDBClient.ExpectScan(0, pkgredis.MakeNetworkTopologyKeyInScheduler("*", mockHost.ID), math.MaxInt64).SetVal([]string{keys[2]}, 0) + mockRDBClient.ExpectScan(0, pkgredis.MakeNetworkTopologyKeyInScheduler("*", mockHost.ID), math.MaxInt64).SetVal([]string{keys[1]}, 0) mockRDBClient.ExpectScan(0, pkgredis.MakeProbesKeyInScheduler(mockHost.ID, "*"), math.MaxInt64).SetVal([]string{}, 0) - mockRDBClient.ExpectScan(0, pkgredis.MakeProbesKeyInScheduler("*", mockHost.ID), math.MaxInt64).SetVal([]string{keys[3]}, 0) + mockRDBClient.ExpectScan(0, pkgredis.MakeProbesKeyInScheduler("*", mockHost.ID), math.MaxInt64).SetVal([]string{keys[2]}, 0) mockRDBClient.ExpectDel(keys...).SetErr(errors.New("delete network topology and probes error")) }, expect: func(t *testing.T, networkTopology NetworkTopology, err error) { @@ -686,58 +684,6 @@ func TestNetworkTopology_ProbedCount(t *testing.T) { } } -func TestNetworkTopology_ProbedAt(t *testing.T) { - tests := []struct { - name string - mock func(mockRDBClient redismock.ClientMock) - expect func(t *testing.T, networkTopology NetworkTopology, err error) - }{ - { - name: "get the time when the host was last probed", - mock: func(mockRDBClient redismock.ClientMock) { - mockRDBClient.ExpectGet(pkgredis.MakeProbedAtKeyInScheduler(mockHost.ID)).SetVal(mockProbe.CreatedAt.Format(time.RFC3339Nano)) - }, - expect: func(t *testing.T, networkTopology NetworkTopology, err error) { - assert := assert.New(t) - assert.NoError(err) - - probedAt, err := networkTopology.ProbedAt(mockHost.ID) - assert.NoError(err) - assert.True(mockProbe.CreatedAt.Equal(probedAt)) - }, - }, - { - name: "get the time when the host was last probed error", - mock: func(mockRDBClient redismock.ClientMock) { - mockRDBClient.ExpectGet(pkgredis.MakeProbedAtKeyInScheduler(mockHost.ID)).SetErr(errors.New("get the time when the host was last probed error")) - }, - expect: func(t *testing.T, networkTopology NetworkTopology, err error) { - assert := assert.New(t) - assert.NoError(err) - - _, err = networkTopology.ProbedAt(mockHost.ID) - assert.EqualError(err, "get the time when the host was last probed error") - }, - }, - } - - for _, tc := range tests { - t.Run(tc.name, func(t *testing.T) { - ctl := gomock.NewController(t) - defer ctl.Finish() - - rdb, mockRDBClient := redismock.NewClientMock() - res := resource.NewMockResource(ctl) - storage := storagemocks.NewMockStorage(ctl) - tc.mock(mockRDBClient) - - networkTopology, err := NewNetworkTopology(mockNetworkTopologyConfig, rdb, res, storage) - tc.expect(t, networkTopology, err) - mockRDBClient.ClearExpect() - }) - } -} - func TestNetworkTopology_Snapshot(t *testing.T) { tests := []struct { name string diff --git a/scheduler/networktopology/probes.go b/scheduler/networktopology/probes.go index 2d9e978b464..08e69c77d4d 100644 --- a/scheduler/networktopology/probes.go +++ b/scheduler/networktopology/probes.go @@ -178,10 +178,6 @@ func (p *probes) Enqueue(probe *Probe) error { return err } - if err := p.rdb.Set(ctx, pkgredis.MakeProbedAtKeyInScheduler(p.destHostID), probe.CreatedAt.Format(time.RFC3339Nano), 0).Err(); err != nil { - return err - } - if err := p.rdb.Incr(ctx, pkgredis.MakeProbedCountKeyInScheduler(p.destHostID)).Err(); err != nil { return err } diff --git a/scheduler/networktopology/probes_test.go b/scheduler/networktopology/probes_test.go index ed0f65c6377..005a3dd7bad 100644 --- a/scheduler/networktopology/probes_test.go +++ b/scheduler/networktopology/probes_test.go @@ -262,7 +262,6 @@ func TestProbes_Peek(t *testing.T) { mockRDBClient.ExpectLRange(pkgredis.MakeProbesKeyInScheduler(mockSeedHost.ID, mockHost.ID), 0, -1).SetVal(rawProbes) mockRDBClient.ExpectHSet(pkgredis.MakeNetworkTopologyKeyInScheduler(mockSeedHost.ID, mockHost.ID), "averageRTT", int64(30388900)).SetVal(1) mockRDBClient.ExpectHSet(pkgredis.MakeNetworkTopologyKeyInScheduler(mockSeedHost.ID, mockHost.ID), "updatedAt", mockProbe.CreatedAt.Format(time.RFC3339Nano)).SetVal(1) - mockRDBClient.ExpectSet(pkgredis.MakeProbedAtKeyInScheduler(mockHost.ID), mockProbe.CreatedAt.Format(time.RFC3339Nano), 0).SetVal("ok") mockRDBClient.ExpectIncr(pkgredis.MakeProbedCountKeyInScheduler(mockHost.ID)).SetVal(6) mockRDBClient.ExpectLIndex(pkgredis.MakeProbesKeyInScheduler(mockSeedHost.ID, mockHost.ID), 0).SetVal(rawProbes[0]) }, @@ -341,7 +340,6 @@ func TestProbes_Enqueue(t *testing.T) { mockRDBClient.ExpectRPush(pkgredis.MakeProbesKeyInScheduler(mockSeedHost.ID, mockHost.ID), data).SetVal(1) mockRDBClient.ExpectHSet(pkgredis.MakeNetworkTopologyKeyInScheduler(mockSeedHost.ID, mockHost.ID), "averageRTT", mockProbe.RTT.Nanoseconds()).SetVal(1) mockRDBClient.ExpectHSet(pkgredis.MakeNetworkTopologyKeyInScheduler(mockSeedHost.ID, mockHost.ID), "updatedAt", mockProbe.CreatedAt.Format(time.RFC3339Nano)).SetVal(1) - mockRDBClient.ExpectSet(pkgredis.MakeProbedAtKeyInScheduler(mockHost.ID), mockProbe.CreatedAt.Format(time.RFC3339Nano), 0).SetVal("ok") mockRDBClient.ExpectIncr(pkgredis.MakeProbedCountKeyInScheduler(mockHost.ID)).SetVal(1) }, expect: func(t *testing.T, ps Probes) { @@ -372,7 +370,6 @@ func TestProbes_Enqueue(t *testing.T) { mockRDBClient.ExpectLRange(pkgredis.MakeProbesKeyInScheduler(mockSeedHost.ID, mockHost.ID), 0, -1).SetVal([]string{rawProbes[1], rawProbes[0]}) mockRDBClient.ExpectHSet(pkgredis.MakeNetworkTopologyKeyInScheduler(mockSeedHost.ID, mockHost.ID), "averageRTT", int64(30100000)).SetVal(1) mockRDBClient.ExpectHSet(pkgredis.MakeNetworkTopologyKeyInScheduler(mockSeedHost.ID, mockHost.ID), "updatedAt", mockProbe.CreatedAt.Format(time.RFC3339Nano)).SetVal(1) - mockRDBClient.ExpectSet(pkgredis.MakeProbedAtKeyInScheduler(mockHost.ID), mockProbe.CreatedAt.Format(time.RFC3339Nano), 0).SetVal("ok") mockRDBClient.ExpectIncr(pkgredis.MakeProbedCountKeyInScheduler(mockHost.ID)).SetVal(2) }, expect: func(t *testing.T, ps Probes) { @@ -407,7 +404,6 @@ func TestProbes_Enqueue(t *testing.T) { mockRDBClient.ExpectLRange(pkgredis.MakeProbesKeyInScheduler(mockSeedHost.ID, mockHost.ID), 0, -1).SetVal(rawProbes) mockRDBClient.ExpectHSet(pkgredis.MakeNetworkTopologyKeyInScheduler(mockSeedHost.ID, mockHost.ID), "averageRTT", int64(30388900)).SetVal(1) mockRDBClient.ExpectHSet(pkgredis.MakeNetworkTopologyKeyInScheduler(mockSeedHost.ID, mockHost.ID), "updatedAt", mockProbe.CreatedAt.Format(time.RFC3339Nano)).SetVal(1) - mockRDBClient.ExpectSet(pkgredis.MakeProbedAtKeyInScheduler(mockHost.ID), mockProbe.CreatedAt.Format(time.RFC3339Nano), 0).SetVal("ok") mockRDBClient.ExpectIncr(pkgredis.MakeProbedCountKeyInScheduler(mockHost.ID)).SetVal(6) }, expect: func(t *testing.T, ps Probes) { @@ -568,29 +564,6 @@ func TestProbes_Enqueue(t *testing.T) { assert.EqualError(ps.Enqueue(mockProbe), "update the updated time error") }, }, - { - name: "update the time of the last probe error", - probes: []*Probe{}, - mock: func(mockRDBClient redismock.ClientMock, ps []*Probe) { - data, err := json.Marshal(mockProbe) - if err != nil { - t.Fatal(err) - } - - mockRDBClient.ExpectLLen(pkgredis.MakeProbesKeyInScheduler(mockSeedHost.ID, mockHost.ID)).SetVal(0) - mockRDBClient.ExpectRPush(pkgredis.MakeProbesKeyInScheduler(mockSeedHost.ID, mockHost.ID), data).SetVal(1) - mockRDBClient.ExpectHSet(pkgredis.MakeNetworkTopologyKeyInScheduler(mockSeedHost.ID, mockHost.ID), - "averageRTT", mockProbe.RTT.Nanoseconds()).SetVal(1) - mockRDBClient.ExpectHSet(pkgredis.MakeNetworkTopologyKeyInScheduler(mockSeedHost.ID, mockHost.ID), - "updatedAt", mockProbe.CreatedAt.Format(time.RFC3339Nano)).SetVal(1) - mockRDBClient.ExpectSet(pkgredis.MakeProbedAtKeyInScheduler(mockHost.ID), mockProbe.CreatedAt.Format(time.RFC3339Nano), 0).SetErr( - errors.New("update the time of the last probe error")) - }, - expect: func(t *testing.T, ps Probes) { - assert := assert.New(t) - assert.EqualError(ps.Enqueue(mockProbe), "update the time of the last probe error") - }, - }, { name: "update the number of times the host has been probed error", probes: []*Probe{}, @@ -606,7 +579,6 @@ func TestProbes_Enqueue(t *testing.T) { "averageRTT", mockProbe.RTT.Nanoseconds()).SetVal(1) mockRDBClient.ExpectHSet(pkgredis.MakeNetworkTopologyKeyInScheduler(mockSeedHost.ID, mockHost.ID), "updatedAt", mockProbe.CreatedAt.Format(time.RFC3339Nano)).SetVal(1) - mockRDBClient.ExpectSet(pkgredis.MakeProbedAtKeyInScheduler(mockHost.ID), mockProbe.CreatedAt.Format(time.RFC3339Nano), 0).SetVal("ok") mockRDBClient.ExpectIncr(pkgredis.MakeProbedCountKeyInScheduler(mockHost.ID)).SetErr(errors.New("update the number of times the host has been probed error")) }, expect: func(t *testing.T, ps Probes) { @@ -678,7 +650,6 @@ func TestProbes_Len(t *testing.T) { mockRDBClient.ExpectLRange(pkgredis.MakeProbesKeyInScheduler(mockSeedHost.ID, mockHost.ID), 0, -1).SetVal(rawProbes) mockRDBClient.ExpectHSet(pkgredis.MakeNetworkTopologyKeyInScheduler(mockSeedHost.ID, mockHost.ID), "averageRTT", int64(30388900)).SetVal(1) mockRDBClient.ExpectHSet(pkgredis.MakeNetworkTopologyKeyInScheduler(mockSeedHost.ID, mockHost.ID), "updatedAt", mockProbe.CreatedAt.Format(time.RFC3339Nano)).SetVal(1) - mockRDBClient.ExpectSet(pkgredis.MakeProbedAtKeyInScheduler(mockHost.ID), mockProbe.CreatedAt.Format(time.RFC3339Nano), 0).SetVal("ok") mockRDBClient.ExpectIncr(pkgredis.MakeProbedCountKeyInScheduler(mockHost.ID)).SetVal(6) mockRDBClient.ExpectLLen(pkgredis.MakeProbesKeyInScheduler(mockSeedHost.ID, mockHost.ID)).SetVal(5) }, @@ -945,7 +916,6 @@ func TestProbes_dequeue(t *testing.T) { mockRDBClient.ExpectLRange(pkgredis.MakeProbesKeyInScheduler(mockSeedHost.ID, mockHost.ID), 0, -1).SetVal(rawProbes) mockRDBClient.ExpectHSet(pkgredis.MakeNetworkTopologyKeyInScheduler(mockSeedHost.ID, mockHost.ID), "averageRTT", int64(30388900)).SetVal(1) mockRDBClient.ExpectHSet(pkgredis.MakeNetworkTopologyKeyInScheduler(mockSeedHost.ID, mockHost.ID), "updatedAt", mockProbe.CreatedAt.Format(time.RFC3339Nano)).SetVal(1) - mockRDBClient.ExpectSet(pkgredis.MakeProbedAtKeyInScheduler(mockHost.ID), mockProbe.CreatedAt.Format(time.RFC3339Nano), 0).SetVal("ok") mockRDBClient.ExpectIncr(pkgredis.MakeProbedCountKeyInScheduler(mockHost.ID)).SetVal(6) mockRDBClient.ExpectLPop(pkgredis.MakeProbesKeyInScheduler(mockSeedHost.ID, mockHost.ID)).SetVal(string(rawProbes[0])) },