Skip to content

Commit

Permalink
feat: add networkTopology e2e test (#3124)
Browse files Browse the repository at this point in the history
Signed-off-by: huangmin <2107139596@qq.com>
  • Loading branch information
MinH-09 authored Apr 8, 2024
1 parent f960bc0 commit 67bb7a6
Show file tree
Hide file tree
Showing 12 changed files with 334 additions and 1 deletion.
3 changes: 2 additions & 1 deletion test/e2e/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ const (
)

const (
dfdaemonCompatibilityTestMode = "dfdaemon"
dfdaemonCompatibilityTestMode = "dfdaemon"
schedulerCompatibilityTestMode = "scheduler"
)

const (
Expand Down
156 changes: 156 additions & 0 deletions test/e2e/network_topology_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
/*
* Copyright 2024 The Dragonfly Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package e2e

import (
"context"
"fmt"
"os"
"strconv"
"strings"
"time"

. "github.com/onsi/ginkgo/v2" //nolint
. "github.com/onsi/gomega" //nolint

"d7y.io/dragonfly/v2/test/e2e/util"
)

var _ = Describe("Evaluator with networkTopology", func() {
Context("networkTopology", func() {
It("check networkTopology in redis", Label("networkTopology"), func() {
mode := os.Getenv("DRAGONFLY_COMPATIBILITY_E2E_TEST_MODE")
if mode == schedulerCompatibilityTestMode {
fmt.Println("networkTopology is disable, skip")
return
}
Expect(waitForProbedInNetworkTopology()).Should(BeTrue())

if waitForProbedInNetworkTopology() == true {
time.Sleep(2 * time.Minute)
Expect(checkNetworkTopologyUpdated()).Should(BeTrue())
}
})
})
})

// getRedisExec get redis pod.
func getRedisExec() *util.PodExec {
out, err := util.KubeCtlCommand("-n", dragonflyNamespace, "get", "pod", "-l", "app.kubernetes.io/name=redis",
"-o", "jsonpath='{range .items[0]}{.metadata.name}{end}'").CombinedOutput()
podName := strings.Trim(string(out), "'")
Expect(err).NotTo(HaveOccurred())
fmt.Println(podName)
Expect(strings.HasPrefix(podName, "dragonfly-redis")).Should(BeTrue())
return util.NewPodExec(dragonflyNamespace, podName, "redis")
}

func waitForProbedInNetworkTopology() bool {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
defer cancel()

ticker := time.NewTicker(5 * time.Second)
defer ticker.Stop()

redisPod := getRedisExec()

for {
select {
case <-ctx.Done():
return false
case <-ticker.C:
out, err := redisPod.Command("redis-cli", "-a", "dragonfly", "-n", "3", "dbsize").CombinedOutput()
Expect(err).NotTo(HaveOccurred())
key, err := strconv.Atoi(strings.Split(string(out), "\n")[1])
if key == 0 || err != nil {
continue
}

out, err = redisPod.Command("redis-cli", "-a", "dragonfly", "-n", "3", "KEYS", "scheduler:network-topology:*").CombinedOutput()
Expect(err).NotTo(HaveOccurred())
networkTopologyKey := strings.Split(string(out), "\n")[1]
if networkTopologyKey == "" || err != nil {
continue
}
networkTopologyOut, err := redisPod.Command("redis-cli", "-a", "dragonfly", "-n", "3", "HGETALL", networkTopologyKey).CombinedOutput()
Expect(err).NotTo(HaveOccurred())
if networkTopologyOut == nil || err != nil {
continue
}

out, err = redisPod.Command("redis-cli", "-a", "dragonfly", "-n", "3", "KEYS", "scheduler:probes:*").CombinedOutput()
Expect(err).NotTo(HaveOccurred())
probesKey := strings.Split(string(out), "\n")[1]
if probesKey == "" || err != nil {
continue
}
probesOut, err := redisPod.Command("redis-cli", "-a", "dragonfly", "-n", "3", "LRANGE", probesKey, "0", "-1").CombinedOutput()
Expect(err).NotTo(HaveOccurred())
if probesOut == nil || err != nil {
continue
}

out, err = redisPod.Command("redis-cli", "-a", "dragonfly", "-n", "3", "KEYS", "scheduler:probed-count:*").CombinedOutput()
Expect(err).NotTo(HaveOccurred())
probedCountKey := strings.Split(string(out), "\n")[1]
if probedCountKey == "" || err != nil {
continue
}
probedCountOut, err := redisPod.Command("redis-cli", "-a", "dragonfly", "-n", "3", "GET", probedCountKey).CombinedOutput()
Expect(err).NotTo(HaveOccurred())
if probedCountOut == nil || err != nil {
continue
}

return true
}
}
}

func checkNetworkTopologyUpdated() bool {
redisPod := getRedisExec()

var networkTopologyKey string
out, err := redisPod.Command("redis-cli", "-a", "dragonfly", "-n", "3", "KEYS", "scheduler:network-topology:*").CombinedOutput()
Expect(err).NotTo(HaveOccurred())
for i := 1; i <= 3; i++ {
networkTopologyKey = strings.Split(string(out), "\n")[i]
updatedAtOut, err := redisPod.Command("redis-cli", "-a", "dragonfly", "-n", "3", "HGET", networkTopologyKey, "updatedAt").CombinedOutput()
Expect(err).NotTo(HaveOccurred())
createdAtOut, err := redisPod.Command("redis-cli", "-a", "dragonfly", "-n", "3", "HGET", networkTopologyKey, "createdAt").CombinedOutput()
Expect(err).NotTo(HaveOccurred())
if strings.Split(string(updatedAtOut), "\n")[1] == strings.Split(string(createdAtOut), "\n")[1] {
return false
}
}

var probedCountKey string
out, err = redisPod.Command("redis-cli", "-a", "dragonfly", "-n", "3", "KEYS", "scheduler:probed-count:*").CombinedOutput()
Expect(err).NotTo(HaveOccurred())
for i := 1; i <= 3; i++ {
probedCountKey = strings.Split(string(out), "\n")[i]
probedCountOut, err := redisPod.Command("redis-cli", "-a", "dragonfly", "-n", "3", "GET", probedCountKey).CombinedOutput()
Expect(err).NotTo(HaveOccurred())
probedCount, err := strconv.Atoi(strings.Split(string(probedCountOut), "\n")[1])
Expect(err).NotTo(HaveOccurred())
if probedCount <= 1 && probedCount >= 50 {
return false
}
}

return true
}
18 changes: 18 additions & 0 deletions test/testdata/charts/config-cache-list-metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ scheduler:
enableHost: true
config:
verbose: true
scheduler:
algorithm: nt
networkTopology:
collectInterval: 2m
probe:
queueLength: 5
count: 10
cache:
interval: 5m
ttl: 5m

seedPeer:
image: dragonflyoss/dfdaemon
Expand Down Expand Up @@ -55,6 +65,10 @@ seedPeer:
verbose: true
download:
prefetch: true
networkTopology:
enable: true
probe:
interval: 10s

dfdaemon:
image: dragonflyoss/dfdaemon
Expand Down Expand Up @@ -89,6 +103,10 @@ dfdaemon:
cacheRecursiveMetadata: 10m
scheduler:
disableAutoBackSource: true
networkTopology:
enable: true
probe:
interval: 10s
proxy:
defaultFilter: "Expires&Signature&ns"
security:
Expand Down
18 changes: 18 additions & 0 deletions test/testdata/charts/config-compatibility.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ scheduler:
enableHost: true
config:
verbose: true
scheduler:
algorithm: nt
networkTopology:
collectInterval: 2m
probe:
queueLength: 5
count: 10
cache:
interval: 5m
ttl: 5m

seedPeer:
image: dragonflyoss/dfdaemon
Expand Down Expand Up @@ -55,6 +65,10 @@ seedPeer:
verbose: true
download:
prefetch: true
networkTopology:
enable: true
probe:
interval: 10s

dfdaemon:
image: dragonflyoss/dfdaemon
Expand Down Expand Up @@ -100,6 +114,10 @@ dfdaemon:
proxies:
- regx: blobs/sha256.*
- regx: file-server
networkTopology:
enable: true
probe:
interval: 10s

manager:
image: dragonflyoss/manager
Expand Down
18 changes: 18 additions & 0 deletions test/testdata/charts/config-concurent-back-source.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ scheduler:
enableHost: true
config:
verbose: true
scheduler:
algorithm: nt
networkTopology:
collectInterval: 2m
probe:
queueLength: 5
count: 10
cache:
interval: 5m
ttl: 5m

seedPeer:
image: dragonflyoss/dfdaemon
Expand Down Expand Up @@ -59,6 +69,10 @@ seedPeer:
thresholdSize: 10M
thresholdSpeed: 2M
goroutineCount: 4
networkTopology:
enable: true
probe:
interval: 10s

dfdaemon:
image: dragonflyoss/dfdaemon
Expand Down Expand Up @@ -108,6 +122,10 @@ dfdaemon:
proxies:
- regx: blobs/sha256.*
- regx: file-server
networkTopology:
enable: true
probe:
interval: 10s

manager:
image: dragonflyoss/manager
Expand Down
14 changes: 14 additions & 0 deletions test/testdata/charts/config-disable-seed-peer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ scheduler:
seedPeer:
enable: false
verbose: true
scheduler:
algorithm: nt
networkTopology:
collectInterval: 2m
probe:
queueLength: 5
count: 10
cache:
interval: 5m
ttl: 5m

seedPeer:
enable: false
Expand Down Expand Up @@ -77,6 +87,10 @@ dfdaemon:
proxies:
- regx: blobs/sha256.*
- regx: file-server
networkTopology:
enable: true
probe:
interval: 10s

manager:
image: dragonflyoss/manager
Expand Down
18 changes: 18 additions & 0 deletions test/testdata/charts/config-grpc-tls-ipv6.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ scheduler:
enableHost: true
config:
verbose: true
scheduler:
algorithm: nt
networkTopology:
collectInterval: 2m
probe:
queueLength: 5
count: 10
cache:
interval: 5m
ttl: 5m
security:
autoIssueCert: true
tlsVerify: true
Expand Down Expand Up @@ -98,6 +108,10 @@ seedPeer:
thresholdSize: 10M
thresholdSpeed: 2M
goroutineCount: 4
networkTopology:
enable: true
probe:
interval: 10s
security:
autoIssueCert: true
tlsVerify: true
Expand Down Expand Up @@ -186,6 +200,10 @@ dfdaemon:
proxies:
- regx: blobs/sha256.*
- regx: file-server
networkTopology:
enable: true
probe:
interval: 10s
security:
autoIssueCert: true
tlsVerify: true
Expand Down
18 changes: 18 additions & 0 deletions test/testdata/charts/config-grpc-tls.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ scheduler:
enableHost: true
config:
verbose: true
scheduler:
algorithm: nt
networkTopology:
collectInterval: 2m
probe:
queueLength: 5
count: 10
cache:
interval: 5m
ttl: 5m
security:
autoIssueCert: true
tlsVerify: true
Expand Down Expand Up @@ -96,6 +106,10 @@ seedPeer:
thresholdSize: 10M
thresholdSpeed: 2M
goroutineCount: 4
networkTopology:
enable: true
probe:
interval: 10s
security:
autoIssueCert: true
tlsVerify: true
Expand Down Expand Up @@ -168,6 +182,10 @@ dfdaemon:
goroutineCount: 4
scheduler:
disableAutoBackSource: true
networkTopology:
enable: true
probe:
interval: 10s
proxy:
defaultFilter: "Expires&Signature&ns"
security:
Expand Down
Loading

0 comments on commit 67bb7a6

Please sign in to comment.