Skip to content

Commit 7564fd5

Browse files
authored
[DX-1118] local beholder support (#1938)
1 parent 51a21de commit 7564fd5

File tree

16 files changed

+2616
-20
lines changed

16 files changed

+2616
-20
lines changed

book/src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
- [NodeSet](framework/components/chainlink/nodeset.md)
5555
- [Storage](framework/components/storage.md)
5656
- [S3](framework/components/storage/s3.md)
57+
- [Chip Ingress Set](framework/components/chipingresset/chip_ingress.md)
5758
- [Clients]()
5859
- [Chainlink]()
5960
- [RPC]()
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
# Chip Ingress Set
2+
3+
Chip Ingress Set is a composite component that collects Beholder events. It is a thin `testcontainers-go` wrapper over a Docker Compose file copied from the [Atlas](https://github.com/smartcontractkit/atlas/blob/master/chip-ingress/docker-compose.yml) repo.
4+
5+
It consists of 3 components:
6+
- Chip Ingress
7+
- Red Panda
8+
- Red Panda Console
9+
10+
## Configuration
11+
12+
To add it to your stack use following TOML:
13+
```toml
14+
[chip_ingress]
15+
compose_file='../../components/chip_ingress_set/docker-compose.yml'
16+
extra_docker_networks = ["my-existing-network"]
17+
```
18+
19+
Where compose file indicates the location of the `docker-compose.yml` file (remote URLs are supported) and `extra_docker_networks` an optional slice of existing Docker networks, to which whole stack should be connected to.
20+
21+
## Exposed ports
22+
23+
These 3 components expose a variety of ports, but the most important ones from the point of view of user interaction are:
24+
- schema registry port: `18081`
25+
- Kafka port: `19092`
26+
- Red Panda console port: `8080`
27+
28+
## Useful helper methods
29+
30+
Packge contains also a bunch of helper functions tha can:
31+
- create and delete Kafka topics
32+
- fetch `.proto` files from remote repositories and register them with Red Panda
33+
34+
35+
### Topic management
36+
```go
37+
import chipingressset "github.com/smartcontractkit/chainlink-testing-framework/framework/components/dockercompose/chip_ingress_set"
38+
39+
topicsErr := chipingressset.DeleteAllTopics(cmd.Context(), redPandaKafkaURLFlag)
40+
if topicsErr != nil {
41+
panic(topicsErr)
42+
}
43+
44+
createTopicsErr := chipingressset.CreateTopics(ctx, out.RedPanda.KafkaExternalURL, []string{"cre"})
45+
if createTopicsErr != nil {
46+
panic(createTopicsErr)
47+
}
48+
```
49+
50+
### Protobuf schema registration
51+
```go
52+
out, outErr := chipingressset.New(in.ChipIngress)
53+
if outErr != nil {
54+
panic(outErr)
55+
}
56+
57+
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
58+
defer cancel()
59+
60+
// we recommend to use GITHUB_TOKEN with read access to repositories with protos to avoid heavy rate limiting
61+
var client *github.Client
62+
if token := os.Getenv("GITHUB_TOKEN"); token != "" {
63+
ts := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: token})
64+
tc := oauth2.NewClient(ctx, ts)
65+
client = github.NewClient(tc)
66+
} else {
67+
client = github.NewClient(nil)
68+
}
69+
70+
protoErr := chipingressset.DefaultRegisterAndFetchProtos(ctx, client, []chipingressset.RepoConfiguration{
71+
{
72+
Owner: "smartcontractkit",
73+
Repo: "chainlink-protos",
74+
Ref: "626c42d55bdcb36dffe0077fff58abba40acc3e5",
75+
Folders: []string{"workflows"},
76+
},
77+
}, out.RedPanda.SchemaRegistryExternalURL)
78+
if protoErr != nil {
79+
panic(protoErr)
80+
}
81+
```
82+
83+
Since `ProtoSchemaSet` has TOML tags you can also read it from a TOML file with this content:
84+
```toml
85+
[[proto_schema_set]]
86+
owner = 'smartcontractkit'
87+
repository = 'chainlink-protos'
88+
ref = '626c42d55bdcb36dffe0077fff58abba40acc3e5'
89+
folders = ['workflows']
90+
```
91+
92+
using this code:
93+
```go
94+
var protoSchemaSets []chipingressset.ProtoSchemaSet
95+
for _, schemaSet := range configFiles {
96+
file, fileErr := os.ReadFile(schemaSet)
97+
if fileErr != nil {
98+
return errors.Wrapf(fileErr, "failed to read proto schema set config file: %s", schemaSet)
99+
}
100+
101+
type protoSchemaSets struct {
102+
Sets []chipingressset.ProtoSchemaSet `toml:"proto_schema_set"`
103+
}
104+
105+
var sets protoSchemaSets
106+
if err := toml.Unmarshal(file, &sets); err != nil {
107+
return errors.Wrapf(err, "failed to unmarshal proto config file: %s", protoConfig)
108+
}
109+
110+
protoSchemaSets = append(reposConfigs, sets.Sets...)
111+
}
112+
```
113+
114+
Registration logic is very simple and should handle cases of protos that import other protos as long they are all available in the `ProtoSchemaSet`s provided to the registration function. That function uses an algorithm called "topological sorting by trail", which will try to register all protos in a loop until it cannot register any more protos or it has registered all of them. That allows us to skip dependency parsing completely.
115+
116+
Since Kafka doesn't have any automatic discoverability mechanism for subject - schema relationship (it has to be provided out-of-band) code currently only knows how to correctly register protos from [chainlink-protos](https://github.com/smartcontractkit/chainlink-protos) repository.

framework/.changeset/v0.9.7.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Add a function to remove a Docker Compose stack/project
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Add a Chip Ingress (Beholder) stack based on Docker Compose
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Docker Compose
2+
3+
Go module for `framework` packages that wrap `docker-compose.yml` files.
4+
5+
This module is separated from the `framework`, because `testcontainers-go` module that adds Docker Compose support pulls in a lot of dependencies and we want to limit the blast radius as much as possible.

0 commit comments

Comments
 (0)