Skip to content

Commit ee9fdc8

Browse files
committed
boilerplate for application to test disruptions
1 parent d02d1fb commit ee9fdc8

File tree

2 files changed

+241
-4
lines changed

2 files changed

+241
-4
lines changed

dogfood/tester/disruptions.go

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
package main
2+
3+
import (
4+
"github.com/DataDog/chaos-controller/api/v1beta1"
5+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
6+
"k8s.io/apimachinery/pkg/util/intstr"
7+
)
8+
9+
// Globals
10+
11+
var SELECTOR = []string{"app", "chaos-dogfood-client"}
12+
var CONTAINER = "client-deploy"
13+
14+
// Network Disruptions
15+
var network1 = v1beta1.Disruption{
16+
ObjectMeta: metav1.ObjectMeta{
17+
Name: "e2etest-network1",
18+
Namespace: "chaos-engineering",
19+
},
20+
Spec: v1beta1.DisruptionSpec{
21+
Count: &intstr.IntOrString{Type: intstr.Int, IntVal: 1},
22+
Unsafemode: &v1beta1.UnsafemodeSpec{
23+
DisableAll: true,
24+
},
25+
Selector: map[string]string{SELECTOR[0]: SELECTOR[1]},
26+
Containers: []string{CONTAINER},
27+
Duration: "3m",
28+
Network: &v1beta1.NetworkDisruptionSpec{
29+
Hosts: []v1beta1.NetworkDisruptionHostSpec{
30+
{
31+
Host: "chaos-dogfood-server.chaos-demo.svc.cluster.local",
32+
Port: 50051,
33+
Protocol: "tcp",
34+
},
35+
},
36+
Drop: 30,
37+
Corrupt: 0,
38+
Delay: 0,
39+
BandwidthLimit: 0,
40+
},
41+
},
42+
}
43+
44+
var network2 = v1beta1.Disruption{
45+
ObjectMeta: metav1.ObjectMeta{
46+
Name: "e2etest-network2",
47+
Namespace: "chaos-engineering",
48+
},
49+
Spec: v1beta1.DisruptionSpec{
50+
Count: &intstr.IntOrString{Type: intstr.Int, IntVal: 1},
51+
Unsafemode: &v1beta1.UnsafemodeSpec{
52+
DisableAll: true,
53+
},
54+
Selector: map[string]string{SELECTOR[0]: SELECTOR[1]},
55+
Containers: []string{CONTAINER},
56+
Duration: "3m",
57+
Network: &v1beta1.NetworkDisruptionSpec{
58+
Hosts: []v1beta1.NetworkDisruptionHostSpec{
59+
{
60+
Host: "chaos-dogfood-server.chaos-demo.svc.cluster.local",
61+
Port: 50051,
62+
Protocol: "tcp",
63+
},
64+
},
65+
Drop: 70,
66+
Corrupt: 0,
67+
Delay: 0,
68+
BandwidthLimit: 0,
69+
},
70+
},
71+
}
72+
73+
var network3 = v1beta1.Disruption{
74+
ObjectMeta: metav1.ObjectMeta{
75+
Name: "e2etest-network3",
76+
Namespace: "chaos-engineering",
77+
},
78+
Spec: v1beta1.DisruptionSpec{
79+
Count: &intstr.IntOrString{Type: intstr.Int, IntVal: 1},
80+
Unsafemode: &v1beta1.UnsafemodeSpec{
81+
DisableAll: true,
82+
},
83+
Selector: map[string]string{SELECTOR[0]: SELECTOR[1]},
84+
Containers: []string{CONTAINER},
85+
Duration: "3m",
86+
Network: &v1beta1.NetworkDisruptionSpec{
87+
Hosts: []v1beta1.NetworkDisruptionHostSpec{
88+
{
89+
Host: "chaos-dogfood-server.chaos-demo.svc.cluster.local",
90+
Port: 50051,
91+
Protocol: "tcp",
92+
},
93+
},
94+
Drop: 0,
95+
Corrupt: 0,
96+
Delay: 1000,
97+
BandwidthLimit: 0,
98+
},
99+
},
100+
}
101+
102+
var NETWORK_DISRUPTIONS = []v1beta1.Disruption{network1, network2, network3}
103+
104+
// Disk Disruptions
105+
var diskReadsThresholds = []int{1024, 2048, 4098}
106+
107+
var disk1 = v1beta1.Disruption{
108+
ObjectMeta: metav1.ObjectMeta{
109+
Name: "e2etest-disk1",
110+
Namespace: "chaos-engineering",
111+
},
112+
Spec: v1beta1.DisruptionSpec{
113+
Count: &intstr.IntOrString{Type: intstr.Int, IntVal: 1},
114+
Unsafemode: &v1beta1.UnsafemodeSpec{
115+
DisableAll: true,
116+
},
117+
Selector: map[string]string{SELECTOR[0]: SELECTOR[1]},
118+
Containers: []string{CONTAINER},
119+
Duration: "3m",
120+
DiskPressure: &v1beta1.DiskPressureSpec{
121+
Path: "/mnt/data",
122+
Throttling: v1beta1.DiskPressureThrottlingSpec{
123+
ReadBytesPerSec: &diskReadsThresholds[0],
124+
},
125+
},
126+
},
127+
}
128+
129+
var disk2 = v1beta1.Disruption{
130+
ObjectMeta: metav1.ObjectMeta{
131+
Name: "e2etest-disk2",
132+
Namespace: "chaos-engineering",
133+
},
134+
Spec: v1beta1.DisruptionSpec{
135+
Count: &intstr.IntOrString{Type: intstr.Int, IntVal: 1},
136+
Unsafemode: &v1beta1.UnsafemodeSpec{
137+
DisableAll: true,
138+
},
139+
Selector: map[string]string{SELECTOR[0]: SELECTOR[1]},
140+
Containers: []string{CONTAINER},
141+
Duration: "3m",
142+
DiskPressure: &v1beta1.DiskPressureSpec{
143+
Path: "/mnt/data",
144+
Throttling: v1beta1.DiskPressureThrottlingSpec{
145+
WriteBytesPerSec: &diskReadsThresholds[1],
146+
},
147+
},
148+
},
149+
}
150+
151+
var disk3 = v1beta1.Disruption{
152+
ObjectMeta: metav1.ObjectMeta{
153+
Name: "e2etest-disk3",
154+
Namespace: "chaos-engineering",
155+
},
156+
Spec: v1beta1.DisruptionSpec{
157+
Count: &intstr.IntOrString{Type: intstr.Int, IntVal: 1},
158+
Unsafemode: &v1beta1.UnsafemodeSpec{
159+
DisableAll: true,
160+
},
161+
Selector: map[string]string{SELECTOR[0]: SELECTOR[1]},
162+
Containers: []string{CONTAINER},
163+
Duration: "3m",
164+
DiskPressure: &v1beta1.DiskPressureSpec{
165+
Path: "/mnt/data",
166+
Throttling: v1beta1.DiskPressureThrottlingSpec{
167+
WriteBytesPerSec: &diskReadsThresholds[2],
168+
},
169+
},
170+
},
171+
}
172+
173+
var DISK_DISRUPTIONS = []v1beta1.Disruption{disk1, disk2, disk3}
174+
175+
// CPU Disruptions
176+
177+
var cpu1 = v1beta1.Disruption{
178+
ObjectMeta: metav1.ObjectMeta{
179+
Name: "e2etest-cpu1",
180+
Namespace: "chaos-engineering",
181+
},
182+
Spec: v1beta1.DisruptionSpec{
183+
Count: &intstr.IntOrString{Type: intstr.Int, IntVal: 1},
184+
Unsafemode: &v1beta1.UnsafemodeSpec{
185+
DisableAll: true,
186+
},
187+
Selector: map[string]string{SELECTOR[0]: SELECTOR[1]},
188+
Containers: []string{CONTAINER},
189+
Duration: "3m",
190+
CPUPressure: &v1beta1.CPUPressureSpec{
191+
Count: &intstr.IntOrString{IntVal: 4},
192+
},
193+
},
194+
}
195+
196+
var CPU_DISRUPTIONS = []v1beta1.Disruption{cpu1}

dogfood/tester/dogfood_client.go renamed to dogfood/tester/dogfood_tester.go

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,53 @@
55

66
package main
77

8-
func init() {
8+
import (
9+
"encoding/json"
10+
"github.com/DataDog/chaos-controller/api/v1beta1"
11+
"go.uber.org/zap"
12+
"net/http"
13+
"time"
14+
)
15+
16+
var VERSION string
17+
var STATUS string
18+
var logger *zap.SugaredLogger
19+
20+
type SpecificRequest struct {
21+
CustomDisruption v1beta1.Disruption `json:"disruption"`
22+
PreInstalledDisruption string `json:"preinstalled"`
23+
}
24+
25+
type Response struct {
26+
Disruption string `json:"disruption"`
27+
StartTime time.Time `json:"startTime"`
28+
EndTime time.Time `json:"endTime"`
29+
Results string `json:"results"`
30+
ResultsExplained string `json:"resultsExplained"`
31+
}
32+
33+
func version(w http.ResponseWriter, r *http.Request) {
34+
if err := json.NewEncoder(w).Encode(VERSION); err != nil {
35+
logger.Errorw("Failed to Encode Version: %w", err)
36+
}
37+
}
38+
39+
func status(w http.ResponseWriter, r *http.Request) {
40+
if err := json.NewEncoder(w).Encode(STATUS); err != nil {
41+
logger.Errorw("Failed to Encode STATUS: %w", err)
42+
}
43+
}
44+
45+
func handleRequests() {
46+
http.HandleFunc("/version", version)
47+
http.HandleFunc("/status", status)
48+
49+
STATUS = "ready for requests"
950
}
1051

1152
func main() {
1253
//TODO
1354
//1. Wait for a request to run a test
14-
//2. When a request is received, place that request in a global queue in case several people are attempting to test at once
15-
// a. Have CI continuously hit this end point and if its currently in the queue, returns its place in queue
16-
//3. In another go thread, pop requests to test from the queue
1755
//4. Find out what relevant metrics would be (if only testing CPU, only CPU metrics matter)
1856
//5. Get relevant metrics from datadog for the past 3 minutes
1957
//6. Deploy the version to test
@@ -27,4 +65,7 @@ func main() {
2765
//12. Once the entire request is finished, do 1 of 2 things:
2866
// a. If queue is empty, return the chaos controller in the staging cluster back to latest:stable
2967
// b. If queue is not empty, take the next request
68+
STATUS = "initializing"
69+
logger = &zap.SugaredLogger{}
70+
handleRequests()
3071
}

0 commit comments

Comments
 (0)