Skip to content

Commit 27e2dfe

Browse files
committed
update docs + more cleanup
1 parent 42741e3 commit 27e2dfe

20 files changed

+10506
-2571
lines changed

crates/cli/src/docker_init.rs

Lines changed: 16 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,11 @@ use docker_compose_types::{
2929
};
3030
use eyre::Result;
3131
use indexmap::IndexMap;
32-
use serde::Serialize;
3332

3433
/// Name of the docker compose file
3534
pub(super) const CB_COMPOSE_FILE: &str = "cb.docker-compose.yml";
3635
/// Name of the envs file
3736
pub(super) const CB_ENV_FILE: &str = ".cb.env";
38-
/// Name of the Prometheus targets file
39-
pub(super) const CB_TARGETS_FILE: &str = "targets.json";
4037

4138
const SIGNER_NETWORK: &str = "signer_network";
4239

@@ -134,10 +131,7 @@ pub async fn handle_docker_init(config_path: PathBuf, output_dir: PathBuf) -> Re
134131
"{} has an exported port on {}",
135132
module_cid, metrics_port
136133
));
137-
targets.push(PrometheusTargetConfig {
138-
targets: vec![format!("{module_cid}:{metrics_port}")],
139-
labels: PrometheusLabelsConfig { job: module_cid.clone() },
140-
});
134+
targets.push(format!("{host_endpoint}"));
141135
let (key, val) = get_env_uval(METRICS_PORT_ENV, metrics_port as u64);
142136
module_envs.insert(key, val);
143137

@@ -209,10 +203,7 @@ pub async fn handle_docker_init(config_path: PathBuf, output_dir: PathBuf) -> Re
209203
"{} has an exported port on {}",
210204
module_cid, metrics_port
211205
));
212-
targets.push(PrometheusTargetConfig {
213-
targets: vec![format!("{module_cid}:{metrics_port}")],
214-
labels: PrometheusLabelsConfig { job: module_cid.clone() },
215-
});
206+
targets.push(format!("{host_endpoint}"));
216207
let (key, val) = get_env_uval(METRICS_PORT_ENV, metrics_port as u64);
217208
module_envs.insert(key, val);
218209

@@ -272,10 +263,7 @@ pub async fn handle_docker_init(config_path: PathBuf, output_dir: PathBuf) -> Re
272263
let host_endpoint = SocketAddr::from((metrics_config.host, metrics_port));
273264
ports.push(format!("{}:{}", host_endpoint, metrics_port));
274265
warnings.push(format!("cb_pbs has an exported port on {}", metrics_port));
275-
targets.push(PrometheusTargetConfig {
276-
targets: vec![format!("cb_pbs:{metrics_port}")],
277-
labels: PrometheusLabelsConfig { job: "pbs".to_owned() },
278-
});
266+
targets.push(format!("{host_endpoint}"));
279267
let (key, val) = get_env_uval(METRICS_PORT_ENV, metrics_port as u64);
280268
pbs_envs.insert(key, val);
281269

@@ -347,10 +335,7 @@ pub async fn handle_docker_init(config_path: PathBuf, output_dir: PathBuf) -> Re
347335
let host_endpoint = SocketAddr::from((metrics_config.host, metrics_port));
348336
ports.push(format!("{}:{}", host_endpoint, metrics_port));
349337
warnings.push(format!("cb_signer has an exported port on {}", metrics_port));
350-
targets.push(PrometheusTargetConfig {
351-
targets: vec![format!("cb_signer:{metrics_port}")],
352-
labels: PrometheusLabelsConfig { job: "signer".to_owned() },
353-
});
338+
targets.push(format!("{host_endpoint}"));
354339
let (key, val) = get_env_uval(METRICS_PORT_ENV, metrics_port as u64);
355340
signer_envs.insert(key, val);
356341
}
@@ -475,10 +460,7 @@ pub async fn handle_docker_init(config_path: PathBuf, output_dir: PathBuf) -> Re
475460
let host_endpoint = SocketAddr::from((metrics_config.host, metrics_port));
476461
ports.push(format!("{}:{}", host_endpoint, metrics_port));
477462
warnings.push(format!("cb_signer has an exported port on {}", metrics_port));
478-
targets.push(PrometheusTargetConfig {
479-
targets: vec![format!("cb_signer:{metrics_port}")],
480-
labels: PrometheusLabelsConfig { job: "signer".to_owned() },
481-
});
463+
targets.push(format!("{host_endpoint}"));
482464
let (key, val) = get_env_uval(METRICS_PORT_ENV, metrics_port as u64);
483465
signer_envs.insert(key, val);
484466
}
@@ -581,9 +563,11 @@ pub async fn handle_docker_init(config_path: PathBuf, output_dir: PathBuf) -> Re
581563
let compose_path = Path::new(&output_dir).join(CB_COMPOSE_FILE);
582564
std::fs::write(&compose_path, compose_str)?;
583565
if !warnings.is_empty() {
566+
println!();
584567
for exposed_port in warnings {
585568
println!("Warning: {}", exposed_port);
586569
}
570+
println!()
587571
}
588572
// if file logging is enabled, warn about permissions
589573
if let Some(logs_config) = cb_config.logs {
@@ -592,20 +576,20 @@ pub async fn handle_docker_init(config_path: PathBuf, output_dir: PathBuf) -> Re
592576
"Warning: file logging is enabled, you may need to update permissions for the logs directory. e.g. with:\n\t`sudo chown -R 10001:10001 {}`",
593577
log_dir.display()
594578
);
579+
println!()
595580
}
596581

597-
println!("Compose file written to: {:?}", compose_path);
582+
println!("Docker Compose file written to: {:?}", compose_path);
598583

599584
// write prometheus targets to file
600585
if !targets.is_empty() {
601-
let targets_str = serde_json::to_string_pretty(&targets)?;
602-
let targets_path = Path::new(&output_dir).join(CB_TARGETS_FILE);
603-
std::fs::write(&targets_path, targets_str)?;
604-
println!("Prometheus targets file written to: {:?}", targets_path);
586+
let targets = targets.join(", ");
587+
println!("Note: Make sure to add these targets for Prometheus to scrape: {targets}");
588+
println!("Check out the docs on how to configure Prometheus/Grafana/cAdvisor: https://commit-boost.github.io/commit-boost-client/get_started/running/metrics");
605589
}
606590

607591
if envs.is_empty() {
608-
println!("Run with:\n\t`commit-boost-cli start --docker {:?}`", compose_path);
592+
println!("Run with:\n\tdocker compose -f {:?} up -d", compose_path);
609593
} else {
610594
// write envs to .env file
611595
let envs_str = {
@@ -619,12 +603,13 @@ pub async fn handle_docker_init(config_path: PathBuf, output_dir: PathBuf) -> Re
619603
std::fs::write(&env_path, envs_str)?;
620604
println!("Env file written to: {:?}", env_path);
621605

606+
println!();
622607
println!(
623-
"Run with:\n\t`docker compose --env-file {:?} -f {:?} up -d`",
608+
"Run with:\n\tdocker compose --env-file {:?} -f {:?} up -d",
624609
env_path, compose_path
625610
);
626611
println!(
627-
"Stop with:\n\t`docker compose --env-file {:?} -f {:?} down`",
612+
"Stop with:\n\tdocker compose --env-file {:?} -f {:?} down",
628613
env_path, compose_path
629614
);
630615
}
@@ -655,18 +640,6 @@ fn get_env_uval(k: &str, v: u64) -> (String, Option<SingleValue>) {
655640
// (k.into(), Some(SingleValue::Bool(v)))
656641
// }
657642

658-
/// A prometheus target, use to dynamically add targets to the prometheus config
659-
#[derive(Debug, Serialize)]
660-
struct PrometheusTargetConfig {
661-
targets: Vec<String>,
662-
labels: PrometheusLabelsConfig,
663-
}
664-
665-
#[derive(Debug, Serialize)]
666-
struct PrometheusLabelsConfig {
667-
job: String,
668-
}
669-
670643
fn get_log_volume(maybe_config: &Option<LogsSettings>, module_id: &str) -> Option<Volumes> {
671644
maybe_config.as_ref().map(|config| {
672645
let p = config.log_dir_path.join(module_id.to_lowercase());

docs/docs/developing/commit-module.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ While a module can be written in any language, we currently provide some utiliti
88

99
In Rust, we provide utilities to load and run modules. Simply add to your `Cargo.toml`:
1010
```toml
11-
commit-boost = { git = "https://github.com/Commit-Boost/commit-boost-client", rev = "..." }
11+
commit-boost = { git = "https://github.com/Commit-Boost/commit-boost-client", version = "..." }
1212
```
1313

1414
You will now be able to import the utils with:

docs/docs/get_started/configuration.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ port = 18550
2020
url = ""
2121

2222
[metrics]
23-
prometheus_config = "./docker/prometheus.yml"
23+
use_metrics = true
2424
```
2525

2626
You can find a list of MEV-Boost Holesky relays [here](https://www.coincashew.com/coins/overview-eth/mev-boost/mev-relay-list#holesky-testnet-relays).
@@ -282,8 +282,12 @@ A full example of a config file with Dirk can be found [here](https://github.com
282282
## Custom module
283283
We currently provide a test module that needs to be built locally. To build the module run:
284284
```bash
285-
bash scripts/build_local_modules.sh
285+
just docker-build-test-modules
286286
```
287+
:::note
288+
We use `just` as command runner. If you don't have it installed, either install it from https://github.com/casey/just or run the commands manually from the `justfile` at the root of the repo.
289+
:::
290+
287291
This will create a Docker image called `test_da_commit` that periodically requests signatures from the validator, and a `test_builder_log` module that logs BuilderAPI events.
288292

289293
The `cb-config.toml` file needs to be updated as follows:
@@ -301,7 +305,7 @@ keys_path = "/path/to/keys"
301305
secrets_path = "/path/to.secrets"
302306

303307
[metrics]
304-
prometheus_config = "./docker/prometheus.yml"
308+
use_metrics = true
305309

306310
[[modules]]
307311
id = "DA_COMMIT"

docs/docs/get_started/overview.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,10 @@ cargo build --release --bin commit-boost-cli
5555

5656
and the modules as Docker images:
5757
```bash
58-
bash scripts/build_local_images.sh
58+
docker build -t commitboost_pbs_default . -f ./provisioning/pbs.Dockerfile
59+
docker build -t commitboost_signer . -f ./provisioning/signer.Dockerfile
5960
```
6061

61-
:::note
62-
If you require `sudo` access to run Docker, you will need `sudo` to run some of the Commit-Boost commands. This is because under the hood Commit-Boost invokes the Docker API. You can double check this by running `docker info` in a terminal. Consider adding your user to the docker group following [ Docker’s official post-installation steps](https://docs.docker.com/engine/install/linux-postinstall/#manage-docker-as-a-non-root-user)
63-
:::
64-
6562
This will create two local images called `commitboost_pbs_default` and `commitboost_signer` for the Pbs and Signer module respectively. Make sure to use these images in the `docker_image` field in the `[pbs]` and `[signer]` sections of the `.toml` config file, respectively.
6663

6764
### Binaries

docs/docs/get_started/running/docker.md

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description: Run Commit-Boost with Docker
33
---
44

55
# Docker
6-
The Commit-Boost CLI will generate a dynamic `docker-compose.yml` file using the provided `.toml` config file. This is the recommended approach as Docker provides sandboxing of the containers from the rest of your system.
6+
The Commit-Boost CLI generates a dynamic `docker-compose.yml` file using the provided `.toml` config file. This is the recommended approach as Docker provides sandboxing of the containers from the rest of your system.
77

88
## Init
99

@@ -20,28 +20,24 @@ This will create up to three files:
2020

2121
To start Commit-Boost run:
2222
```bash
23-
commit-boost-cli start --docker cb.docker-compose.yml [--env .cb.env]
23+
docker compose --env-file ".cb.env" -f ".cb.docker-compose.yml" up -d
2424
```
2525

26-
This will run `docker compose up` with the correct envs, and start up the services including PBS, commit modules (if any), and metrics collection (if enabled).
26+
This will run the all the configured services, including PBS, signer and modules (if any).
2727

2828
The MEV-Boost server will be exposed at `pbs.port` from the config, `18550` in our example. You'll need to point your CL/Validator client to this port to be able to source blocks from the builder market.
2929

30-
If enabled, this will also start a Prometheus server on port `9090` and a Grafana instance on port `3000`. In Grafana, you will also find some preset dashboards already connected.
31-
32-
3330
## Logs
34-
35-
To check logs, run:
31+
To check the logs, run:
3632
```bash
37-
commit-boost-cli logs
33+
docker compose --env-file ".cb.env" -f ".cb.docker-compose.yml" logs -f
3834
```
3935
This will currently show all logs from the different services via the Docker logs interface. Logs are also optionally saved to file, depending on your `[logs]` configuration.
4036

4137
## Stop
4238

4339
To stop all the services and cleanup, simply run:
4440
```bash
45-
commit-boost-cli stop
41+
docker compose --env-file ".cb.env" -f ".cb.docker-compose.yml" down
4642
```
4743
This will wind down all services and clear internal networks and file mounts.
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
---
2+
description: Setup metrics collection
3+
---
4+
5+
# Metrics
6+
7+
Commit-Boost can be configured to collect metrics from the different services and expose them to be scraped from Prometheus.
8+
9+
Make use to add the `[metrics]` section to your config file:
10+
11+
```toml
12+
[metrics]
13+
use_metrics = true
14+
```
15+
If the section is missing, metrics collection will be disabled. If you generated the `docker-compose.yml` file with `commit-boost-cli`, metrics ports will be automatically configured, and a sample `target.json` file will be created. If you're running the binaries directly, you will need to set the correct environment variables, as described in the [previous section](/get_started/running/binary#common).
16+
17+
## Example setup
18+
19+
:::note
20+
The following examples assume you're running Prometheus/Grafana on the same machine as Commit-Boost. In general you should avoid this setup, and instead run them on a separate machine. cAdvisor should run in the same machine as the containers you want to monitor.
21+
:::
22+
23+
24+
### cAdvisor
25+
[cAdvisor](https://github.com/google/cadvisor) is a tool for collecting and reporting resource usage and performance characteristics of running containers.
26+
27+
```yml title="cb.docker-compose.yml"
28+
cb_cadvisor:
29+
image: gcr.io/cadvisor/cadvisor
30+
container_name: cb_cadvisor
31+
ports:
32+
- 127.0.0.1:8080:8080
33+
volumes:
34+
- /var/run/docker.sock:/var/run/docker.sock:ro
35+
- /sys:/sys:ro
36+
- /var/lib/docker/:/var/lib/docker:ro
37+
```
38+
39+
### Prometheus
40+
41+
For more information on how to setup Prometheus, see the [Prometheus documentation](https://prometheus.io/docs/prometheus/latest/getting_started/).
42+
43+
```yml title="cb.docker-compose.yml"
44+
cb_prometheus:
45+
image: prom/prometheus:v3.0.0
46+
container_name: cb_prometheus
47+
ports:
48+
- 127.0.0.1:9090:9090
49+
volumes:
50+
- ./prometheus.yml:/etc/prometheus/prometheus.yml
51+
- prometheus-data:/prometheus
52+
```
53+
54+
```yml title="prometheus.yml"
55+
global:
56+
scrape_interval: 15s
57+
58+
scrape_configs:
59+
- job_name: "commit-boost"
60+
static_configs:
61+
- targets: ["cb_da_commit:10000", "cb_pbs:10001", "cb_signer:10002", "cb_cadvisor:8080"]
62+
```
63+
64+
### Grafana
65+
For more information on how to setup Grafana, see the [Grafana documentation](https://grafana.com/docs/grafana/latest/getting-started/).
66+
67+
```yml title="cb.docker-compose.yml"
68+
cb_grafana:
69+
image: grafana/grafana:11.3.1
70+
container_name: cb_grafana
71+
ports:
72+
- 127.0.0.1:3000:3000
73+
volumes:
74+
- ./grafana/datasources:/etc/grafana/provisioning/datasources
75+
- grafana-data:/var/lib/grafana
76+
```
77+
78+
```yml title="datasources.yml"
79+
apiVersion: 1
80+
81+
datasources:
82+
- name: prometheus
83+
type: prometheus
84+
uid: prometheus
85+
access: proxy
86+
orgId: 1
87+
url: http://cb_prometheus:9090
88+
isDefault: true
89+
editable: true
90+
```
91+
92+
Once Grafana is running, you can [import](https://grafana.com/docs/grafana/latest/dashboards/build-dashboards/import-dashboards/) the Commit-Boost dashboards from [here](https://github.com/Commit-Boost/commit-boost-client/tree/main/provisioning/grafana), making sure to select the correct `Prometheus` datasource.
93+
94+

docs/sidebars.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ const sidebars = {
3939
items: [
4040
'get_started/running/docker',
4141
'get_started/running/binary',
42+
'get_started/running/metrics',
4243

4344
],
4445
},

0 commit comments

Comments
 (0)