docs(gitbook): fix API snippets to match current code

This commit is contained in:
andrussal 2025-12-16 06:23:49 +01:00
parent 0210e857f0
commit 73070284c0
4 changed files with 23 additions and 24 deletions

View File

@ -81,7 +81,7 @@ Helper utilities:
**Compose runner** includes: **Compose runner** includes:
- **Prometheus** at `http://localhost:9090` (metrics scraping) - **Prometheus** at `http://localhost:9090` (metrics scraping)
- Node metrics exposed per validator/executor - Node metrics exposed per validator/executor
- Access in expectations: `ctx.telemetry().prometheus_endpoint()` - Access in expectations: `ctx.telemetry().prometheus().map(|p| p.base_url())`
**Logging** controlled by: **Logging** controlled by:
- `NOMOS_LOG_DIR` — Write per-node log files - `NOMOS_LOG_DIR` — Write per-node log files

View File

@ -140,11 +140,11 @@ Templates and configs in `testing-framework/runners/compose/assets/`:
**Prometheus (Compose only):** **Prometheus (Compose only):**
- Exposed at `http://localhost:9090` (configurable) - Exposed at `http://localhost:9090` (configurable)
- Scrapes all validator and executor metrics - Scrapes all validator and executor metrics
- Accessible in expectations: `ctx.telemetry().prometheus_endpoint()` - Accessible in expectations: `ctx.telemetry().prometheus().map(|p| p.base_url())`
**Node APIs:** **Node APIs:**
- HTTP endpoints per node for consensus info, network status, DA membership - HTTP endpoints per node for consensus info, network status, DA membership
- Accessible in expectations: `ctx.node_clients().validators().get(0)` - Accessible in expectations: `ctx.node_clients().validator_clients().get(0)`
**OTLP (optional):** **OTLP (optional):**
- Trace endpoint: `NOMOS_OTLP_ENDPOINT=http://localhost:4317` - Trace endpoint: `NOMOS_OTLP_ENDPOINT=http://localhost:4317`

View File

@ -13,35 +13,30 @@ Key ideas:
- **start**: drive async activity using the shared `RunContext`. - **start**: drive async activity using the shared `RunContext`.
```rust ```rust
use std::sync::Arc;
use async_trait::async_trait; use async_trait::async_trait;
use testing_framework_core::scenario::{ use testing_framework_core::scenario::{
DynError, Expectation, RunContext, RunMetrics, Workload, DynError, Expectation, RunContext, Workload, runtime::context::RunMetrics,
}; };
use testing_framework_core::topology::generation::GeneratedTopology; use testing_framework_core::topology::generation::GeneratedTopology;
pub struct ReachabilityWorkload { pub struct ReachabilityWorkload {
target_idx: usize, target_idx: usize,
bundled: Vec<Box<dyn Expectation>>,
} }
impl ReachabilityWorkload { impl ReachabilityWorkload {
pub fn new(target_idx: usize) -> Self { pub fn new(target_idx: usize) -> Self {
Self { Self { target_idx }
target_idx,
bundled: vec![Box::new(ReachabilityExpectation::new(target_idx))],
}
} }
} }
#[async_trait] #[async_trait]
impl Workload for ReachabilityWorkload { impl Workload for ReachabilityWorkload {
fn name(&self) -> &'static str { fn name(&self) -> &str {
"reachability_workload" "reachability_workload"
} }
fn expectations(&self) -> Vec<Box<dyn Expectation>> { fn expectations(&self) -> Vec<Box<dyn Expectation>> {
self.bundled.clone() vec![Box::new(ReachabilityExpectation::new(self.target_idx))]
} }
fn init( fn init(
@ -57,13 +52,13 @@ impl Workload for ReachabilityWorkload {
async fn start(&self, ctx: &RunContext) -> Result<(), DynError> { async fn start(&self, ctx: &RunContext) -> Result<(), DynError> {
let client = ctx let client = ctx
.clients() .node_clients()
.validators() .validator_clients()
.get(self.target_idx) .get(self.target_idx)
.ok_or("missing target client")?; .ok_or("missing target client")?;
// Pseudo-action: issue a lightweight RPC to prove reachability. // Lightweight API call to prove reachability.
client.health_check().await.map_err(|e| e.into()) client.consensus_info().await.map(|_| ()).map_err(|e| e.into())
} }
} }
``` ```
@ -96,14 +91,16 @@ impl Expectation for ReachabilityExpectation {
async fn evaluate(&mut self, ctx: &RunContext) -> Result<(), DynError> { async fn evaluate(&mut self, ctx: &RunContext) -> Result<(), DynError> {
let client = ctx let client = ctx
.clients() .node_clients()
.validators() .validator_clients()
.get(self.target_idx) .get(self.target_idx)
.ok_or("missing target client")?; .ok_or("missing target client")?;
client.health_check().await.map_err(|e| { client
format!("target became unreachable during run: {e}").into() .consensus_info()
}) .await
.map(|_| ())
.map_err(|e| format!("target became unreachable during run: {e}").into())
} }
} }
``` ```

View File

@ -32,14 +32,16 @@ which describes the proposed `block_peer`/`unblock_peer` API (not yet implemente
Check for control support and use it conditionally: Check for control support and use it conditionally:
```rust ```rust
use testing_framework_core::scenario::{Expectation, RunContext, Workload}; use async_trait::async_trait;
use testing_framework_core::scenario::{DynError, RunContext, Workload};
struct RestartWorkload; struct RestartWorkload;
#[async_trait]
impl Workload for RestartWorkload { impl Workload for RestartWorkload {
fn name(&self) -> &'static str { "restart_workload" } fn name(&self) -> &str { "restart_workload" }
async fn start(&self, ctx: &RunContext) -> Result<(), Box<dyn std::error::Error + Send + Sync>> { async fn start(&self, ctx: &RunContext) -> Result<(), DynError> {
if let Some(control) = ctx.node_control() { if let Some(control) = ctx.node_control() {
// Restart the first validator (index 0) if supported. // Restart the first validator (index 0) if supported.
control.restart_validator(0).await?; control.restart_validator(0).await?;