@@ -19,6 +19,7 @@ package main
19
19
import (
20
20
"context"
21
21
"flag"
22
+ "math/rand/v2"
22
23
"os"
23
24
"slices"
24
25
"sync"
@@ -37,13 +38,23 @@ import (
37
38
"go.etcd.io/etcd/tests/v3/robustness/traffic"
38
39
)
39
40
40
- var profile = traffic.Profile {
41
- MinimalQPS : 100 ,
42
- MaximalQPS : 1000 ,
43
- BurstableQPS : 1000 ,
44
- ClientCount : 3 ,
45
- MaxNonUniqueRequestConcurrency : 3 ,
46
- }
41
+ var (
42
+ profile = traffic.Profile {
43
+ MinimalQPS : 100 ,
44
+ MaximalQPS : 1000 ,
45
+ BurstableQPS : 1000 ,
46
+ ClientCount : 3 ,
47
+ MaxNonUniqueRequestConcurrency : 3 ,
48
+ }
49
+ trafficNames = []string {
50
+ "etcd" ,
51
+ "kubernetes" ,
52
+ }
53
+ traffics = []traffic.Traffic {
54
+ traffic .EtcdPutDeleteLease ,
55
+ traffic .Kubernetes ,
56
+ }
57
+ )
47
58
48
59
func main () {
49
60
local := flag .Bool ("local" , false , "run tests locally and connect to etcd instances via localhost" )
@@ -62,6 +73,9 @@ func main() {
62
73
if err != nil {
63
74
panic (err )
64
75
}
76
+ choice := rand .IntN (len (traffics ))
77
+ tf := traffics [choice ]
78
+ lg .Info ("Traffic" , zap .String ("Type" , trafficNames [choice ]))
65
79
r := report.TestReport {Logger : lg , ServersDataPath : etcdetcdDataPaths }
66
80
defer func () {
67
81
if err = r .Report (reportPath ); err != nil {
@@ -70,14 +84,14 @@ func main() {
70
84
}()
71
85
72
86
lg .Info ("Start traffic generation" , zap .Duration ("duration" , duration ))
73
- r .Client , err = runTraffic (ctx , lg , hosts , baseTime , duration )
87
+ r .Client , err = runTraffic (ctx , lg , tf , hosts , baseTime , duration )
74
88
if err != nil {
75
89
lg .Error ("Failed to generate traffic" )
76
90
panic (err )
77
91
}
78
92
}
79
93
80
- func runTraffic (ctx context.Context , lg * zap.Logger , hosts []string , baseTime time.Time , duration time.Duration ) ([]report.ClientReport , error ) {
94
+ func runTraffic (ctx context.Context , lg * zap.Logger , tf traffic. Traffic , hosts []string , baseTime time.Time , duration time.Duration ) ([]report.ClientReport , error ) {
81
95
ids := identity .NewIDProvider ()
82
96
r , err := traffic .CheckEmptyDatabaseAtStart (ctx , lg , hosts , ids , baseTime )
83
97
if err != nil {
@@ -93,7 +107,7 @@ func runTraffic(ctx context.Context, lg *zap.Logger, hosts []string, baseTime ti
93
107
startTime := time .Since (baseTime )
94
108
g .Go (func () error {
95
109
defer close (maxRevisionChan )
96
- trafficReports = slices .Concat (trafficReports , simulateTraffic (ctx , hosts , ids , baseTime , duration ))
110
+ trafficReports = slices .Concat (trafficReports , simulateTraffic (ctx , tf , hosts , ids , baseTime , duration ))
97
111
maxRevision := report .OperationsMaxRevision (trafficReports )
98
112
maxRevisionChan <- maxRevision
99
113
lg .Info ("Finished simulating Traffic" , zap .Int64 ("max-revision" , maxRevision ))
@@ -120,7 +134,7 @@ func runTraffic(ctx context.Context, lg *zap.Logger, hosts []string, baseTime ti
120
134
return reports , nil
121
135
}
122
136
123
- func simulateTraffic (ctx context.Context , hosts []string , ids identity.Provider , baseTime time.Time , duration time.Duration ) []report.ClientReport {
137
+ func simulateTraffic (ctx context.Context , tf traffic. Traffic , hosts []string , ids identity.Provider , baseTime time.Time , duration time.Duration ) []report.ClientReport {
124
138
var mux sync.Mutex
125
139
var wg sync.WaitGroup
126
140
storage := identity .NewLeaseIDStorage ()
@@ -136,7 +150,7 @@ func simulateTraffic(ctx context.Context, hosts []string, ids identity.Provider,
136
150
defer wg .Done ()
137
151
defer c .Close ()
138
152
139
- traffic . EtcdPutDeleteLease .RunTrafficLoop (ctx , c , limiter ,
153
+ tf .RunTrafficLoop (ctx , c , limiter ,
140
154
ids ,
141
155
storage ,
142
156
concurrencyLimiter ,
@@ -153,7 +167,7 @@ func simulateTraffic(ctx context.Context, hosts []string, ids identity.Provider,
153
167
go func (c * client.RecordingClient ) {
154
168
defer wg .Done ()
155
169
defer c .Close ()
156
- traffic . EtcdPutDeleteLease .RunCompactLoop (ctx , c , traffic .DefaultCompactionPeriod , finish )
170
+ tf .RunCompactLoop (ctx , c , traffic .DefaultCompactionPeriod , finish )
157
171
mux .Lock ()
158
172
reports = append (reports , c .Report ())
159
173
mux .Unlock ()
0 commit comments