Skip to content

Commit 88c6d2e

Browse files
authored
Container polling speedup, move Promtail to CLI, Delve debugger entrypoint (#1484)
move promtail, speedup, delve
1 parent d9c773e commit 88c6d2e

File tree

15 files changed

+52
-54
lines changed

15 files changed

+52
-54
lines changed

book/src/framework/components/debug.md

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,35 +10,6 @@ Use `RESTY_DEBUG=true` to debug any API calls.
1010

1111
Use `SETH_LOG_LEVEL=trace|debug|info|warn` to debug [Seth](../../libs/seth.md).
1212

13-
## Using Delve (TBD)
14-
15-
You can use [Delve]() inside your containers to debug aplications.
16-
17-
Build them with `go build -gcflags="all=-N -l" -o myapp` and use an example `Dockerfile`:
18-
```
19-
FROM golang:1.20
20-
21-
# Install Delve
22-
RUN go install github.com/go-delve/delve/cmd/dlv@latest
23-
24-
# Set working directory
25-
WORKDIR /app
26-
27-
# Copy the application binary and source code (if needed for debugging)
28-
COPY myapp /app/myapp
29-
COPY . /app
30-
31-
# Expose the port for Delve
32-
EXPOSE 40000
33-
34-
# Start Delve in headless mode for remote debugging
35-
ENTRYPOINT ["dlv", "exec", "./myapp", "--headless", "--listen=:40000", "--api-version=2", "--accept-multiclient"]
36-
37-
```
38-
39-
Adding `Delve` to all our components is WIP right now.
40-
41-
To expose `Delve` port follow this [guide](state.md).
42-
43-
13+
## Using Delve Debugger
4414

15+
If you are using `Chainlink` image with [Delve](https://github.com/go-delve/delve) available in path you can use ports `40000..400XX` to connect to any node.

book/src/framework/components/state.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ When deploying a component, you can explicitly configure port ranges if the defa
99
Defaults are:
1010
- [NodeSet](../components/chainlink/nodeset.md) (Node HTTP API): `10000..100XX`
1111
- [NodeSet](../components/chainlink/nodeset.md) (Node P2P API): `12000..120XX`
12+
- [NodeSet](../components/chainlink/nodeset.md) (Delve debugger): `40000..400XX` (if you are using debug image)
1213
- Shared `PostgreSQL` volume is called `postgresql_data`
1314
```
1415
[nodeset]

framework/.changeset/v0.3.8.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- Move promtail to CLI
2+
- Speed up container polling
3+
- Allow debug entrypoint for dlv

framework/cmd/interactive.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,6 @@ func createComponentsFromForm(form *nodeSetForm) error {
7575
}
7676
switch form.Observability {
7777
case true:
78-
if err = framework.NewPromtail(); err != nil {
79-
return err
80-
}
8178
if err := observabilityUp(); err != nil {
8279
return err
8380
}

framework/cmd/observability.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ func observabilityUp() error {
1010
if err := extractAllFiles("observability"); err != nil {
1111
return err
1212
}
13+
if err := framework.NewPromtail(); err != nil {
14+
return err
15+
}
1316
err := runCommand("bash", "-c", fmt.Sprintf(`
1417
cd %s && \
1518
docker compose up -d

framework/components/blockchain/anvil.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func newAnvil(in *Input) (*Output, error) {
5353
NetworkAliases: map[string][]string{
5454
framework.DefaultNetworkName: {containerName},
5555
},
56-
WaitingFor: wait.ForListeningPort(nat.Port(in.Port)).WithStartupTimeout(10 * time.Second),
56+
WaitingFor: wait.ForListeningPort(nat.Port(in.Port)).WithStartupTimeout(10 * time.Second).WithPollInterval(200 * time.Millisecond),
5757
Entrypoint: entryPoint,
5858
}
5959
c, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{

framework/components/blockchain/besu.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func newBesu(in *Input) (*Output, error) {
8282
},
8383
}
8484
},
85-
WaitingFor: wait.ForListeningPort(nat.Port(in.Port)).WithStartupTimeout(15 * time.Second),
85+
WaitingFor: wait.ForListeningPort(nat.Port(in.Port)).WithStartupTimeout(15 * time.Second).WithPollInterval(200 * time.Millisecond),
8686
Cmd: entryPoint,
8787
}
8888

framework/components/blockchain/geth.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ func newGeth(in *Input) (*Output, error) {
191191
FileMode: 0644,
192192
},
193193
},
194-
WaitingFor: wait.ForListeningPort(nat.Port(in.Port)).WithStartupTimeout(15 * time.Second),
194+
WaitingFor: wait.ForListeningPort(nat.Port(in.Port)).WithStartupTimeout(15 * time.Second).WithPollInterval(200 * time.Millisecond),
195195
Cmd: entryPoint,
196196
}
197197
c, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{

framework/components/clnode/clnode.go

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"fmt"
88
"os"
99
"path/filepath"
10+
"strconv"
1011
"strings"
1112
"sync"
1213
"text/template"
@@ -23,6 +24,7 @@ import (
2324
const (
2425
DefaultHTTPPort = "6688"
2526
DefaultP2PPort = "6690"
27+
DefaultDebuggerPort = 40000
2628
TmpImageName = "chainlink-tmp:latest"
2729
CustomPortSeparator = ":"
2830
)
@@ -54,6 +56,7 @@ type NodeInput struct {
5456
HTTPPort int `toml:"port"`
5557
P2PPort int `toml:"p2p_port"`
5658
CustomPorts []string `toml:"custom_ports"`
59+
DebuggerPort int `toml:"debugger_port"`
5760
}
5861

5962
// Output represents Chainlink node output, nodes and databases connection URLs
@@ -114,18 +117,38 @@ func NewNode(in *Input, pgOut *postgres.Output) (*Output, error) {
114117
return out, nil
115118
}
116119

120+
func generateEntryPoint() []string {
121+
entrypoint := []string{
122+
"/bin/sh", "-c",
123+
}
124+
if os.Getenv("CTF_CLNODE_DLV") == "true" {
125+
entrypoint = append(entrypoint, "dlv exec /usr/local/bin/chainlink --continue --listen=0.0.0.0:40000 --headless=true --api-version=2 --accept-multiclient -- -c /config/config -c /config/overrides -c /config/user-overrides -s /config/secrets -s /config/secrets-overrides -s /config/user-secrets-overrides node start -d -p /config/node_password -a /config/apicredentials")
126+
} else {
127+
entrypoint = append(entrypoint, "chainlink -c /config/config -c /config/overrides -c /config/user-overrides -s /config/secrets -s /config/secrets-overrides -s /config/user-secrets-overrides node start -d -p /config/node_password -a /config/apicredentials")
128+
}
129+
return entrypoint
130+
}
131+
117132
// generatePortBindings generates exposed ports and port bindings
118133
// exposes default CL node port
119134
// exposes custom_ports in format "host:docker" or map 1-to-1 if only "host" port is provided
120135
func generatePortBindings(in *Input) ([]string, nat.PortMap, error) {
121136
httpPort := fmt.Sprintf("%s/tcp", DefaultHTTPPort)
137+
innerDebuggerPort := fmt.Sprintf("%d/tcp", DefaultDebuggerPort)
138+
debuggerPort := fmt.Sprintf("%d/tcp", in.Node.DebuggerPort)
122139
portBindings := nat.PortMap{
123140
nat.Port(httpPort): []nat.PortBinding{
124141
{
125142
HostIP: "0.0.0.0",
126143
HostPort: fmt.Sprintf("%d/tcp", in.Node.HTTPPort),
127144
},
128145
},
146+
nat.Port(innerDebuggerPort): []nat.PortBinding{
147+
{
148+
HostIP: "0.0.0.0",
149+
HostPort: debuggerPort,
150+
},
151+
},
129152
}
130153
customPorts := make([]string, 0)
131154
for _, p := range in.Node.CustomPorts {
@@ -157,7 +180,7 @@ func generatePortBindings(in *Input) ([]string, nat.PortMap, error) {
157180
}
158181
}
159182
}
160-
exposedPorts := []string{httpPort}
183+
exposedPorts := []string{httpPort, strconv.Itoa(DefaultDebuggerPort)}
161184
exposedPorts = append(exposedPorts, customPorts...)
162185
return exposedPorts, portBindings, nil
163186
}
@@ -219,11 +242,8 @@ func newNode(in *Input, pgOut *postgres.Output) (*NodeOut, error) {
219242
framework.DefaultNetworkName: {containerName},
220243
},
221244
ExposedPorts: exposedPorts,
222-
Entrypoint: []string{
223-
"/bin/sh", "-c",
224-
"chainlink -c /config/config -c /config/overrides -c /config/user-overrides -s /config/secrets -s /config/secrets-overrides -s /config/user-secrets-overrides node start -d -p /config/node_password -a /config/apicredentials",
225-
},
226-
WaitingFor: wait.ForHTTP("/").WithPort(DefaultHTTPPort).WithStartupTimeout(2 * time.Minute),
245+
Entrypoint: generateEntryPoint(),
246+
WaitingFor: wait.ForHTTP("/").WithPort(DefaultHTTPPort).WithStartupTimeout(1 * time.Minute).WithPollInterval(200 * time.Millisecond),
227247
}
228248
if in.Node.HTTPPort != 0 && in.Node.P2PPort != 0 {
229249
req.HostConfigModifier = func(h *container.HostConfig) {

framework/components/postgres/postgres.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ func NewPostgreSQL(in *Input) (*Output, error) {
107107
},
108108
WaitingFor: tcwait.ForExec([]string{"psql", "-h", "127.0.0.1",
109109
"-U", User, "-p", Port, "-c", "select", "1", "-d", Database}).
110-
WithStartupTimeout(20 * time.Second).
111-
WithPollInterval(1 * time.Second),
110+
WithStartupTimeout(15 * time.Second).
111+
WithPollInterval(200 * time.Millisecond),
112112
}
113113
var portToExpose int
114114
if in.Port != 0 {

0 commit comments

Comments
 (0)