Skip to content

Commit c895cef

Browse files
MartinquaXDxdecentralix
authored andcommitted
Enable tokio-console in playground (cowprotocol#3768)
# Description `tokio-console` can be nice to see what's going on in the tokio runtime. This PR makes it so that all services pods will be spawned with tokio console enabled. It also fixes a few other playground issues # Changes For Tokio Console - adjusts `Dockerfile` to add `--cfg tokio_unstable` to `.cargo/config.toml` which builds the services with `tokio-console` support - adds necessary tokio console env variables to docker compose files - `TOKIO_CONSOLE=true` to activate the feature in our processes - `TOKIO_CONSOLE_RETENTION=600s` to limit the memory used for all the metrics - `TOKIO_CONSOLE_BIND=0.0.0.0:6669` to open port listening on all devices (the default of `127.0.0.1` can not be reached from outside docker) - adds the necessary port forwards (while avoiding conflicts) - moved the log about the tokio configuration message until after the subscriber gets initialized - otherwise it doesn't actually get logged 😅 - added `tokio-console` instructions in the readme Other stuff - convert `as` to `AS` to avoid docker complaining about inconsistent capitalization - removed caching from `yarn` build step of frontend and explorer because having multiple builds use the same yarn cache regularly caused errors in my builds. Since we usually don't rebuild the frontends not having the cache here doesn't slow anything down AFAICS ## How to test 1. Install [tokio-console](https://github.com/tokio-rs/console) 2. start playground 3. run `tokio-console` (this connects to the default port which I assigned to the orderbook). Other pods can be accessed with `tokio-console http://localhost:<PORT>` The port mappings are as follows: orderbook: 6669 autopilot: 6670 driver: 6671 baseline: 6672 <img width="962" height="498" alt="Screenshot 2025-10-10 at 10 06 11" src="https://github.com/user-attachments/assets/31e93560-004b-42d4-88b7-3639a068ce5b" />
1 parent d5537a5 commit c895cef

File tree

7 files changed

+60
-19
lines changed

7 files changed

+60
-19
lines changed

crates/observe/src/tracing.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,11 @@ fn set_tracing_subscriber(config: &Config) {
162162
.with(tracing_layer);
163163

164164
if cfg!(tokio_unstable) && enable_tokio_console {
165-
tracing::info!("started program with support for tokio-console");
166165
subscriber.with(console_subscriber::spawn()).init();
166+
tracing::info!("started program with support for tokio-console");
167167
} else {
168-
tracing::info!("started program without support for tokio-console");
169168
subscriber.init();
169+
tracing::info!("started program without support for tokio-console");
170170
}
171171
if cfg!(unix) {
172172
spawn_reload_handler(initial_filter, reload_handle);

playground/Dockerfile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ RUN rustup component add clippy rustfmt
88
RUN echo "\
99
[build]\n \
1010
target = \"$(rustc -Vv | grep host | awk '{print $2}')\"\n \
11+
rustflags = [\"-C\", \"link-arg=-fuse-ld=/usr/bin/mold\", \"--cfg\", \"tokio_unstable\"]\n \
1112
[target.$(rustc -Vv | grep host | awk '{print $2}')]\n \
1213
linker = \"clang\"\n \
13-
rustflags = [\"-C\", \"link-arg=-fuse-ld=/usr/bin/mold\"]\n \
1414
" > ~/.cargo/config.toml
1515

1616
RUN cargo install cargo-chef
@@ -30,9 +30,11 @@ CMD ["migrate"]
3030

3131
FROM chef AS builder
3232
COPY --from=planner /src/recipe.json recipe.json
33+
COPY --from=chef /.cargo /.cargo
3334
RUN CARGO_PROFILE_RELEASE_DEBUG=1 cargo chef cook --release --recipe-path recipe.json
3435

3536
# Copy only the library crates for now
37+
COPY --from=chef /.cargo /.cargo
3638
COPY Cargo.toml Cargo.lock ./
3739
COPY ./crates/app-data/ ./crates/app-data
3840
COPY ./crates/database/ ./crates/database
@@ -57,6 +59,7 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked apt-get update && \
5759
apt-get clean
5860

5961
FROM builder AS alerter-build
62+
COPY --from=chef /.cargo /.cargo
6063
COPY ./crates/alerter/ ./crates/alerter
6164
RUN CARGO_PROFILE_RELEASE_DEBUG=1 cargo build --release --package alerter
6265

@@ -68,6 +71,7 @@ FROM builder AS autopilot-build
6871
RUN CARGO_PROFILE_RELEASE_DEBUG=1 cargo build --release --package autopilot
6972

7073
FROM base AS autopilot
74+
COPY --from=chef /.cargo /.cargo
7175
COPY ./crates/autopilot/ ./crates/autopilot
7276
COPY --from=autopilot-build /src/target/release/autopilot /usr/local/bin/autopilot
7377
ENTRYPOINT [ "autopilot" ]
@@ -81,6 +85,7 @@ COPY --from=driver-build /src/target/release/driver /usr/local/bin/driver
8185
ENTRYPOINT [ "driver" ]
8286

8387
FROM builder AS orderbook-build
88+
COPY --from=chef /.cargo /.cargo
8489
COPY ./crates/orderbook/ ./crates/orderbook
8590
RUN CARGO_PROFILE_RELEASE_DEBUG=1 cargo build --release --package orderbook
8691

@@ -89,6 +94,7 @@ COPY --from=orderbook-build /src/target/release/orderbook /usr/local/bin/orderbo
8994
ENTRYPOINT [ "orderbook" ]
9095

9196
FROM builder AS refunder-build
97+
COPY --from=chef /.cargo /.cargo
9298
COPY ./crates/refunder/ ./crates/refunder
9399
RUN CARGO_PROFILE_RELEASE_DEBUG=1 cargo build --release --package refunder
94100

@@ -97,6 +103,7 @@ COPY --from=refunder-build /src/target/release/refunder /usr/local/bin/refunder
97103
ENTRYPOINT [ "refunder" ]
98104

99105
FROM builder AS solvers-build
106+
COPY --from=chef /.cargo /.cargo
100107
COPY ./crates/solvers/ ./crates/solvers
101108
RUN CARGO_PROFILE_RELEASE_DEBUG=1 cargo build --release --package solvers
102109

playground/Dockerfile.cowswap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ RUN git clone https://github.com/cowprotocol/cowswap . && \
1919
git submodule update --init --recursive
2020

2121
# Install npm dependencies
22-
RUN --mount=type=cache,target=/home/node/.yarn YARN_CACHE_FOLDER=/home/node/.yarn yarn install --frozen-lockfile
22+
RUN yarn install --frozen-lockfile --no-cache
2323

2424
# Set the environment variable "chain"
2525
ARG CHAIN
@@ -58,7 +58,7 @@ RUN if [ -n "$ETH_RPC_URL" ]; then \
5858
fi
5959

6060
# Stage 2: Copy the frontend to the nginx container
61-
FROM docker.io/nginx:1.21-alpine as frontend
61+
FROM docker.io/nginx:1.21-alpine AS frontend
6262
COPY --from=node-build /usr/src/app/build/cowswap /usr/share/nginx/html
6363
EXPOSE 80
6464
CMD ["nginx", "-g", "daemon off;"]

playground/Dockerfile.explorer

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Stage 1: Build the frontend
2-
FROM docker.io/node:22-bookworm-slim as node-build
2+
FROM docker.io/node:22-bookworm-slim AS node-build
33
WORKDIR /usr/src/app
44

55
# Install dependencies
@@ -11,7 +11,7 @@ RUN git clone https://github.com/cowprotocol/cowswap . && \
1111
git submodule update --init --recursive
1212

1313
# Install npm dependencies
14-
RUN --mount=type=cache,target=/home/node/.yarn YARN_CACHE_FOLDER=/home/node/.yarn yarn install --frozen-lockfile
14+
RUN yarn install --frozen-lockfile --no-cache
1515

1616
ENV REACT_APP_ORDER_BOOK_URLS='{"1":"http://localhost:8080"}'
1717

playground/README.md

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -103,21 +103,23 @@ await window.ethereum.request({
103103

104104
## Components
105105

106-
| **Component** | **Container name** | **Host port** | **Container port** | **Stack** |
107-
|---------------|--------------------|---------------|--------------------|------------|
108-
| Autopilot | autopilot | N/A | N/A | Common |
109-
| Driver | driver | N/A | 80 | Common |
110-
| Baseline | baseline | N/A | 80 | Common |
111-
| CoW Swap | cowswap | 8000 | 80 | Local/Fork |
112-
| CoW Explorer | cowexplorer | 8001 | 80 | Local/Fork |
113-
| Orderbook | orderbook | 8080 | 80 | Local/Fork |
114-
| RPC | chain | 8545 | 8545 | Local/Fork |
115-
| Postgres | postgres | 5432 | 5432 | Local/Fork |
116-
| Adminer | adminer | 8082 | 8080 | Local/Fork |
117-
| Grafana | grafana | 3000 | 3000 | Local/Fork |
106+
| **Component** | **Container name** | **Host port** | **Container port** | **Tokio Console Port** | **Stack** |
107+
|---------------|--------------------|---------------|--------------------|------------------------|------------|
108+
| Autopilot | autopilot | N/A | N/A | 6670 | Local/Fork |
109+
| Driver | driver | N/A | 80 | 6671 | Local/Fork |
110+
| Baseline | baseline | N/A | 80 | 6672 | Local/Fork |
111+
| CoW Swap | cowswap | 8000 | 80 | N/A | Local/Fork |
112+
| CoW Explorer | cowexplorer | 8001 | 80 | N/A | Local/Fork |
113+
| Orderbook | orderbook | 8080 | 80 | 6669 | Local/Fork |
114+
| RPC | chain | 8545 | 8545 | N/A | Local/Fork |
115+
| Postgres | postgres | 5432 | 5432 | N/A | Local/Fork |
116+
| Adminer | adminer | 8082 | 8080 | N/A | Local/Fork |
117+
| Grafana | grafana | 3000 | 3000 | N/A | Local/Fork |
118118

119119
**NOTE**: Currently only **FORK** mode is supported.
120120

121+
Some services support to be inspected with [tokio-console](https://github.com/tokio-rs/console). For that simply install `tokio-console` and run `tokio-console http://localhost:<PORT>`. The relevant port numbers can be found in the table above.
122+
121123
## Modes
122124

123125
### Shadow

playground/docker-compose.fork.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,17 @@ services:
8888
- RUST_BACKTRACE=1
8989
- TOML_TRACE_ERROR=1
9090
- TRACING_COLLECTOR_ENDPOINT=http://tempo:4317
91+
- TOKIO_CONSOLE=true
92+
- TOKIO_CONSOLE_RETENTION=600sec
93+
- TOKIO_CONSOLE_BIND=0.0.0.0:6669
9194
volumes:
9295
- ../:/src
9396
depends_on:
9497
- db-migrations
9598
ports:
9699
- 8080:80 # API
97100
- 9586:9586 # metrics
101+
- 6669:6669 # tokio console
98102

99103
autopilot:
100104
build:
@@ -126,6 +130,9 @@ services:
126130
- TOML_TRACE_ERROR=1
127131
- ETHFLOW_CONTRACTS
128132
- ETHFLOW_INDEXING_START
133+
- TOKIO_CONSOLE=true
134+
- TOKIO_CONSOLE_RETENTION=600sec
135+
- TOKIO_CONSOLE_BIND=0.0.0.0:6669
129136
volumes:
130137
- ../:/src
131138
depends_on:
@@ -135,6 +142,7 @@ services:
135142
condition: service_healthy
136143
ports:
137144
- 9589:9589 # metrics
145+
- 6670:6669 # tokio console
138146

139147
driver:
140148
build:
@@ -155,10 +163,14 @@ services:
155163
- RUST_BACKTRACE=1
156164
- TOML_TRACE_ERROR=1
157165
- TRACING_COLLECTOR_ENDPOINT=http://tempo:4317
166+
- TOKIO_CONSOLE=true
167+
- TOKIO_CONSOLE_RETENTION=600sec
168+
- TOKIO_CONSOLE_BIND=0.0.0.0:6669
158169
volumes:
159170
- ../:/src
160171
ports:
161172
- 9000:80 # API & metrics
173+
- 6671:6669 # tokio console
162174
depends_on:
163175
chain:
164176
condition: service_healthy
@@ -182,10 +194,14 @@ services:
182194
- LOG=solvers=trace,shared=trace
183195
- RUST_BACKTRACE=1
184196
- TOML_TRACE_ERROR=1
197+
- TOKIO_CONSOLE=true
198+
- TOKIO_CONSOLE_RETENTION=600sec
199+
- TOKIO_CONSOLE_BIND=0.0.0.0:6669
185200
volumes:
186201
- ../:/src
187202
ports:
188203
- 9001:80 # API & metrics
204+
- 6672:6669 # tokio console
189205

190206
frontend:
191207
build:

playground/docker-compose.non-interactive.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,17 @@ services:
9090
- RUST_BACKTRACE=1
9191
- TOML_TRACE_ERROR=1
9292
- TRACING_COLLECTOR_ENDPOINT=http://tempo:4317
93+
- TOKIO_CONSOLE=true
94+
- TOKIO_CONSOLE_RETENTION=600sec
95+
- TOKIO_CONSOLE_BIND=0.0.0.0:6669
9396
volumes:
9497
- ../:/src
9598
depends_on:
9699
- db-migrations
97100
ports:
98101
- 8080:80 # API
99102
- 9586:9586 # metrics
103+
- 6669:6669 # tokio console
100104

101105
autopilot:
102106
build:
@@ -127,6 +131,9 @@ services:
127131
- TOML_TRACE_ERROR=1
128132
- ETHFLOW_CONTRACTS
129133
- ETHFLOW_INDEXING_START
134+
- TOKIO_CONSOLE=true
135+
- TOKIO_CONSOLE_RETENTION=600sec
136+
- TOKIO_CONSOLE_BIND=0.0.0.0:6669
130137
volumes:
131138
- ../:/src
132139
depends_on:
@@ -136,6 +143,7 @@ services:
136143
condition: service_healthy
137144
ports:
138145
- 9589:9589 # metrics
146+
- 6670:6669 # tokio console
139147

140148
driver:
141149
build:
@@ -150,10 +158,14 @@ services:
150158
- RUST_BACKTRACE=1
151159
- TOML_TRACE_ERROR=1
152160
- TRACING_COLLECTOR_ENDPOINT=http://tempo:4317
161+
- TOKIO_CONSOLE=true
162+
- TOKIO_CONSOLE_RETENTION=600sec
163+
- TOKIO_CONSOLE_BIND=0.0.0.0:6669
153164
volumes:
154165
- ./driver.toml:/driver.toml
155166
ports:
156167
- 9000:80 # API & metrics
168+
- 6671:6669 # tokio console
157169
depends_on:
158170
chain:
159171
condition: service_healthy
@@ -171,10 +183,14 @@ services:
171183
- LOG=solvers=trace,shared=trace
172184
- RUST_BACKTRACE=1
173185
- TOML_TRACE_ERROR=1
186+
- TOKIO_CONSOLE=true
187+
- TOKIO_CONSOLE_RETENTION=600sec
188+
- TOKIO_CONSOLE_BIND=0.0.0.0:6669
174189
volumes:
175190
- ./baseline.toml:/baseline.toml
176191
ports:
177192
- 9001:80 # API & metrics
193+
- 6672:6669 # tokio console
178194

179195
frontend:
180196
build:

0 commit comments

Comments
 (0)