Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add toxic-config component to configure Toxiproxy instances with latency toxics #14473

Merged
merged 2 commits into from
Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
/components/image-builder-mk3 @gitpod-io/engineering-workspace
/components/installation-telemetry @gitpod-io/engineering-delivery-operations-experience
/components/kots-config-check @gitpod-io/engineering-delivery-operations-experience
/components/toxic-config @gitpod-io/engineering-webapp
/install @gitpod-io/engineering-delivery-operations-experience
/install/installer @gitpod-io/engineering-delivery-operations-experience
# For testdata a single review from anyone who is allowed to review PRs is sufficent.
Expand Down
2 changes: 2 additions & 0 deletions components/BUILD.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ packages:
- components/server:docker
- components/service-waiter:docker
- components/supervisor:docker
- components/toxic-config:docker
- components/installation-telemetry:docker
- components/workspacekit:docker
- components/ws-daemon:docker
Expand Down Expand Up @@ -119,6 +120,7 @@ packages:
- components/service-waiter:app
- components/supervisor:app
- components/supervisor/frontend:app
- components/toxic-config:app
- components/installation-telemetry:app
- components/workspacekit:app
- components/ws-daemon:app
Expand Down
29 changes: 29 additions & 0 deletions components/toxic-config/BUILD.yaml
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}
13 changes: 13 additions & 0 deletions components/toxic-config/README.md
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.
65 changes: 65 additions & 0 deletions components/toxic-config/go.mod
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
15 changes: 15 additions & 0 deletions components/toxic-config/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions components/toxic-config/leeway.Dockerfile
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" ]
69 changes: 69 additions & 0 deletions components/toxic-config/main.go
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 {}
}
}