@@ -12,16 +12,18 @@ import (
1212 "attacknet/cmd/pkg/types"
1313 "context"
1414 "fmt"
15+ "github.com/kurtosis-tech/stacktrace"
1516 log "github.com/sirupsen/logrus"
1617 "golang.org/x/exp/rand"
18+ "net/http"
1719 "os"
1820 "os/signal"
1921 "syscall"
2022 "time"
2123)
2224
2325const WaitBetweenTestsSecs = 60
24- const Seed = 555
26+ const Seed = 557
2527
2628func getRandomAttackSize () suite.AttackSize {
2729 //return suite.AttackOne
@@ -51,7 +53,7 @@ func buildRandomLatencyTest(targetDescription string, targetSelectors []*suite.C
5153 minDelayMilliSeconds := 10
5254 maxDelayMilliSeconds := 1000
5355 minDurationSeconds := 10
54- maxDurationSeconds := 1000
56+ maxDurationSeconds := 300
5557 minJitterMilliseconds := 10
5658 maxJitterMilliseconds := 1000
5759 minCorrelation := 0
@@ -75,6 +77,38 @@ func buildRandomLatencyTest(targetDescription string, targetSelectors []*suite.C
7577 )
7678}
7779
80+ func buildRandomClockSkewTest (targetDescription string , targetSelectors []* suite.ChaosTargetSelector ) (* types.SuiteTest , error ) {
81+ minDelaySeconds := - 600
82+ maxDelaySeconds := 600
83+ minDurationSeconds := 10
84+ maxDurationSeconds := 300
85+
86+ grace := time .Second * 300
87+ delay := fmt .Sprintf ("%ds" , rand .Intn (maxDelaySeconds - minDelaySeconds )+ minDelaySeconds )
88+ duration := fmt .Sprintf ("%ds" , rand .Intn (maxDurationSeconds - minDurationSeconds )+ minDurationSeconds )
89+
90+ description := fmt .Sprintf ("Apply %s clock skew for %s against %d targets. %s" , delay , duration , len (targetSelectors ), targetDescription )
91+ log .Info (description )
92+ return suite .ComposeNodeClockSkewTest (
93+ description ,
94+ targetSelectors ,
95+ delay ,
96+ duration ,
97+ & grace ,
98+ )
99+ }
100+
101+ func buildRandomTest (targetDescription string , targetSelectors []* suite.ChaosTargetSelector ) (* types.SuiteTest , error ) {
102+ testId := rand .Intn (2 )
103+ if testId == 0 {
104+ return buildRandomLatencyTest (targetDescription , targetSelectors )
105+ }
106+ if testId == 1 {
107+ return buildRandomClockSkewTest (targetDescription , targetSelectors )
108+ }
109+ return nil , stacktrace .NewError ("unknown test id" )
110+ }
111+
78112func pickRandomClient (config * plan.PlannerConfig ) (string , bool ) {
79113 //return "reth", true
80114 isExec := rand .Intn (2 )
@@ -104,6 +138,11 @@ func StartExploration(config *plan.PlannerConfig) error {
104138 }
105139 testableNodes := nodes [1 :]
106140
141+ for _ , n := range nodes {
142+ log .Infof ("%s" , suite .ConvertToNodeIdTag (len (nodes ), n , "execution" ))
143+ log .Infof ("%s" , suite .ConvertToNodeIdTag (len (nodes ), n , "consensus" ))
144+ }
145+
107146 // dedupe from runtime?
108147 kubeClient , err := kubernetes .CreateKubeClient (config .KubernetesNamespace )
109148 if err != nil {
@@ -118,22 +157,29 @@ func StartExploration(config *plan.PlannerConfig) error {
118157 }
119158
120159 var testArtifacts []* artifacts.TestArtifact
121- var done = make (chan bool , 1 )
122- sigs := make (chan os.Signal , 1 )
160+ var done = make (chan bool , 2 )
161+ sigs := make (chan os.Signal , 2 )
123162 signal .Notify (sigs , syscall .SIGINT )
124163 go func () {
125164 sig := <- sigs
126165 fmt .Println ()
127166 fmt .Println (sig , "Signal received. Ending after next test is completed." )
128167 done <- true // Signal that we're done
129- }()
130168
169+ }()
170+ killall := false
131171 for {
172+ loc := time .FixedZone ("GMT" , 0 )
173+ log .Infof ("Start loop. GMT time: %s" , time .Now ().In (loc ).Format (http .TimeFormat ))
132174 select {
133175 case <- done :
134176 fmt .Println ("Writing test artifacts" )
135177 return cleanup (testArtifacts )
136178 default :
179+ if killall {
180+ fmt .Println ("Writing test artifacts" )
181+ return cleanup (testArtifacts )
182+ }
137183 clientUnderTest , isExec := pickRandomClient (config )
138184 targetSpec := getTargetSpec ()
139185 attackSize := getRandomAttackSize ()
@@ -149,14 +195,25 @@ func StartExploration(config *plan.PlannerConfig) error {
149195 continue
150196 }
151197
198+ for _ , selector := range targetSelectors {
199+ for _ , s := range selector .Selector {
200+ msg := "Hitting "
201+ for _ , target := range s .Values {
202+ msg = fmt .Sprintf ("%s %s," , msg , target )
203+ }
204+ log .Info (msg )
205+ }
206+ }
207+ log .Infof ("time: %d" , time .Now ().Unix ())
208+
152209 var targetingDescription string
153210 if targetSpec == suite .TargetMatchingNode {
154211 targetingDescription = fmt .Sprintf ("Impacting the full node of targeted %s clients. Injecting into %s of the matching targets." , clientUnderTest , attackSize )
155212 } else {
156213 targetingDescription = fmt .Sprintf ("Impacting the client of targeted %s clients. Injecting into %s of the matching targets." , clientUnderTest , attackSize )
157214 }
158215
159- test , err := buildRandomLatencyTest (
216+ test , err := buildRandomTest (
160217 targetingDescription ,
161218 targetSelectors ,
162219 )
@@ -169,12 +226,13 @@ func StartExploration(config *plan.PlannerConfig) error {
169226 err = executor .RunTestPlan (ctx )
170227 if err != nil {
171228 log .Errorf ("Error while running test" )
172- return err
229+ fmt .Println ("Writing test artifacts" )
230+ return cleanup (testArtifacts )
173231 } else {
174232 log .Infof ("Test steps completed." )
175233 }
176234
177- log .Info ("Starting health checks" )
235+ log .Infof ("Starting health checks at %s" , time . Now (). In ( loc ). Format ( http . TimeFormat ) )
178236 podsUnderTest , err := executor .GetPodsUnderTest ()
179237 if err != nil {
180238 return err
@@ -186,6 +244,9 @@ func StartExploration(config *plan.PlannerConfig) error {
186244 }
187245 results , err := hc .RunChecks (ctx )
188246 if err != nil {
247+
248+ fmt .Println ("Writing test artifacts" )
249+ err := cleanup (testArtifacts )
189250 return err
190251 }
191252 testArtifact := artifacts .BuildTestArtifact (results , podsUnderTest , * test )
0 commit comments