pub struct WeaverController { /* private fields */ }Expand description
Controller for Weaver live-check process
Manages the lifecycle of a Weaver validation process, including:
- Starting the live-check listener
- Monitoring validation status
- Stopping and retrieving final report
§Example
use clnrm_core::telemetry::weaver_controller::{WeaverController, WeaverConfig};
use std::path::PathBuf;
let config = WeaverConfig {
registry_path: PathBuf::from("registry"),
output_dir: PathBuf::from("./validation_output"),
..Default::default()
};
let mut controller = WeaverController::new(config);
// Start Weaver before tests
controller.start_live_check()?;
// Run tests (they emit telemetry to OTLP)
// ...
// Stop Weaver and get validation results
let report = controller.stop_and_report()?;
if report.violations > 0 {
eprintln!("Validation failed with {} violations", report.violations);
}Implementations§
Source§impl WeaverController
impl WeaverController
Sourcepub fn new(config: WeaverConfig) -> Self
pub fn new(config: WeaverConfig) -> Self
Create a new WeaverController with the given configuration
Sourcepub fn start_and_coordinate(&mut self) -> Result<WeaverCoordination>
pub fn start_and_coordinate(&mut self) -> Result<WeaverCoordination>
Start Weaver and return coordination info (Weaver-first pattern)
This is the PRIMARY method for Weaver-first initialization. It blocks until Weaver is ready and returns coordination metadata that MUST be used to configure OTEL exporters.
§Weaver-First Pattern
use clnrm_core::telemetry::weaver_controller::{WeaverController, WeaverConfig};
use clnrm_core::telemetry::{init_otel, OtelConfig, Export};
use std::path::PathBuf;
let config = WeaverConfig::default();
let mut controller = WeaverController::new(config);
// Step 1: Start Weaver and get coordination
let coordination = controller.start_and_coordinate()?;
println!("Weaver listening on port {}", coordination.otlp_grpc_port);
// Step 2: Initialize OTEL with Weaver's actual port
let endpoint = format!("http://localhost:{}", coordination.otlp_grpc_port);
let _otel_guard = init_otel(OtelConfig {
service_name: "clnrm",
deployment_env: "testing",
sample_ratio: 1.0,
export: Export::OtlpGrpc {
endpoint: Box::leak(endpoint.into_boxed_str()),
},
enable_fmt_layer: false,
headers: None,
})?;
// Step 3: Run tests (telemetry goes to Weaver)
// ...
// Step 4: Flush OTEL before stopping Weaver
drop(_otel_guard);
std::thread::sleep(std::time::Duration::from_millis(500));
// Step 5: Stop Weaver and get validation report
let report = controller.stop_and_report()?;§Errors
Returns an error if:
- Weaver binary not found
- No available ports in range
- Weaver process fails to start
- Health check timeout
Sourcepub fn coordination(&self) -> Option<WeaverCoordination>
pub fn coordination(&self) -> Option<WeaverCoordination>
Get current coordination state (non-blocking)
Returns None if Weaver not started via start_and_coordinate(),
otherwise returns the coordination metadata.
Sourcepub fn start_live_check(&mut self) -> Result<()>
pub fn start_live_check(&mut self) -> Result<()>
Start Weaver live-check listener
Spawns Weaver as a child process and waits for it to be ready. Includes intelligent port management and process cleanup.
§Errors
Returns an error if:
- Weaver binary is not found
- Failed to create output directory
- Process failed to start
- Listener failed to become ready
- No available ports in range
Sourcepub fn stop_and_report(&mut self) -> Result<ValidationReport>
pub fn stop_and_report(&mut self) -> Result<ValidationReport>
Stop Weaver and retrieve validation report
Sends SIGHUP to gracefully stop Weaver, then parses the validation report.
§Errors
Returns an error if:
- Weaver is not running
- Failed to stop the process
- Report file not found or invalid JSON
Sourcepub fn is_validation_passing(&self) -> bool
pub fn is_validation_passing(&self) -> bool
Check if validation has detected violations during streaming
This is only useful when streaming is enabled in the configuration.
Sourcepub fn get_otlp_port(&self) -> u16
pub fn get_otlp_port(&self) -> u16
Get the OTLP port that Weaver is listening on
This returns the port discovered during start_live_check().
Useful for configuring OTEL exporters to send to the correct endpoint.
Sourcepub fn get_admin_port(&self) -> u16
pub fn get_admin_port(&self) -> u16
Get the admin port that Weaver is listening on
This returns the port discovered during start_live_check().
Trait Implementations§
Auto Trait Implementations§
impl Freeze for WeaverController
impl !RefUnwindSafe for WeaverController
impl Send for WeaverController
impl Sync for WeaverController
impl Unpin for WeaverController
impl !UnwindSafe for WeaverController
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request