Skip to content

Commit 837e0f6

Browse files
committed
wip
1 parent 86211ec commit 837e0f6

File tree

2 files changed

+102
-20
lines changed

2 files changed

+102
-20
lines changed

havoc/examples/ccip_v2_test.go

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package examples
2+
3+
import (
4+
"context"
5+
"github.com/smartcontractkit/chainlink-testing-framework/havoc"
6+
"github.com/stretchr/testify/require"
7+
"testing"
8+
"time"
9+
)
10+
11+
func TestCCIPChaos(t *testing.T) {
12+
l := defaultLogger()
13+
c, err := havoc.NewChaosMeshClient()
14+
require.NoError(t, err)
15+
16+
namespace := "crib-radek-ccip-v2"
17+
18+
rebootsChaos, err := podFail(c, l, NodeRebootsConfig{
19+
Namespace: namespace,
20+
Description: "reboot nodes",
21+
LabelKey: "app.kubernetes.io/instance",
22+
LabelValues: []string{"ccip-1"},
23+
ExperimentTotalDuration: 3 * time.Minute,
24+
})
25+
require.NoError(t, err)
26+
latenciesChaos, err := networkDelay(c, l, NodeLatenciesConfig{
27+
Namespace: namespace,
28+
Description: "network issues",
29+
Latency: 5000 * time.Millisecond,
30+
LatencyDuration: 40 * time.Second,
31+
FromLabelKey: "app.kubernetes.io/instance",
32+
FromLabelValues: []string{"ccip-1"},
33+
ToLabelKey: "app.kubernetes.io/instance",
34+
ToLabelValues: []string{"ccip-2", "ccip-3", "ccip-4"},
35+
ExperimentTotalDuration: 3 * time.Minute,
36+
//ExperimentCreateDelay: 3 * time.Minute,
37+
})
38+
require.NoError(t, err)
39+
blockchainLatency, err := networkDelay(c, l, NodeLatenciesConfig{
40+
Namespace: namespace,
41+
Description: "blockchain nodes network issues",
42+
Latency: 5000 * time.Millisecond,
43+
LatencyDuration: 40 * time.Second,
44+
FromLabelKey: "app.kubernetes.io/instance",
45+
FromLabelValues: []string{"ccip-1", "ccip-2", "ccip-3"},
46+
ToLabelKey: "instance",
47+
ToLabelValues: []string{"geth-1337"},
48+
ExperimentTotalDuration: 3 * time.Minute,
49+
//ExperimentCreateDelay: 3 * time.Minute,
50+
})
51+
require.NoError(t, err)
52+
53+
_ = rebootsChaos
54+
_ = latenciesChaos
55+
_ = blockchainLatency
56+
57+
chaosList := []havoc.ChaosEntity{
58+
//rebootsChaos,
59+
//latenciesChaos,
60+
blockchainLatency,
61+
}
62+
63+
for _, chaos := range chaosList {
64+
chaos.AddListener(havoc.NewChaosLogger(l))
65+
//chaos.AddListener(havoc.NewSingleLineGrafanaAnnotator(cfg.GrafanaURL, cfg.GrafanaToken, cfg.GrafanaDashboardUID))
66+
exists, err := havoc.ChaosObjectExists(chaos.GetObject(), c)
67+
require.NoError(t, err)
68+
require.False(t, exists, "chaos object already exists: %s. Delete it before starting the test", chaos.GetChaosName())
69+
chaos.Create(context.Background())
70+
}
71+
t.Cleanup(func() {
72+
for _, chaos := range chaosList {
73+
chaos.Delete(context.Background())
74+
}
75+
})
76+
77+
// your load test comes here !
78+
time.Sleep(3*time.Minute + 5*time.Second)
79+
}

havoc/examples/example_test.go

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,15 @@ import (
1515
"time"
1616
)
1717

18-
const (
19-
Namespace = "janitor"
20-
)
21-
2218
func defaultLogger() zerolog.Logger {
2319
return log.Output(zerolog.ConsoleWriter{Out: os.Stderr}).Level(zerolog.TraceLevel)
2420
}
2521

2622
type NodeLatenciesConfig struct {
23+
Namespace string
2724
Description string
2825
Latency time.Duration
26+
LatencyDuration time.Duration
2927
FromLabelKey string
3028
FromLabelValues []string
3129
ToLabelKey string
@@ -34,7 +32,7 @@ type NodeLatenciesConfig struct {
3432
ExperimentCreateDelay time.Duration
3533
}
3634

37-
func nodeLatencies(client client.Client, l zerolog.Logger, cfg NodeLatenciesConfig) (*havoc.Schedule, error) {
35+
func networkDelay(client client.Client, l zerolog.Logger, cfg NodeLatenciesConfig) (*havoc.Schedule, error) {
3836
return havoc.NewSchedule(havoc.ScheduleOpts{
3937
Description: cfg.Description,
4038
DelayCreate: cfg.ExperimentCreateDelay,
@@ -47,13 +45,13 @@ func nodeLatencies(client client.Client, l zerolog.Logger, cfg NodeLatenciesConf
4745
},
4846
ObjectMeta: metav1.ObjectMeta{
4947
Name: "latencies",
50-
Namespace: Namespace,
48+
Namespace: cfg.Namespace,
5149
},
5250
Spec: v1alpha1.ScheduleSpec{
53-
Schedule: "*/1 * * * *",
51+
Schedule: "@every 1m",
5452
ConcurrencyPolicy: v1alpha1.ForbidConcurrent,
5553
Type: v1alpha1.ScheduleTypeNetworkChaos,
56-
HistoryLimit: 10,
54+
HistoryLimit: 2,
5755
ScheduleItem: v1alpha1.ScheduleItem{
5856
EmbedChaos: v1alpha1.EmbedChaos{
5957
NetworkChaos: &v1alpha1.NetworkChaosSpec{
@@ -62,7 +60,7 @@ func nodeLatencies(client client.Client, l zerolog.Logger, cfg NodeLatenciesConf
6260
Mode: v1alpha1.AllMode,
6361
Selector: v1alpha1.PodSelectorSpec{
6462
GenericSelectorSpec: v1alpha1.GenericSelectorSpec{
65-
Namespaces: []string{Namespace},
63+
Namespaces: []string{cfg.Namespace},
6664
ExpressionSelectors: v1alpha1.LabelSelectorRequirements{
6765
{
6866
Operator: "In",
@@ -73,12 +71,12 @@ func nodeLatencies(client client.Client, l zerolog.Logger, cfg NodeLatenciesConf
7371
},
7472
},
7573
},
76-
Duration: ptr.To[string]((30 * time.Second).String()),
74+
Duration: ptr.To[string]((cfg.LatencyDuration).String()),
7775
Direction: v1alpha1.From,
7876
Target: &v1alpha1.PodSelector{
7977
Selector: v1alpha1.PodSelectorSpec{
8078
GenericSelectorSpec: v1alpha1.GenericSelectorSpec{
81-
Namespaces: []string{Namespace},
79+
Namespaces: []string{cfg.Namespace},
8280
ExpressionSelectors: v1alpha1.LabelSelectorRequirements{
8381
{
8482
Operator: "In",
@@ -107,14 +105,15 @@ func nodeLatencies(client client.Client, l zerolog.Logger, cfg NodeLatenciesConf
107105
}
108106

109107
type NodeRebootsConfig struct {
108+
Namespace string
110109
Description string
111110
LabelKey string
112111
LabelValues []string
113112
ExperimentTotalDuration time.Duration
114113
ExperimentCreateDelay time.Duration
115114
}
116115

117-
func reboots(client client.Client, l zerolog.Logger, cfg NodeRebootsConfig) (*havoc.Schedule, error) {
116+
func podFail(client client.Client, l zerolog.Logger, cfg NodeRebootsConfig) (*havoc.Schedule, error) {
118117
return havoc.NewSchedule(havoc.ScheduleOpts{
119118
Description: cfg.Description,
120119
DelayCreate: cfg.ExperimentCreateDelay,
@@ -126,14 +125,14 @@ func reboots(client client.Client, l zerolog.Logger, cfg NodeRebootsConfig) (*ha
126125
APIVersion: "chaos-mesh.org/v1alpha1",
127126
},
128127
ObjectMeta: metav1.ObjectMeta{
129-
Name: "reboots",
130-
Namespace: Namespace,
128+
Name: "fail",
129+
Namespace: cfg.Namespace,
131130
},
132131
Spec: v1alpha1.ScheduleSpec{
133-
Schedule: "*/1 * * * *",
132+
Schedule: "@every 1m",
134133
ConcurrencyPolicy: v1alpha1.ForbidConcurrent,
135134
Type: v1alpha1.ScheduleTypePodChaos,
136-
HistoryLimit: 10,
135+
HistoryLimit: 2,
137136
ScheduleItem: v1alpha1.ScheduleItem{
138137
EmbedChaos: v1alpha1.EmbedChaos{
139138
PodChaos: &v1alpha1.PodChaosSpec{
@@ -143,7 +142,7 @@ func reboots(client client.Client, l zerolog.Logger, cfg NodeRebootsConfig) (*ha
143142
Mode: v1alpha1.AllMode,
144143
Selector: v1alpha1.PodSelectorSpec{
145144
GenericSelectorSpec: v1alpha1.GenericSelectorSpec{
146-
Namespaces: []string{Namespace},
145+
Namespaces: []string{cfg.Namespace},
147146
ExpressionSelectors: v1alpha1.LabelSelectorRequirements{
148147
{
149148
Operator: "In",
@@ -155,7 +154,7 @@ func reboots(client client.Client, l zerolog.Logger, cfg NodeRebootsConfig) (*ha
155154
},
156155
},
157156
},
158-
Duration: ptr.To[string]("40s"),
157+
Duration: ptr.To[string]("10s"),
159158
},
160159
},
161160
},
@@ -170,14 +169,18 @@ func TestChaos(t *testing.T) {
170169
c, err := havoc.NewChaosMeshClient()
171170
require.NoError(t, err)
172171

173-
rebootsChaos, err := reboots(c, l, NodeRebootsConfig{
172+
namespace := "janitor"
173+
174+
rebootsChaos, err := podFail(c, l, NodeRebootsConfig{
175+
Namespace: namespace,
174176
Description: "reboot nodes",
175177
LabelKey: "app.kubernetes.io/instance",
176178
LabelValues: []string{"janitor"},
177179
ExperimentTotalDuration: 1 * time.Minute,
178180
})
179181
require.NoError(t, err)
180-
latenciesChaos, err := nodeLatencies(c, l, NodeLatenciesConfig{
182+
latenciesChaos, err := networkDelay(c, l, NodeLatenciesConfig{
183+
Namespace: namespace,
181184
Description: "network issues",
182185
Latency: 300 * time.Millisecond,
183186
FromLabelKey: "app.kubernetes.io/instance",

0 commit comments

Comments
 (0)