Skip to content

Commit 625f05b

Browse files
Andrew Farriesroboquat
Andrew Farries
authored andcommitted
Add toxic-config component
1 parent 956c979 commit 625f05b

File tree

7 files changed

+215
-0
lines changed

7 files changed

+215
-0
lines changed

components/BUILD.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ packages:
6666
- components/server:docker
6767
- components/service-waiter:docker
6868
- components/supervisor:docker
69+
- components/toxic-config:docker
6970
- components/installation-telemetry:docker
7071
- components/workspacekit:docker
7172
- components/ws-daemon:docker
@@ -119,6 +120,7 @@ packages:
119120
- components/service-waiter:app
120121
- components/supervisor:app
121122
- components/supervisor/frontend:app
123+
- components/toxic-config:app
122124
- components/installation-telemetry:app
123125
- components/workspacekit:app
124126
- components/ws-daemon:app

components/toxic-config/BUILD.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
packages:
2+
- name: app
3+
type: go
4+
srcs:
5+
- "**/*.go"
6+
- "go.mod"
7+
- "go.sum"
8+
deps:
9+
- components/common-go:lib
10+
env:
11+
- CGO_ENABLED=0
12+
- GOOS=linux
13+
config:
14+
packaging: app
15+
- name: docker
16+
type: docker
17+
deps:
18+
- :app
19+
argdeps:
20+
- imageRepoBase
21+
config:
22+
buildArgs:
23+
VERSION: ${version}
24+
dockerfile: leeway.Dockerfile
25+
metadata:
26+
helm-component: toxic-config
27+
image:
28+
- ${imageRepoBase}/toxic-config:${version}
29+
- ${imageRepoBase}/toxic-config:commit-${__git_commit}

components/toxic-config/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# toxic-config
2+
3+
Configures a given [Toxiproxy](https://github.com/Shopify/toxiproxy) proxy with a latency toxic.
4+
5+
For example, with a Toxiproxy instance running on `localhost:8474` with a proxy called `mysql` configured:
6+
7+
```
8+
go run . --proxy mysql --latency=1000 --jitter=250
9+
```
10+
11+
will configure the `mysql` proxy with a [latency toxic](https://github.com/Shopify/toxiproxy#latency) with `latency` and `jitter` set to the provided values.
12+
13+
`toxic-config` is intended to run as a sidecar container in a Kubernetes pod alongside the Toxiproxy instance to be configured.

components/toxic-config/go.mod

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
module github.com/gitpod-io/gitpod/toxic-config
2+
3+
go 1.19
4+
5+
require (
6+
github.com/Shopify/toxiproxy/v2 v2.5.0
7+
github.com/gitpod-io/gitpod/common-go v0.0.0-00010101000000-000000000000
8+
)
9+
10+
require (
11+
github.com/sirupsen/logrus v1.8.1 // indirect
12+
golang.org/x/sys v0.0.0-20220909162455-aba9fc2a8ff2 // indirect
13+
)
14+
15+
replace github.com/gitpod-io/gitpod/common-go => ../common-go // leeway
16+
17+
replace k8s.io/api => k8s.io/api v0.24.4 // leeway indirect from components/common-go:lib
18+
19+
replace k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.24.4 // leeway indirect from components/common-go:lib
20+
21+
replace k8s.io/apimachinery => k8s.io/apimachinery v0.24.4 // leeway indirect from components/common-go:lib
22+
23+
replace k8s.io/apiserver => k8s.io/apiserver v0.24.4 // leeway indirect from components/common-go:lib
24+
25+
replace k8s.io/cli-runtime => k8s.io/cli-runtime v0.24.4 // leeway indirect from components/common-go:lib
26+
27+
replace k8s.io/client-go => k8s.io/client-go v0.24.4 // leeway indirect from components/common-go:lib
28+
29+
replace k8s.io/cloud-provider => k8s.io/cloud-provider v0.24.4 // leeway indirect from components/common-go:lib
30+
31+
replace k8s.io/cluster-bootstrap => k8s.io/cluster-bootstrap v0.24.4 // leeway indirect from components/common-go:lib
32+
33+
replace k8s.io/code-generator => k8s.io/code-generator v0.24.4 // leeway indirect from components/common-go:lib
34+
35+
replace k8s.io/component-base => k8s.io/component-base v0.24.4 // leeway indirect from components/common-go:lib
36+
37+
replace k8s.io/cri-api => k8s.io/cri-api v0.24.4 // leeway indirect from components/common-go:lib
38+
39+
replace k8s.io/csi-translation-lib => k8s.io/csi-translation-lib v0.24.4 // leeway indirect from components/common-go:lib
40+
41+
replace k8s.io/kube-aggregator => k8s.io/kube-aggregator v0.24.4 // leeway indirect from components/common-go:lib
42+
43+
replace k8s.io/kube-controller-manager => k8s.io/kube-controller-manager v0.24.4 // leeway indirect from components/common-go:lib
44+
45+
replace k8s.io/kube-proxy => k8s.io/kube-proxy v0.24.4 // leeway indirect from components/common-go:lib
46+
47+
replace k8s.io/kube-scheduler => k8s.io/kube-scheduler v0.24.4 // leeway indirect from components/common-go:lib
48+
49+
replace k8s.io/kubelet => k8s.io/kubelet v0.24.4 // leeway indirect from components/common-go:lib
50+
51+
replace k8s.io/legacy-cloud-providers => k8s.io/legacy-cloud-providers v0.24.4 // leeway indirect from components/common-go:lib
52+
53+
replace k8s.io/metrics => k8s.io/metrics v0.24.4 // leeway indirect from components/common-go:lib
54+
55+
replace k8s.io/sample-apiserver => k8s.io/sample-apiserver v0.24.4 // leeway indirect from components/common-go:lib
56+
57+
replace k8s.io/component-helpers => k8s.io/component-helpers v0.24.4 // leeway indirect from components/common-go:lib
58+
59+
replace k8s.io/controller-manager => k8s.io/controller-manager v0.24.4 // leeway indirect from components/common-go:lib
60+
61+
replace k8s.io/kubectl => k8s.io/kubectl v0.24.4 // leeway indirect from components/common-go:lib
62+
63+
replace k8s.io/mount-utils => k8s.io/mount-utils v0.24.4 // leeway indirect from components/common-go:lib
64+
65+
replace k8s.io/pod-security-admission => k8s.io/pod-security-admission v0.24.4 // leeway indirect from components/common-go:lib

components/toxic-config/go.sum

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Copyright (c) 2022 Gitpod GmbH. All rights reserved.
2+
# Licensed under the GNU Affero General Public License (AGPL).
3+
# See License-AGPL.txt in the project root for license information.
4+
5+
FROM alpine:3.16
6+
7+
# Ensure latest packages are present, like security updates.
8+
RUN apk upgrade --no-cache \
9+
&& apk add --no-cache ca-certificates
10+
11+
RUN adduser -S -D -H -h /app -u 1000 appuser
12+
COPY components-toxic-config--app/toxic-config /app/toxic-config
13+
RUN chown -R appuser /app
14+
15+
USER appuser
16+
17+
ARG __GIT_COMMIT
18+
ARG VERSION
19+
20+
ENV GITPOD_BUILD_GIT_COMMIT=${__GIT_COMMIT}
21+
ENV GITPOD_BUILD_VERSION=${VERSION}
22+
ENTRYPOINT [ "/app/toxic-config" ]

components/toxic-config/main.go

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
2+
// Licensed under the GNU Affero General Public License (AGPL).
3+
// See License-AGPL.txt in the project root for license information.
4+
5+
package main
6+
7+
import (
8+
"flag"
9+
"time"
10+
11+
"github.com/gitpod-io/gitpod/common-go/log"
12+
13+
toxiproxy "github.com/Shopify/toxiproxy/v2/client"
14+
)
15+
16+
var (
17+
proxyName string
18+
latency int
19+
jitter int
20+
wait bool
21+
)
22+
23+
func main() {
24+
flag.StringVar(&proxyName, "proxy", "mysql", "the name of the proxy to which latency should be added")
25+
flag.IntVar(&latency, "latency", 1000, "latency in milliseconds")
26+
flag.IntVar(&jitter, "jitter", 250, "jitter in milliseconds")
27+
flag.BoolVar(&wait, "wait", false, "whether the process should wait indefinitely after running")
28+
29+
flag.Parse()
30+
31+
client := toxiproxy.NewClient(":8474")
32+
33+
var (
34+
proxies map[string]*toxiproxy.Proxy
35+
err error
36+
)
37+
for {
38+
proxies, err = client.Proxies()
39+
if err != nil {
40+
log.WithError(err).Print("Failed to list proxies")
41+
log.Println("Retrying in 1s...")
42+
time.Sleep(1 * time.Second)
43+
} else {
44+
break
45+
}
46+
}
47+
48+
proxy, ok := proxies[proxyName]
49+
if !ok {
50+
log.Fatalf("Failed to find proxy %q", proxyName)
51+
}
52+
53+
toxic, err := proxy.AddToxic(
54+
"latency",
55+
"latency",
56+
"downstream",
57+
1.0,
58+
toxiproxy.Attributes{"latency": latency, "jitter": jitter},
59+
)
60+
if err != nil {
61+
log.Fatalf("Failed to add toxic: %s", err)
62+
}
63+
64+
log.Printf("Toxic added: %s", toxic.Name)
65+
66+
if wait {
67+
select {}
68+
}
69+
}

0 commit comments

Comments
 (0)