2025-12-17 17:04:41 +01:00
|
|
|
use std::{env, process, time::Duration};
|
2025-12-01 12:48:39 +01:00
|
|
|
|
2025-12-18 09:09:27 +01:00
|
|
|
use anyhow::{Context as _, Result};
|
2025-12-18 14:11:54 +01:00
|
|
|
use runner_examples::{ScenarioBuilderExt as _, demo, read_env_any};
|
2025-12-17 17:04:41 +01:00
|
|
|
use testing_framework_core::scenario::{
|
|
|
|
|
Deployer as _, ObservabilityCapability, Runner, ScenarioBuilder,
|
|
|
|
|
};
|
2025-12-01 12:48:39 +01:00
|
|
|
use testing_framework_runner_k8s::{K8sDeployer, K8sRunnerError};
|
2025-12-17 17:04:41 +01:00
|
|
|
use testing_framework_workflows::ObservabilityBuilderExt as _;
|
2025-12-01 12:48:39 +01:00
|
|
|
use tracing::{info, warn};
|
|
|
|
|
|
2025-12-17 21:52:11 +01:00
|
|
|
const MIXED_TXS_PER_BLOCK: u64 = 2;
|
2025-12-18 09:00:14 +01:00
|
|
|
const TOTAL_WALLETS: usize = 200;
|
|
|
|
|
const TRANSACTION_WALLETS: usize = 50;
|
2025-12-01 12:48:39 +01:00
|
|
|
|
|
|
|
|
#[tokio::main]
|
|
|
|
|
async fn main() {
|
|
|
|
|
tracing_subscriber::fmt::init();
|
|
|
|
|
|
2025-12-18 14:11:54 +01:00
|
|
|
let validators = read_env_any(&["NOMOS_DEMO_VALIDATORS"], demo::DEFAULT_VALIDATORS);
|
|
|
|
|
let executors = read_env_any(&["NOMOS_DEMO_EXECUTORS"], demo::DEFAULT_EXECUTORS);
|
|
|
|
|
let run_secs = read_env_any(&["NOMOS_DEMO_RUN_SECS"], demo::DEFAULT_RUN_SECS);
|
2025-12-01 12:48:39 +01:00
|
|
|
info!(validators, executors, run_secs, "starting k8s runner demo");
|
|
|
|
|
|
|
|
|
|
if let Err(err) = run_k8s_case(validators, executors, Duration::from_secs(run_secs)).await {
|
2025-12-17 21:52:11 +01:00
|
|
|
warn!("k8s runner demo failed: {err:#}");
|
2025-12-15 22:29:36 +01:00
|
|
|
process::exit(1);
|
2025-12-01 12:48:39 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-16 01:41:24 +01:00
|
|
|
async fn run_k8s_case(validators: usize, executors: usize, run_duration: Duration) -> Result<()> {
|
2025-12-01 12:48:39 +01:00
|
|
|
info!(
|
|
|
|
|
validators,
|
|
|
|
|
executors,
|
|
|
|
|
duration_secs = run_duration.as_secs(),
|
|
|
|
|
"building scenario plan"
|
|
|
|
|
);
|
2025-12-17 21:52:11 +01:00
|
|
|
|
2025-12-17 17:04:41 +01:00
|
|
|
let mut scenario = ScenarioBuilder::topology_with(|t| {
|
2025-12-16 01:41:24 +01:00
|
|
|
t.network_star().validators(validators).executors(executors)
|
2025-12-03 05:46:32 +01:00
|
|
|
})
|
2025-12-17 17:04:41 +01:00
|
|
|
.with_capabilities(ObservabilityCapability::default())
|
2025-12-16 01:41:24 +01:00
|
|
|
.wallets(TOTAL_WALLETS)
|
|
|
|
|
.transactions_with(|txs| txs.rate(MIXED_TXS_PER_BLOCK).users(TRANSACTION_WALLETS))
|
2025-12-18 09:09:27 +01:00
|
|
|
.with_run_duration(run_duration)
|
|
|
|
|
.expect_consensus_liveness();
|
2025-12-17 21:52:11 +01:00
|
|
|
|
2025-12-18 09:23:39 +01:00
|
|
|
if let Ok(url) = env::var("NOMOS_METRICS_QUERY_URL") {
|
2025-12-17 17:04:41 +01:00
|
|
|
if !url.trim().is_empty() {
|
|
|
|
|
scenario = scenario.with_metrics_query_url_str(url.trim());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-18 09:23:39 +01:00
|
|
|
if let Ok(url) = env::var("NOMOS_METRICS_OTLP_INGEST_URL") {
|
2025-12-17 17:04:41 +01:00
|
|
|
if !url.trim().is_empty() {
|
|
|
|
|
scenario = scenario.with_metrics_otlp_ingest_url_str(url.trim());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-18 22:48:45 +01:00
|
|
|
let mut plan = scenario.build()?;
|
2025-12-01 12:48:39 +01:00
|
|
|
|
|
|
|
|
let deployer = K8sDeployer::new();
|
|
|
|
|
info!("deploying k8s stack");
|
2025-12-16 01:41:24 +01:00
|
|
|
|
2025-12-01 12:48:39 +01:00
|
|
|
let runner: Runner = match deployer.deploy(&plan).await {
|
|
|
|
|
Ok(runner) => runner,
|
|
|
|
|
Err(K8sRunnerError::ClientInit { source }) => {
|
|
|
|
|
warn!("Kubernetes cluster unavailable ({source}); skipping");
|
|
|
|
|
return Ok(());
|
|
|
|
|
}
|
2025-12-15 23:13:38 +01:00
|
|
|
Err(err) => return Err(anyhow::Error::new(err)).context("deploying k8s stack failed"),
|
2025-12-01 12:48:39 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if !runner.context().telemetry().is_configured() {
|
2025-12-17 18:28:36 +01:00
|
|
|
warn!("metrics querying is disabled; set NOMOS_METRICS_QUERY_URL to enable PromQL queries");
|
2025-12-01 12:48:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
info!("running scenario");
|
2025-12-18 09:09:27 +01:00
|
|
|
runner
|
2025-12-01 12:48:39 +01:00
|
|
|
.run(&mut plan)
|
|
|
|
|
.await
|
2025-12-15 23:13:38 +01:00
|
|
|
.context("running k8s scenario failed")?;
|
2025-12-01 12:48:39 +01:00
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|