-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
215 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
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,29 @@ | ||
packages: | ||
- name: app | ||
type: go | ||
srcs: | ||
- "**/*.go" | ||
- "go.mod" | ||
- "go.sum" | ||
deps: | ||
- components/common-go:lib | ||
env: | ||
- CGO_ENABLED=0 | ||
- GOOS=linux | ||
config: | ||
packaging: app | ||
- name: docker | ||
type: docker | ||
deps: | ||
- :app | ||
argdeps: | ||
- imageRepoBase | ||
config: | ||
buildArgs: | ||
VERSION: ${version} | ||
dockerfile: leeway.Dockerfile | ||
metadata: | ||
helm-component: toxic-config | ||
image: | ||
- ${imageRepoBase}/toxic-config:${version} | ||
- ${imageRepoBase}/toxic-config:commit-${__git_commit} |
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 @@ | ||
# toxic-config | ||
|
||
Configures a given [Toxiproxy](https://github.com/Shopify/toxiproxy) proxy with a latency toxic. | ||
|
||
For example, with a Toxiproxy instance running on `localhost:8474` with a proxy called `mysql` configured: | ||
|
||
``` | ||
go run . --proxy mysql --latency=1000 --jitter=250 | ||
``` | ||
|
||
will configure the `mysql` proxy with a [latency toxic](https://github.com/Shopify/toxiproxy#latency) with `latency` and `jitter` set to the provided values. | ||
|
||
`toxic-config` is intended to run as a sidecar container in a Kubernetes pod alongside the Toxiproxy instance to be configured. |
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,65 @@ | ||
module github.com/gitpod-io/gitpod/toxic-config | ||
|
||
go 1.19 | ||
|
||
require ( | ||
github.com/Shopify/toxiproxy/v2 v2.5.0 | ||
github.com/gitpod-io/gitpod/common-go v0.0.0-00010101000000-000000000000 | ||
) | ||
|
||
require ( | ||
github.com/sirupsen/logrus v1.8.1 // indirect | ||
golang.org/x/sys v0.0.0-20220909162455-aba9fc2a8ff2 // indirect | ||
) | ||
|
||
replace github.com/gitpod-io/gitpod/common-go => ../common-go // leeway | ||
|
||
replace k8s.io/api => k8s.io/api v0.24.4 // leeway indirect from components/common-go:lib | ||
|
||
replace k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.24.4 // leeway indirect from components/common-go:lib | ||
|
||
replace k8s.io/apimachinery => k8s.io/apimachinery v0.24.4 // leeway indirect from components/common-go:lib | ||
|
||
replace k8s.io/apiserver => k8s.io/apiserver v0.24.4 // leeway indirect from components/common-go:lib | ||
|
||
replace k8s.io/cli-runtime => k8s.io/cli-runtime v0.24.4 // leeway indirect from components/common-go:lib | ||
|
||
replace k8s.io/client-go => k8s.io/client-go v0.24.4 // leeway indirect from components/common-go:lib | ||
|
||
replace k8s.io/cloud-provider => k8s.io/cloud-provider v0.24.4 // leeway indirect from components/common-go:lib | ||
|
||
replace k8s.io/cluster-bootstrap => k8s.io/cluster-bootstrap v0.24.4 // leeway indirect from components/common-go:lib | ||
|
||
replace k8s.io/code-generator => k8s.io/code-generator v0.24.4 // leeway indirect from components/common-go:lib | ||
|
||
replace k8s.io/component-base => k8s.io/component-base v0.24.4 // leeway indirect from components/common-go:lib | ||
|
||
replace k8s.io/cri-api => k8s.io/cri-api v0.24.4 // leeway indirect from components/common-go:lib | ||
|
||
replace k8s.io/csi-translation-lib => k8s.io/csi-translation-lib v0.24.4 // leeway indirect from components/common-go:lib | ||
|
||
replace k8s.io/kube-aggregator => k8s.io/kube-aggregator v0.24.4 // leeway indirect from components/common-go:lib | ||
|
||
replace k8s.io/kube-controller-manager => k8s.io/kube-controller-manager v0.24.4 // leeway indirect from components/common-go:lib | ||
|
||
replace k8s.io/kube-proxy => k8s.io/kube-proxy v0.24.4 // leeway indirect from components/common-go:lib | ||
|
||
replace k8s.io/kube-scheduler => k8s.io/kube-scheduler v0.24.4 // leeway indirect from components/common-go:lib | ||
|
||
replace k8s.io/kubelet => k8s.io/kubelet v0.24.4 // leeway indirect from components/common-go:lib | ||
|
||
replace k8s.io/legacy-cloud-providers => k8s.io/legacy-cloud-providers v0.24.4 // leeway indirect from components/common-go:lib | ||
|
||
replace k8s.io/metrics => k8s.io/metrics v0.24.4 // leeway indirect from components/common-go:lib | ||
|
||
replace k8s.io/sample-apiserver => k8s.io/sample-apiserver v0.24.4 // leeway indirect from components/common-go:lib | ||
|
||
replace k8s.io/component-helpers => k8s.io/component-helpers v0.24.4 // leeway indirect from components/common-go:lib | ||
|
||
replace k8s.io/controller-manager => k8s.io/controller-manager v0.24.4 // leeway indirect from components/common-go:lib | ||
|
||
replace k8s.io/kubectl => k8s.io/kubectl v0.24.4 // leeway indirect from components/common-go:lib | ||
|
||
replace k8s.io/mount-utils => k8s.io/mount-utils v0.24.4 // leeway indirect from components/common-go:lib | ||
|
||
replace k8s.io/pod-security-admission => k8s.io/pod-security-admission v0.24.4 // leeway indirect from components/common-go:lib |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,22 @@ | ||
# Copyright (c) 2022 Gitpod GmbH. All rights reserved. | ||
# Licensed under the GNU Affero General Public License (AGPL). | ||
# See License-AGPL.txt in the project root for license information. | ||
|
||
FROM alpine:3.16 | ||
|
||
# Ensure latest packages are present, like security updates. | ||
RUN apk upgrade --no-cache \ | ||
&& apk add --no-cache ca-certificates | ||
|
||
RUN adduser -S -D -H -h /app -u 1000 appuser | ||
COPY components-toxic-config--app/toxic-config /app/toxic-config | ||
RUN chown -R appuser /app | ||
|
||
USER appuser | ||
|
||
ARG __GIT_COMMIT | ||
ARG VERSION | ||
|
||
ENV GITPOD_BUILD_GIT_COMMIT=${__GIT_COMMIT} | ||
ENV GITPOD_BUILD_VERSION=${VERSION} | ||
ENTRYPOINT [ "/app/toxic-config" ] |
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,69 @@ | ||
// Copyright (c) 2022 Gitpod GmbH. All rights reserved. | ||
// Licensed under the GNU Affero General Public License (AGPL). | ||
// See License-AGPL.txt in the project root for license information. | ||
|
||
package main | ||
|
||
import ( | ||
"flag" | ||
"time" | ||
|
||
"github.com/gitpod-io/gitpod/common-go/log" | ||
|
||
toxiproxy "github.com/Shopify/toxiproxy/v2/client" | ||
) | ||
|
||
var ( | ||
proxyName string | ||
latency int | ||
jitter int | ||
wait bool | ||
) | ||
|
||
func main() { | ||
flag.StringVar(&proxyName, "proxy", "mysql", "the name of the proxy to which latency should be added") | ||
flag.IntVar(&latency, "latency", 1000, "latency in milliseconds") | ||
flag.IntVar(&jitter, "jitter", 250, "jitter in milliseconds") | ||
flag.BoolVar(&wait, "wait", false, "whether the process should wait indefinitely after running") | ||
|
||
flag.Parse() | ||
|
||
client := toxiproxy.NewClient(":8474") | ||
|
||
var ( | ||
proxies map[string]*toxiproxy.Proxy | ||
err error | ||
) | ||
for { | ||
proxies, err = client.Proxies() | ||
if err != nil { | ||
log.WithError(err).Print("Failed to list proxies") | ||
log.Println("Retrying in 1s...") | ||
time.Sleep(1 * time.Second) | ||
} else { | ||
break | ||
} | ||
} | ||
|
||
proxy, ok := proxies[proxyName] | ||
if !ok { | ||
log.Fatalf("Failed to find proxy %q", proxyName) | ||
} | ||
|
||
toxic, err := proxy.AddToxic( | ||
"latency", | ||
"latency", | ||
"downstream", | ||
1.0, | ||
toxiproxy.Attributes{"latency": latency, "jitter": jitter}, | ||
) | ||
if err != nil { | ||
log.Fatalf("Failed to add toxic: %s", err) | ||
} | ||
|
||
log.Printf("Toxic added: %s", toxic.Name) | ||
|
||
if wait { | ||
select {} | ||
} | ||
} |