observability_probe/observability_probe.rs
1//! Demonstrates observability probing against a running supervisor.
2
3// Import the YAML configuration loader.
4use rust_supervisor::config::loader::load_config_state;
5// Import the supervisor runtime entry point.
6use rust_supervisor::runtime::supervisor::Supervisor;
7
8// Define the shared example result type.
9type ExampleResult = Result<(), rust_supervisor::error::types::SupervisorError>;
10
11// Use the Tokio runtime for the asynchronous example.
12#[tokio::main]
13// Return typed supervisor errors from the example.
14/// Runs the observability probe example.
15async fn main() -> ExampleResult {
16 // Load centralized YAML configuration.
17 let state = load_config_state("examples/config/supervisor.yaml")?;
18 // Derive the supervisor specification from configuration.
19 let spec = state.to_supervisor_spec()?;
20 // Start the supervisor runtime from the specification.
21 let handle = Supervisor::start(spec).await?;
22 // Subscribe to runtime event text.
23 let mut events = handle.subscribe_events();
24 // Query the current runtime state.
25 let current = handle.current_state().await?;
26 // Print the current state for the learner.
27 println!("current={current:#?}");
28 // Read one emitted runtime event when it is available.
29 let received = events.recv().await;
30 // Continue only when an event was received.
31 if let Ok(event) = received {
32 // Print the observed runtime event.
33 println!("event={event:#?}");
34 // Finish the optional event display.
35 }
36 // Use the runtime handle for the shutdown request.
37 handle
38 // Request tree shutdown with audit metadata.
39 .shutdown_tree("operator", "observability probe complete")
40 // Wait for the shutdown command result.
41 .await?;
42 // Finish the example successfully.
43 Ok(())
44 // End the observability example.
45}