WeaverController

Struct WeaverController 

Source
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

Source

pub fn new(config: WeaverConfig) -> Self

Create a new WeaverController with the given configuration

Source

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
Source

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.

Source

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
Source

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
Source

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.

Source

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.

Source

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§

Source§

impl Drop for WeaverController

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Fake for T

Source§

fn fake<U>(&self) -> U
where Self: FakeBase<U>,

Source§

fn fake_with_rng<U, R>(&self, rng: &mut R) -> U
where R: Rng + ?Sized, Self: FakeBase<U>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<T> IntoResult<T> for T

Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<G1, G2> Within<G2> for G1
where G2: Contains<G1>,

Source§

fn is_within(&self, b: &G2) -> bool

Source§

impl<T> ErasedDestructor for T
where T: 'static,