Skip to content

Commit 41190d9

Browse files
authored
Load/Chaos codegen (#2218)
* WIP: load/chaos codegen * remove old havoc * update go mods * Remove replace in generated go mod * remove old chaos templates, switch to wasp * fix lint and remove havoc linter CI * more cases, add default params, error when no uniq labels * correct k8s labelling * use default wasp test prefix * do not remove chaos experiments by default * remove replace * bump CVE packages * changesets * chaos&load codegen * fix copilot review
1 parent cd424f5 commit 41190d9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+2255
-1321
lines changed

.github/workflows/linters.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ jobs:
1313
- parrot
1414
- wasp
1515
- seth
16-
- havoc
1716
- k8s-test-runner
1817
- lib
1918
- tools/workflowresultparser

book/src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- [CLI](./framework/cli.md)
1313
- [Configuration](./framework/configuration.md)
1414
- [Debugging Tests](framework/components/debug.md)
15+
- [Generating Tests](framework/generate.md)
1516
- [Creating your own components](./developing/developing_components.md)
1617
- [Exposing Components](framework/components/state.md)
1718
- [Asserting Logs](./developing/asserting_logs.md)

book/src/framework/generate.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Generating Tests
2+
3+
Some types of tests may require a lot of boilerplate and configurability, for example load and chaos tests.
4+
5+
We provide code generation tool that help you to start with best practes in such cases.
6+
7+
All generators have `-h` or `--help` flag, please read the docs!

framework/.changeset/v0.11.8.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
- Usnet Docker Build Ctx and Filepath if `CTF_*_IMAGE` env vars are used
1+
- Usnet Docker Build Ctx and Filepath if `CTF_*_IMAGE` env vars are used

framework/.changeset/v0.11.9.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Chaos and Load codegen

framework/cmd/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ blockscout/services/blockscout-db-data
22
blockscout/services/logs
33
blockscout/services/redis-data
44
blockscout/services/stats-db-data
5+
wasp-self-test/
6+
wasp-test/

framework/cmd/main.go

Lines changed: 123 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/urfave/cli/v2"
1212

1313
"github.com/smartcontractkit/chainlink-testing-framework/framework"
14+
"github.com/smartcontractkit/chainlink-testing-framework/wasp"
1415
)
1516

1617
func main() {
@@ -19,6 +20,127 @@ func main() {
1920
Usage: "Chainlink Testing Framework CLI",
2021
UsageText: "'ctf' is a useful utility that can:\n- clean up test docker containers\n- modify test files\n- create a local observability stack with Grafana/Loki/Pyroscope",
2122
Commands: []*cli.Command{
23+
{
24+
Name: "gen",
25+
Aliases: []string{"g"},
26+
Usage: "Generates various test templates",
27+
Subcommands: []*cli.Command{
28+
{
29+
Name: "load",
30+
Aliases: []string{"l"},
31+
Usage: "Generates a load/chaos test template for Kubernetes namespace",
32+
Description: `Scans a Kubernetes namespace and generates load testing templates for discovered services.
33+
34+
Prerequisites:
35+
36+
Connect to K8s and don't forget to switch context first:
37+
kubectl config use-context <your_ctx>
38+
By default test sends data to a local CTF stack, see //TODO comments to change that, spin up the stack:
39+
ctf obs up
40+
41+
Usage:
42+
43+
Generate basic kill/latency tests:
44+
ctf gen k8s-load my-namespace
45+
With workload:
46+
ctf gen k8s-load -w my-namespace
47+
With workload and name:
48+
ctf gen k8s-load -w -n TestSomething my-namespace
49+
50+
Be aware that any TODO requires your attention before your run the final test!
51+
`,
52+
ArgsUsage: "--workload --name $name --output-dir $dir --module $go_mod_name [NAMESPACE]",
53+
Flags: []cli.Flag{
54+
&cli.StringFlag{
55+
Name: "name",
56+
Aliases: []string{"n"},
57+
Value: "TestGeneratedLoadChaos",
58+
Usage: "Test suite name",
59+
},
60+
&cli.StringFlag{
61+
Name: "output-dir",
62+
Aliases: []string{"o"},
63+
Value: "wasp-test",
64+
Usage: "Output directory for generated files",
65+
},
66+
&cli.StringFlag{
67+
Name: "module",
68+
Aliases: []string{"m"},
69+
Value: "github.com/smartcontractkit/chainlink-testing-framework/wasp-test",
70+
Usage: "Go module name for generated project",
71+
},
72+
&cli.BoolFlag{
73+
Name: "workload",
74+
Aliases: []string{"w"},
75+
Value: false,
76+
Usage: "Include workload generation in tests",
77+
},
78+
&cli.StringFlag{
79+
Name: "pod-label-key",
80+
Aliases: []string{"k"},
81+
Value: "app.kubernetes.io/instance",
82+
Usage: "Default unique pod key, read more here: https://kubernetes.io/docs/concepts/overview/working-with-objects/common-labels/",
83+
},
84+
&cli.StringFlag{
85+
Name: "latency-ms",
86+
Aliases: []string{"l"},
87+
Value: "300",
88+
Usage: "Default latency for delay experiments in milliseconds",
89+
},
90+
&cli.StringFlag{
91+
Name: "jitter-ms",
92+
Aliases: []string{"j"},
93+
Value: "100",
94+
Usage: "Default jitter for delay experiments in milliseconds",
95+
},
96+
},
97+
Action: func(c *cli.Context) error {
98+
if c.Args().Len() == 0 {
99+
return fmt.Errorf("Kubernetes namespace argument is required")
100+
}
101+
ns := c.Args().First()
102+
testSuiteName := c.String("name")
103+
podLabelKey := c.String("pod-label-key")
104+
latencyMs := c.Int("latency-ms")
105+
jitterMs := c.Int("jitter-ms")
106+
outputDir := c.String("output-dir")
107+
moduleName := c.String("module")
108+
includeWorkload := c.Bool("workload")
109+
framework.L.Info().
110+
Str("SuiteName", testSuiteName).
111+
Str("OutputDir", outputDir).
112+
Str("GoModuleName", moduleName).
113+
Bool("Workload", includeWorkload).
114+
Msg("Generating load&chaos test template")
115+
116+
k8sClient, err := wasp.NewK8s()
117+
if err != nil {
118+
return fmt.Errorf("failed to create K8s client")
119+
}
120+
121+
cg, err := wasp.NewLoadTestGenBuilder(k8sClient, ns).
122+
TestSuiteName(testSuiteName).
123+
UniqPodLabelKey(podLabelKey).
124+
Latency(latencyMs).
125+
Jitter(jitterMs).
126+
Workload(includeWorkload).
127+
OutputDir(outputDir).
128+
GoModName(moduleName).
129+
Build()
130+
if err != nil {
131+
return fmt.Errorf("failed to create codegen: %w", err)
132+
}
133+
if err := cg.Read(); err != nil {
134+
return fmt.Errorf("failed to scan namespace: %w", err)
135+
}
136+
if err := cg.Write(); err != nil {
137+
return fmt.Errorf("failed to generate module: %w", err)
138+
}
139+
return nil
140+
},
141+
},
142+
},
143+
},
22144
{
23145
Name: "config",
24146
Aliases: []string{"c"},
@@ -206,7 +328,7 @@ func PrettyPrintTOML(inputFile string, outputFile string) error {
206328
}
207329

208330
//nolint
209-
err = os.WriteFile(outputFile, []byte(dumpData), 0644)
331+
err = os.WriteFile(outputFile, []byte(dumpData), 0o644)
210332
if err != nil {
211333
return fmt.Errorf("error writing to output file: %v", err)
212334
}

framework/components/dockercompose/go.mod

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ require (
1515
github.com/smartcontractkit/freeport v0.1.2
1616
github.com/testcontainers/testcontainers-go v0.37.0
1717
github.com/testcontainers/testcontainers-go/modules/compose v0.37.0
18-
golang.org/x/oauth2 v0.25.0
18+
golang.org/x/oauth2 v0.32.0
1919
)
2020

2121
require (
@@ -80,17 +80,17 @@ require (
8080
github.com/go-logr/logr v1.4.2 // indirect
8181
github.com/go-logr/stdr v1.2.2 // indirect
8282
github.com/go-ole/go-ole v1.3.0 // indirect
83-
github.com/go-openapi/jsonpointer v0.19.6 // indirect
84-
github.com/go-openapi/jsonreference v0.20.2 // indirect
85-
github.com/go-openapi/swag v0.22.4 // indirect
83+
github.com/go-openapi/jsonpointer v0.21.0 // indirect
84+
github.com/go-openapi/jsonreference v0.21.0 // indirect
85+
github.com/go-openapi/swag v0.23.0 // indirect
8686
github.com/go-playground/locales v0.14.1 // indirect
8787
github.com/go-playground/universal-translator v0.18.1 // indirect
8888
github.com/go-playground/validator/v10 v10.22.1 // indirect
89-
github.com/go-resty/resty/v2 v2.15.3 // indirect
89+
github.com/go-resty/resty/v2 v2.16.3 // indirect
9090
github.com/go-viper/mapstructure/v2 v2.0.0 // indirect
9191
github.com/gofrs/flock v0.12.1 // indirect
9292
github.com/gogo/protobuf v1.3.2 // indirect
93-
github.com/golang-jwt/jwt/v5 v5.2.2 // indirect
93+
github.com/golang-jwt/jwt/v5 v5.3.0 // indirect
9494
github.com/golang/protobuf v1.5.4 // indirect
9595
github.com/google/gnostic-models v0.6.8 // indirect
9696
github.com/google/go-cmp v0.7.0 // indirect
@@ -99,13 +99,12 @@ require (
9999
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
100100
github.com/google/uuid v1.6.0 // indirect
101101
github.com/gorilla/mux v1.8.1 // indirect
102-
github.com/gorilla/websocket v1.5.1 // indirect
102+
github.com/gorilla/websocket v1.5.3 // indirect
103103
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 // indirect
104104
github.com/hashicorp/errwrap v1.1.0 // indirect
105105
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
106106
github.com/hashicorp/go-multierror v1.1.1 // indirect
107107
github.com/hashicorp/go-version v1.7.0 // indirect
108-
github.com/imdario/mergo v0.3.16 // indirect
109108
github.com/in-toto/in-toto-golang v0.5.0 // indirect
110109
github.com/inconshreveable/mousetrap v1.1.0 // indirect
111110
github.com/inhies/go-bytesize v0.0.0-20220417184213-4913239db9cf // indirect
@@ -115,7 +114,7 @@ require (
115114
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
116115
github.com/klauspost/compress v1.18.0 // indirect
117116
github.com/leodido/go-urn v1.4.0 // indirect
118-
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
117+
github.com/lufia/plan9stats v0.0.0-20240226150601-1dcf7310316a // indirect
119118
github.com/magiconair/properties v1.8.10 // indirect
120119
github.com/mailru/easyjson v0.7.7 // indirect
121120
github.com/mattn/go-colorable v0.1.13 // indirect
@@ -125,13 +124,13 @@ require (
125124
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect
126125
github.com/miekg/pkcs11 v1.1.1 // indirect
127126
github.com/mitchellh/hashstructure/v2 v2.0.2 // indirect
128-
github.com/mitchellh/mapstructure v1.5.0 // indirect
127+
github.com/mitchellh/mapstructure v1.5.1-0.20220423185008-bf980b35cac4 // indirect
129128
github.com/moby/buildkit v0.20.1 // indirect
130129
github.com/moby/docker-image-spec v1.3.1 // indirect
131130
github.com/moby/go-archive v0.1.0 // indirect
132131
github.com/moby/locker v1.0.1 // indirect
133132
github.com/moby/patternmatcher v0.6.0 // indirect
134-
github.com/moby/spdystream v0.4.0 // indirect
133+
github.com/moby/spdystream v0.5.0 // indirect
135134
github.com/moby/sys/atomicwriter v0.1.0 // indirect
136135
github.com/moby/sys/capability v0.4.0 // indirect
137136
github.com/moby/sys/mountinfo v0.7.2 // indirect
@@ -152,10 +151,10 @@ require (
152151
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
153152
github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 // indirect
154153
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
155-
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
156-
github.com/prometheus/client_golang v1.20.5 // indirect
154+
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect
155+
github.com/prometheus/client_golang v1.21.0-rc.0 // indirect
157156
github.com/prometheus/client_model v0.6.1 // indirect
158-
github.com/prometheus/common v0.55.0 // indirect
157+
github.com/prometheus/common v0.62.0 // indirect
159158
github.com/prometheus/procfs v0.15.1 // indirect
160159
github.com/r3labs/sse v0.0.0-20210224172625-26fe804710bc // indirect
161160
github.com/rivo/uniseg v0.4.7 // indirect
@@ -171,8 +170,8 @@ require (
171170
github.com/stretchr/testify v1.10.0 // indirect
172171
github.com/theupdateframework/notary v0.7.0 // indirect
173172
github.com/tilt-dev/fsnotify v1.4.8-0.20220602155310-fff9c274a375 // indirect
174-
github.com/tklauser/go-sysconf v0.3.12 // indirect
175-
github.com/tklauser/numcpus v0.6.1 // indirect
173+
github.com/tklauser/go-sysconf v0.3.13 // indirect
174+
github.com/tklauser/numcpus v0.7.0 // indirect
176175
github.com/tonistiigi/dchapes-mode v0.0.0-20241001053921-ca0759fec205 // indirect
177176
github.com/tonistiigi/fsutil v0.0.0-20250113203817-b14e27f4135a // indirect
178177
github.com/tonistiigi/go-csvvalue v0.0.0-20240710180619-ddb21b71c0b4 // indirect
@@ -187,8 +186,8 @@ require (
187186
github.com/zclconf/go-cty v1.16.0 // indirect
188187
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
189188
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.56.0 // indirect
190-
go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.56.0 // indirect
191-
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.56.0 // indirect
189+
go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.59.0 // indirect
190+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.59.0 // indirect
192191
go.opentelemetry.io/otel v1.35.0 // indirect
193192
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.31.0 // indirect
194193
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.31.0 // indirect
@@ -203,30 +202,30 @@ require (
203202
go.uber.org/mock v0.5.0 // indirect
204203
go.uber.org/multierr v1.11.0 // indirect
205204
golang.org/x/crypto v0.39.0 // indirect
206-
golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f // indirect
205+
golang.org/x/exp v0.0.0-20250106191152-7588d65b2ba8 // indirect
207206
golang.org/x/net v0.40.0 // indirect
208207
golang.org/x/sync v0.15.0 // indirect
209208
golang.org/x/sys v0.33.0 // indirect
210209
golang.org/x/term v0.32.0 // indirect
211210
golang.org/x/text v0.26.0 // indirect
212-
golang.org/x/time v0.6.0 // indirect
213-
google.golang.org/genproto/googleapis/api v0.0.0-20250106144421-5f5ef82da422 // indirect
214-
google.golang.org/genproto/googleapis/rpc v0.0.0-20250115164207-1a7da9e5054f // indirect
211+
golang.org/x/time v0.10.0 // indirect
212+
google.golang.org/genproto/googleapis/api v0.0.0-20250124145028-65684f501c47 // indirect
213+
google.golang.org/genproto/googleapis/rpc v0.0.0-20250207221924-e9438ea467c6 // indirect
215214
google.golang.org/grpc v1.71.0 // indirect
216-
google.golang.org/protobuf v1.36.4 // indirect
215+
google.golang.org/protobuf v1.36.5 // indirect
217216
gopkg.in/cenkalti/backoff.v1 v1.1.0 // indirect
217+
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
218218
gopkg.in/inf.v0 v0.9.1 // indirect
219219
gopkg.in/ini.v1 v1.67.0 // indirect
220-
gopkg.in/yaml.v2 v2.4.0 // indirect
221220
gopkg.in/yaml.v3 v3.0.1 // indirect
222-
k8s.io/api v0.31.2 // indirect
223-
k8s.io/apimachinery v0.31.2 // indirect
224-
k8s.io/client-go v0.31.2 // indirect
221+
k8s.io/api v0.32.2 // indirect
222+
k8s.io/apimachinery v0.32.2 // indirect
223+
k8s.io/client-go v0.32.2 // indirect
225224
k8s.io/klog/v2 v2.130.1 // indirect
226-
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 // indirect
227-
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 // indirect
228-
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
229-
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
225+
k8s.io/kube-openapi v0.0.0-20241105132330-32ad38e42d3f // indirect
226+
k8s.io/utils v0.0.0-20241104163129-6fe5fd82f078 // indirect
227+
sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 // indirect
228+
sigs.k8s.io/structured-merge-diff/v4 v4.4.2 // indirect
230229
sigs.k8s.io/yaml v1.4.0 // indirect
231230
tags.cncf.io/container-device-interface v1.0.1 // indirect
232231
)

0 commit comments

Comments
 (0)