-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add chaos backend based on toxiproxy
- Loading branch information
0 parents
commit 9c0e097
Showing
8 changed files
with
164 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
**/.classpath | ||
**/.dockerignore | ||
**/.env | ||
**/.git | ||
**/.gitignore | ||
**/.project | ||
**/.settings | ||
**/.toolstarget | ||
**/.vs | ||
**/.vscode | ||
**/*.*proj.user | ||
**/*.dbmdl | ||
**/*.jfm | ||
**/azds.yaml | ||
**/bin | ||
**/charts | ||
**/docker-compose* | ||
**/Dockerfile* | ||
**/node_modules | ||
**/npm-debug.log | ||
**/obj | ||
**/secrets.dev.yaml | ||
**/values.dev.yaml | ||
README.md |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Chaos backend (Toxiproxy) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#build stage | ||
FROM golang:alpine AS builder | ||
RUN apk add --no-cache git | ||
WORKDIR /go/src/app | ||
COPY . . | ||
RUN go get -d -v ./... | ||
RUN go install -v ./... | ||
|
||
#final stage | ||
FROM alpine:latest | ||
RUN apk --no-cache add ca-certificates | ||
COPY --from=builder /go/bin/chaos-backend-toxiproxy /app | ||
ENTRYPOINT ["./app"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
version: "3.7" | ||
|
||
services: | ||
server: | ||
image: iskorotkov/chaos-server:latest | ||
command: ["-port", "8811"] | ||
hostname: server | ||
deploy: | ||
restart_policy: | ||
delay: 5s | ||
max_attempts: 5 | ||
networks: | ||
- private | ||
|
||
writer: | ||
image: iskorotkov/chaos-client:latest | ||
depends_on: | ||
- server | ||
- toxiproxy | ||
networks: | ||
- public | ||
deploy: | ||
replicas: 3 | ||
restart_policy: | ||
delay: 5s | ||
max_attempts: 5 | ||
command: ["-host", "toxiproxy", "-port", "18811", "-verb", "post", "-rate", "1"] | ||
|
||
reader: | ||
image: iskorotkov/chaos-client:latest | ||
depends_on: | ||
- server | ||
- toxiproxy | ||
networks: | ||
- public | ||
deploy: | ||
restart_policy: | ||
delay: 5s | ||
max_attempts: 5 | ||
command: ["-host", "toxiproxy", "-port", "18811", "-verb", "get", "-rate", "1"] | ||
|
||
toxiproxy: | ||
image: shopify/toxiproxy:2.1.4 | ||
hostname: toxiproxy | ||
networks: | ||
- public | ||
- private | ||
|
||
backend: | ||
image: iskorotkov/chaos-backend-toxiproxy:latest | ||
hostname: backend | ||
depends_on: | ||
- toxiproxy | ||
- server | ||
networks: | ||
- private | ||
deploy: | ||
restart_policy: | ||
delay: 5s | ||
max_attempts: 5 | ||
command: ["-tp_host", "toxiproxy", "-host", "server", "-listen", "18811", "-upstream", "8811"] | ||
|
||
networks: | ||
public: | ||
driver: overlay | ||
private: | ||
driver: overlay |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module github.com/iskorotkov/chaos-backend-toxiproxy | ||
|
||
go 1.15 | ||
|
||
require ( | ||
github.com/Shopify/toxiproxy v2.1.4+incompatible | ||
github.com/gorilla/mux v1.8.0 // indirect | ||
github.com/sirupsen/logrus v1.7.0 // indirect | ||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
github.com/Shopify/toxiproxy v2.1.4+incompatible h1:TKdv8HiTLgE5wdJuEML90aBgNWsokNbMijUGhmcoBJc= | ||
github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI= | ||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= | ||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= | ||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= | ||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"github.com/Shopify/toxiproxy/client" | ||
"time" | ||
) | ||
|
||
var tpHost = flag.String("tp_host", "localhost", "Toxiproxy host") | ||
var tpPort = flag.Int("tp_port", 8474, "Toxiproxy port") | ||
|
||
var host = flag.String("host", "localhost", "Host that will be proxied") | ||
var listenPort = flag.Int("listen", 18811, "Listen port for Toxiproxy") | ||
var upstreamPort = flag.Int("upstream", 8811, "Upstream port for Toxiproxy") | ||
|
||
func main() { | ||
flag.Parse() | ||
|
||
client := toxiproxy.NewClient(fmt.Sprintf("%v:%v", *tpHost, *tpPort)) | ||
proxy, err := client.CreateProxy("server", fmt.Sprintf(":%v", *listenPort), fmt.Sprintf("%v:%v", *host, *upstreamPort)) | ||
if err != nil { | ||
fmt.Println("Failed to create proxy") | ||
panic(err) | ||
} | ||
defer func() { | ||
_ = proxy.Delete() | ||
}() | ||
|
||
_, err = proxy.AddToxic("latency_down", "latency", "", 1.0, toxiproxy.Attributes{ | ||
"latency": 1000, | ||
}) | ||
if err != nil { | ||
fmt.Println("Error occurred while adding toxic") | ||
panic(err) | ||
} | ||
|
||
ch := time.After(time.Hour) | ||
<-ch | ||
} |