Skip to content

Commit 8f27f74

Browse files
authored
feature : add chaos testing example (#20)
- [x] add chaos testing example using toxiproxy - [x] create prometheus dashboard - [x] create README to explain the setup
1 parent c635a68 commit 8f27f74

14 files changed

+202
-0
lines changed

examples/chaostesting/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.cache
52.3 KB
Loading
54.1 KB
Loading
68.1 KB
Loading
63.9 KB
Loading

examples/chaostesting/README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Chaos testing with toxiproxy
2+
3+
This setup uses toxiproxy as a middleware between client and database to simulate latency, bandwidth and variation problems at TCP level.
4+
5+
The client service uses toxiproxy service as a sybase database which integrates toxic issues and forwards tcp packets to the database service (sybase server).
6+
7+
![Architecture](./docker-compose.png)
8+
[Docker compose file](./compose.yml)
9+
10+
Prometheus
11+
[dashboard](http://localhost:9090/graph?g0.expr=rate(client%5B1m%5D)&g0.tab=0&g0.stacked=0&g0.show_exemplars=0&g0.range_input=1h&g1.expr=sybase_test_table_insert&g1.tab=0&g1.stacked=0&g1.show_exemplars=0&g1.range_input=1h) is used to analyze metrics from statsd:
12+
13+
The ``client`` is a counter from the client point of view while ``sybase_test_table_insert`` is a timer from the server point of view.
14+
15+
## Example without Toxics (direct)
16+
![Client counter without toxics](./1-client-no-toxics.png)
17+
![Server rates without toxics](./1-server-no-toxics.png)
18+
19+
## Example with Toxics
20+
We can see that the that from the client point of view the rate is lower than before (1rps > 0.04rps).
21+
![Client counter with toxics](./0-client-toxics.png)
22+
![Server rates with toxics](./0-server-toxics.png)
23+
24+
## Tools
25+
26+
### Toxiproxy
27+
28+
[Project Page](https://github.com/Shopify/toxiproxy)
29+
30+
```bash
31+
toxiproxy-cli create database --listen 0.0.0.0:5000 --upstream database:5000;
32+
toxiproxy-cli toxic add -t latency -a latency=2000 database;
33+
toxiproxy-cli toxic add -t bandwidth -a rate=1 database;
34+
toxiproxy-cli toxic add -t slicer -a average_size=1000 -a size_variation=900 -a delay=10000 database;
35+
36+
toxiproxy-cli toxic remove -n latency_downstream database;
37+
```
38+
39+
### Prometheus
40+
41+
[Dashboard](http://localhost:9090/graph?g0.expr=rate(client%5B1m%5D)&g0.tab=0&g0.stacked=0&g0.show_exemplars=0&g0.range_input=1h&g1.expr=sybase_test_table_insert&g1.tab=0&g1.stacked=0&g1.show_exemplars=0&g1.range_input=1h)

examples/chaostesting/client/data.sql

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
use TESTDB
2+
go
3+
4+
set statistics time ON
5+
6+
/* Tradeoff : measure delay with datetime (no support for ticks nor timestamp nor true stopwatch, precision is 1/300 second). Ok to measure high latencies ie : > 1s */
7+
declare @s datetime
8+
select @s = GETUTCDATE()
9+
10+
insert into dbo.TEST_TABLE(TEST_FIELD1) values ('1')
11+
insert into dbo.TEST_TABLE(TEST_FIELD1) values ('1')
12+
insert into dbo.TEST_TABLE(TEST_FIELD1) values ('1')
13+
insert into dbo.TEST_TABLE(TEST_FIELD1) values ('1')
14+
insert into dbo.TEST_TABLE(TEST_FIELD1) values ('1')
15+
16+
declare @e datetime
17+
select @e = GETUTCDATE()
18+
19+
declare @t integer
20+
select @t = DATEDIFF(MILLISECOND, @s, @e)
21+
22+
declare @msg varchar(255)
23+
select @msg = "sybase.test_table.insert:" + convert(varchar, @t) + "|ms"
24+
exec sp_sendmsg "statsd", 8125, @msg
25+
select @msg as metric, count(*) as total from dbo.TEST_TABLE
26+
27+
go
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/sh
2+
. /opt/sap/SYBASE.sh
3+
4+
set -u
5+
6+
while true
7+
do
8+
echo running $1
9+
isql -Usa -S${SERVER}:5000 -P${SA_PASSWORD} -D${DATABASE} -i $1
10+
echo -n "client:1|c" >/dev/udp/statsd/8125
11+
sleep 1
12+
done

examples/chaostesting/compose.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
version: '3.8'
2+
3+
services:
4+
prometheus:
5+
image: prom/prometheus:v2.41.0
6+
volumes:
7+
- ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:ro
8+
ports:
9+
- 9090:9090
10+
networks:
11+
- bridge
12+
13+
statsd:
14+
image: prom/statsd-exporter:v0.23.0
15+
command: "--statsd.listen-udp=:8125 --web.listen-address=:9102 --log.level=debug"
16+
networks:
17+
- bridge
18+
depends_on:
19+
- prometheus
20+
21+
database:
22+
image: superbeeeeeee/docker-sybase
23+
pull_policy: always
24+
environment:
25+
- DATABASE=TESTDB
26+
- SA_PASSWORD=Sybase1234
27+
volumes:
28+
- ./database/:/docker-entrypoint-initdb.d/
29+
networks:
30+
- bridge
31+
healthcheck:
32+
test: healthcheck
33+
interval: 10s
34+
retries: 10
35+
36+
client:
37+
image: superbeeeeeee/docker-sybase
38+
pull_policy: always
39+
entrypoint: ["/schedule.sh", "/data.sql"]
40+
environment:
41+
- DATABASE=TESTDB
42+
- SA_PASSWORD=Sybase1234
43+
- SERVER=toxiproxy
44+
volumes:
45+
- ./client/schedule.sh:/schedule.sh:ro
46+
- ./client/data.sql:/data.sql:ro
47+
networks:
48+
- bridge
49+
depends_on:
50+
database:
51+
condition: service_healthy
52+
statsd:
53+
condition: service_started
54+
toxiproxy:
55+
condition: service_started
56+
57+
toxiproxy:
58+
image: shopify/toxiproxy
59+
networks:
60+
- bridge
61+
toxiproxy-config:
62+
image: shopify/toxiproxy
63+
entrypoint: >
64+
sh -c "/go/bin/toxiproxy-cli -h toxiproxy:8474 create database --listen 0.0.0.0:5000 --upstream database:5000;
65+
/go/bin/toxiproxy-cli -h toxiproxy:8474 toxic add -t latency -a latency=2000 database;
66+
/go/bin/toxiproxy-cli -h toxiproxy:8474 toxic add -t bandwidth -a rate=1 database;
67+
/go/bin/toxiproxy-cli -h toxiproxy:8474 toxic add -t slicer -a average_size=1000 -a size_variation=900 -a delay=10000 database;"
68+
networks:
69+
- bridge
70+
depends_on:
71+
- toxiproxy
72+
73+
networks:
74+
bridge:
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
sp_configure 'allow sendmsg', 1
2+
go

0 commit comments

Comments
 (0)