Skip to content

Commit 9acf8c4

Browse files
committed
Merge branch 'main' into maturity-model
2 parents fa91378 + 1778cb7 commit 9acf8c4

34 files changed

+78
-1058
lines changed

.gitignore

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,7 @@ suite/remote_runner_config.yaml
4646
*.csv
4747

4848
# docs
49-
docs/_site/
50-
docs/.sass-cache/
51-
docs/Gemfile.lock
49+
book/docs/
5250

5351
dist/
5452

@@ -78,4 +76,4 @@ __debug*
7876
.tool-versions
7977

8078
import_keys_test.go
81-
tag.py
79+
tag.py

book/README.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1-
## MDBook
2-
Install [mdbook](https://github.com/rust-lang/mdBook)
3-
```
1+
# Chainlink Testing Framework Docs
2+
3+
We use [mdBook](https://github.com/rust-lang/mdBook) for our docs. They can be found [here](https://smartcontractkit.github.io/chainlink-testing-framework/).
4+
5+
## Development
6+
7+
First [install Rust](https://doc.rust-lang.org/cargo/getting-started/installation.html), then [mdbook](https://github.com/rust-lang/mdBook).
8+
9+
```sh
10+
# Install mdBook
411
cargo install mdbook && \
512
cargo install mdbook-alerts && \
613
cargo install mdbook-cmdrun
7-
```
8-
9-
Run it locally
10-
```
14+
# Run the mdBook
1115
make run
1216
```
13-
Open your browser [here](http://localhost:9999/)
1417

15-
GitHub hosted [version](https://smartcontractkit.github.io/chainlink-testing-framework/overview.html)
18+
Visit [localhost:9999](http://localhost:9999) to see your local version.

book/src/libs/havoc.md

Lines changed: 19 additions & 195 deletions
Original file line numberDiff line numberDiff line change
@@ -1,211 +1,35 @@
1-
## Havoc
1+
# Havoc
22

3-
The `havoc` package is a Go library designed to facilitate chaos testing within Kubernetes environments using Chaos Mesh. It offers a structured way to define, execute, and manage chaos experiments as code, directly integrated into Go applications or testing suites. This package simplifies the creation and control of Chaos Mesh experiments, including network chaos, pod failures, and stress testing on Kubernetes clusters.
3+
[![Go Reference](https://pkg.go.dev/badge/github.com/smartcontractkit/chainlink-testing-framework/havoc.svg)](https://pkg.go.dev/github.com/smartcontractkit/chainlink-testing-framework/havoc)
44

5-
### Features
5+
The `havoc` package is designed to facilitate chaos testing within [Kubernetes](https://kubernetes.io/) environments using [Chaos Mesh](https://chaos-mesh.org/). It offers a structured way to define, execute, and manage chaos experiments as code, directly integrated into Go applications or testing suites, simplifying the creation and control of Chaos Mesh experiments.
66

7-
- **Chaos Object Management:** Easily create, update, pause, resume, and delete chaos experiments using Go structures and methods.
8-
- **Lifecycle Hooks:** Utilize chaos listeners to hook into lifecycle events of chaos experiments, such as creation, start, pause, resume, and finish.
9-
- **Support for Various Chaos Experiments:** Create and manage different types of chaos experiments like NetworkChaos, IOChaos, StressChaos, PodChaos, and HTTPChaos.
10-
- **Chaos Experiment Status Monitoring:** Monitor and react to the status of chaos experiments programmatically.
7+
## Features
118

12-
### Installation
9+
- **Chaos Object Management:** Create, update, pause, resume, and delete chaos experiments using Go structures and methods.
10+
- **Lifecycle Hooks:** Utilize chaos listeners to hook into the lifecycle of chaos experiments.
11+
- **Different Experiments:** Create and manage different types of chaos experiments to affect network, IO, K8s pods, and more.
12+
- **Active Monitoring:** Monitor and react to the status of chaos experiments programmatically.
1313

14-
To use `havoc` in your project, ensure you have a Go environment setup. Then, install the package using go get:
14+
## Requirements
1515

16-
```
17-
go get -u github.com/smartcontractkit/chainlink-testing-framework/havoc
18-
```
16+
- [Go](https://go.dev/)
17+
- A Kubernetes cluster with [Chaos Mesh installed](https://chaos-mesh.org/docs/quick-start/)
1918

20-
Ensure your Kubernetes cluster is accessible and that you have Chaos Mesh installed and configured.
19+
## Active Monitoring
2120

22-
### Monitoring and Observability in Chaos Experiments
21+
`havoc` enhances chaos experiment observability through structured logging and Grafana annotations by implementing the [ChaosListener](https://pkg.go.dev/github.com/smartcontractkit/chainlink-testing-framework/havoc#ChaosListener) interface.
2322

24-
`havoc` enhances chaos experiment observability through structured logging and Grafana annotations, facilitated by implementing the ChaosListener interface. This approach allows for detailed monitoring, debugging, and visual representation of chaos experiments' impact.
23+
The [ChaosLogger](https://pkg.go.dev/github.com/smartcontractkit/chainlink-testing-framework/havoc#ChaosLogger) is the default implementation. It uses [zerolog](https://github.com/rs/zerolog) to provide structured, queryable logging of chaos events. It automatically logs key lifecycle events such as creation, start, pause, and termination of chaos experiments with detailed contextual information.
2524

26-
#### Structured Logging with ChaosLogger
25+
### Grafana Annotations
2726

28-
`ChaosLogger` leverages the zerolog library to provide structured, queryable logging of chaos events. It automatically logs key lifecycle events such as creation, start, pause, and termination of chaos experiments, including detailed contextual information.
27+
We recommend using [Grafana dashboards](https://grafana.com/) to monitor your chaos experiments, and provide the [SingleLineGrafanaAnnotator](https://pkg.go.dev/github.com/smartcontractkit/chainlink-testing-framework/havoc#SingleLineGrafanaAnnotator), a `ChaosListener` that annotates dashboards with chaos experiment events so you can see in real time what your chaos experiment is doing.
2928

30-
Instantiate `ChaosLogger` and register it as a listener to your chaos experiments:
29+
You can also use the [RangeGrafanaAnnotator](https://pkg.go.dev/github.com/smartcontractkit/chainlink-testing-framework/havoc#RangeGrafanaAnnotator) to show the full range of a chaos event's duration rather than a single line.
3130

32-
```
33-
logger := havoc.NewChaosLogger()
34-
chaos.AddListener(logger)
35-
```
36-
37-
### Default package logger
38-
39-
`havoc/logger.go` contains default `Logger` instance for the package.
40-
41-
#### Visual Monitoring with Grafana Annotations
42-
43-
`SingleLineGrafanaAnnotator` is a `ChaosListener` that annotates Grafana dashboards with chaos experiment events. This visual representation helps correlate chaos events with their effects on system metrics and logs.
44-
45-
Initialize `SingleLineGrafanaAnnotator` with your Grafana instance details and register it alongside `ChaosLogger`:
46-
47-
```golang
48-
annotator := havoc.NewSingleLineGrafanaAnnotator(
49-
"http://grafana-instance.com",
50-
"grafana-access-token",
51-
"dashboard-uid",
52-
)
53-
chaos.AddListener(annotator)
54-
```
55-
56-
### Creating a Chaos Experiment
31+
## Creating a Chaos Experiment
5732

5833
To create a chaos experiment, define the chaos object options, initialize a chaos experiment with NewChaos, and then call Create to start the experiment.
5934

60-
Here is an example of creating and starting a PodChaos experiment:
61-
62-
```golang
63-
package main
64-
65-
import (
66-
"context"
67-
"github.com/smartcontractkit/chainlink-testing-framework/havoc"
68-
"github.com/chaos-mesh/chaos-mesh/api/v1alpha1"
69-
"sigs.k8s.io/controller-runtime/pkg/client"
70-
"time"
71-
)
72-
73-
func main() {
74-
// Initialize dependencies
75-
client, err := havoc.NewChaosMeshClient()
76-
if err != nil {
77-
panic(err)
78-
}
79-
logger := havoc.NewChaosLogger()
80-
annotator := havoc.NewSingleLineGrafanaAnnotator(
81-
"http://grafana-instance.com",
82-
"grafana-access-token",
83-
"dashboard-uid",
84-
)
85-
86-
// Define chaos experiment
87-
podChaos := &v1alpha1.PodChaos{ /* PodChaos spec */ }
88-
chaos, err := havoc.NewChaos(havoc.ChaosOpts{
89-
Object: podChaos,
90-
Description: "Pod failure example",
91-
DelayCreate: 5 * time.Second,
92-
Client: client,
93-
})
94-
if err != nil {
95-
panic(err)
96-
}
97-
98-
// Register listeners
99-
chaos.AddListener(logger)
100-
chaos.AddListener(annotator)
101-
102-
// Start chaos experiment
103-
chaos.Create(context.Background())
104-
105-
// Manage chaos lifecycle...
106-
}
107-
```
108-
109-
### Test Example
110-
111-
```golang
112-
func TestChaosDON(t *testing.T) {
113-
testDuration := time.Minute * 60
114-
115-
// Load test config
116-
cfg := &config.MercuryQAEnvChaos{}
117-
118-
// Define chaos experiments and their schedule
119-
120-
k8sClient, err := havoc.NewChaosMeshClient()
121-
require.NoError(t, err)
122-
123-
// Test 3.2: Disable 2 nodes simultaneously
124-
125-
podFailureChaos4, err := k8s_chaos.MercuryPodChaosSchedule(k8s_chaos.MercuryScheduledPodChaosOpts{
126-
Name: "schedule-don-ocr-node-failure-4",
127-
Description: "Disable 2 nodes (clc-ocr-mercury-arb-testnet-qa-nodes-3 and clc-ocr-mercury-arb-testnet-qa-nodes-4)",
128-
DelayCreate: time.Minute * 0,
129-
Duration: time.Minute * 20,
130-
Namespace: cfg.ChaosNodeNamespace,
131-
PodSelector: v1alpha1.PodSelector{
132-
Mode: v1alpha1.AllMode,
133-
Selector: v1alpha1.PodSelectorSpec{
134-
GenericSelectorSpec: v1alpha1.GenericSelectorSpec{
135-
Namespaces: []string{cfg.ChaosNodeNamespace},
136-
ExpressionSelectors: v1alpha1.LabelSelectorRequirements{
137-
{
138-
Key: "app.kubernetes.io/instance",
139-
Operator: "In",
140-
Values: []string{
141-
"clc-ocr-mercury-arb-testnet-qa-nodes-3",
142-
"clc-ocr-mercury-arb-testnet-qa-nodes-4",
143-
},
144-
},
145-
},
146-
},
147-
},
148-
},
149-
Client: k8sClient,
150-
})
151-
require.NoError(t, err)
152-
153-
// Test 3.3: Disable 3 nodes simultaneously
154-
155-
podFailureChaos5, err := k8s_chaos.MercuryPodChaosSchedule(k8s_chaos.MercuryScheduledPodChaosOpts{
156-
Name: "schedule-don-ocr-node-failure-5",
157-
Description: "Disable 3 nodes (clc-ocr-mercury-arb-testnet-qa-nodes-3, clc-ocr-mercury-arb-testnet-qa-nodes-4 and clc-ocr-mercury-arb-testnet-qa-nodes-5)",
158-
DelayCreate: time.Minute * 40,
159-
Duration: time.Minute * 20,
160-
Namespace: cfg.ChaosNodeNamespace,
161-
PodSelector: v1alpha1.PodSelector{
162-
Mode: v1alpha1.AllMode,
163-
Selector: v1alpha1.PodSelectorSpec{
164-
GenericSelectorSpec: v1alpha1.GenericSelectorSpec{
165-
Namespaces: []string{cfg.ChaosNodeNamespace},
166-
ExpressionSelectors: v1alpha1.LabelSelectorRequirements{
167-
{
168-
Key: "app.kubernetes.io/instance",
169-
Operator: "In",
170-
Values: []string{
171-
"clc-ocr-mercury-arb-testnet-qa-nodes-3",
172-
"clc-ocr-mercury-arb-testnet-qa-nodes-4",
173-
"clc-ocr-mercury-arb-testnet-qa-nodes-5",
174-
},
175-
},
176-
},
177-
},
178-
},
179-
},
180-
Client: k8sClient,
181-
})
182-
require.NoError(t, err)
183-
184-
chaosList := []havoc.ChaosEntity{
185-
podFailureChaos4,
186-
podFailureChaos5,
187-
}
188-
189-
for _, chaos := range chaosList {
190-
chaos.AddListener(havoc.NewChaosLogger())
191-
chaos.AddListener(havoc.NewSingleLineGrafanaAnnotator(cfg.GrafanaURL, cfg.GrafanaToken, cfg.GrafanaDashboardUID))
192-
193-
// Fail the test if the chaos object already exists
194-
exists, err := havoc.ChaosObjectExists(chaos.GetObject(), k8sClient)
195-
require.NoError(t, err)
196-
require.False(t, exists, "chaos object already exists: %s. Delete it before starting the test", chaos.GetChaosName())
197-
198-
chaos.Create(context.Background())
199-
}
200-
201-
t.Cleanup(func() {
202-
for _, chaos := range chaosList {
203-
// Delete chaos object if it still exists
204-
chaos.Delete(context.Background())
205-
}
206-
})
207-
208-
// Simulate user activity/load for the duration of the chaos experiments
209-
runUserLoad(t, cfg, testDuration)
210-
}
211-
```
35+
See [this runnable example](https://pkg.go.dev/github.com/smartcontractkit/chainlink-testing-framework/havoc#ExampleNewChaos) of defining a chaos experiment.

docs/Gemfile

Lines changed: 0 additions & 11 deletions
This file was deleted.

docs/README.md

Lines changed: 0 additions & 58 deletions
This file was deleted.

docs/_config.yaml

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)