From ca8aacb39206d1a546bda26c16efdb1a57f6486d Mon Sep 17 00:00:00 2001 From: Andrew Farries Date: Sun, 6 Nov 2022 16:04:34 +0000 Subject: [PATCH 1/2] Add `toxic-config` component --- components/BUILD.yaml | 2 + components/toxic-config/BUILD.yaml | 29 ++++++++++ components/toxic-config/README.md | 13 +++++ components/toxic-config/go.mod | 65 +++++++++++++++++++++ components/toxic-config/go.sum | 15 +++++ components/toxic-config/leeway.Dockerfile | 22 ++++++++ components/toxic-config/main.go | 69 +++++++++++++++++++++++ 7 files changed, 215 insertions(+) create mode 100644 components/toxic-config/BUILD.yaml create mode 100644 components/toxic-config/README.md create mode 100644 components/toxic-config/go.mod create mode 100644 components/toxic-config/go.sum create mode 100644 components/toxic-config/leeway.Dockerfile create mode 100644 components/toxic-config/main.go diff --git a/components/BUILD.yaml b/components/BUILD.yaml index 97519062413d89..d9ee3c8b023997 100644 --- a/components/BUILD.yaml +++ b/components/BUILD.yaml @@ -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 @@ -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 diff --git a/components/toxic-config/BUILD.yaml b/components/toxic-config/BUILD.yaml new file mode 100644 index 00000000000000..a933e00bed28f6 --- /dev/null +++ b/components/toxic-config/BUILD.yaml @@ -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} diff --git a/components/toxic-config/README.md b/components/toxic-config/README.md new file mode 100644 index 00000000000000..e9c1521b9a7fd2 --- /dev/null +++ b/components/toxic-config/README.md @@ -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. diff --git a/components/toxic-config/go.mod b/components/toxic-config/go.mod new file mode 100644 index 00000000000000..29254c79406dc5 --- /dev/null +++ b/components/toxic-config/go.mod @@ -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 diff --git a/components/toxic-config/go.sum b/components/toxic-config/go.sum new file mode 100644 index 00000000000000..6926758dc23027 --- /dev/null +++ b/components/toxic-config/go.sum @@ -0,0 +1,15 @@ +github.com/Shopify/toxiproxy/v2 v2.5.0 h1:i4LPT+qrSlKNtQf5QliVjdP08GyAH8+BUIc9gT0eahc= +github.com/Shopify/toxiproxy/v2 v2.5.0/go.mod h1:yhM2epWtAmel9CB8r2+L+PCmhH6yH2pITaPAo7jxJl0= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE= +github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= +golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20220909162455-aba9fc2a8ff2 h1:wM1k/lXfpc5HdkJJyW9GELpd8ERGdnh8sMGL6Gzq3Ho= +golang.org/x/sys v0.0.0-20220909162455-aba9fc2a8ff2/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= diff --git a/components/toxic-config/leeway.Dockerfile b/components/toxic-config/leeway.Dockerfile new file mode 100644 index 00000000000000..d161ac0c563adf --- /dev/null +++ b/components/toxic-config/leeway.Dockerfile @@ -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" ] diff --git a/components/toxic-config/main.go b/components/toxic-config/main.go new file mode 100644 index 00000000000000..1e8c76eafb4947 --- /dev/null +++ b/components/toxic-config/main.go @@ -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 {} + } +} From bcd739d523627bffd48dee9e344f60d8b98dabe8 Mon Sep 17 00:00:00 2001 From: Andrew Farries Date: Mon, 7 Nov 2022 12:23:43 +0000 Subject: [PATCH 2/2] Add webapp as owner for `toxic-config` component --- .github/CODEOWNERS | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 4d3ca82d0f9699..d5a253d04bb9c8 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -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.