Skip to main content

UsageWriterConfig

Struct UsageWriterConfig 

Source
pub struct UsageWriterConfig {
    pub queue_capacity: usize,
    pub max_batch: usize,
    pub flush_interval: Duration,
    pub retry_backoff: Duration,
    pub shutdown_drain_deadline: Duration,
    pub ingest_timeout: Duration,
}
Expand description

The usage queue’s size and the writer’s batching, retry and shutdown timing.

There are no defaults; every value is a deployment decision. validate runs before the task starts (INVARIANTS.md 16).

Fields§

§queue_capacity: usize

Channel capacity — the shed point. Size it to cover the sink’s worst tolerable outage at peak admission rate.

Counted in usage events, one per in-flight or committed-but-unwritten request. Every reserved permit holds a slot, so it also caps concurrent admitted requests. Too small sheds (AccountingBackpressure, zero charge) during brief sink hiccups or bursts; too large lets a longer outage pile up unbilled events in memory and in the shutdown drain. The writer splits it exactly into lanes by host parallelism, with at least 64 slots a lane when there is more than one. Must be positive.

§max_batch: usize

Largest batch handed to one ingest call.

Counted in events. Too small multiplies sink calls under load; too large makes each call, and each retry of a failing one, heavier. It also sets how full a lane gets before it wakes the writer early. Must be positive and at most MAX_INGEST_BATCH, the ingest endpoint’s limit.

§flush_interval: Duration

A partial batch is flushed after at most this long.

The latency between a charge being recorded and the sink seeing it at low traffic. Too long delays billing and leaves more events in the queue when a process dies; too short sends many small batches. Must be positive.

§retry_backoff: Duration

Backoff between retries of a failing ingest.

A failing sink is retried forever at this pace while the queue fills and sheds upstream. Too short hot-spins against a failing sink; too long delays recovery after it returns. Must be positive.

§shutdown_drain_deadline: Duration

Wall-clock bound on the shutdown drain: how long shutdown waits for outstanding permits (slots reserved by in-flight requests or committed committed guards) to resolve, including the ingest calls it makes along the way. Must be positive. Size it within expiry_safety_margin + reclaim_grace so an event landing at the end of the drain is still billable against its lease.

Too short reports permits as WriterStats::unresolved and batches as WriterStats::lost that a longer drain would have billed; too long risks events landing after their lease settled, which the sink rejects. Under an InstanceRuntime the runtime’s shutdown_deadline must cover it.

§ingest_timeout: Duration

Wall-clock bound on one UsageSink::ingest call. A sink that hangs rather than erroring would otherwise park the writer task forever, and with it every later shutdown step. Must be positive.

A timed-out call is a failed attempt and is retried; the sink may still have recorded the batch, which the retry then reports as duplicate. Set it above the sink’s slowest legitimate ingest of a full batch: too short turns a slow sink into endless retries; too long holds the queue behind a hung call.

Implementations§

Source§

impl UsageWriterConfig

Source

pub fn validate(&self) -> Result<(), UsageWriterConfigError>

Every field is a contract, so none of them is silently repaired (INVARIANTS.md GL-16): a zero capacity or batch size has no sensible coercion, a zero backoff hot-spins against a failing sink, and a zero deadline or timeout reports failure without waiting at all.

Trait Implementations§

Source§

impl Clone for UsageWriterConfig

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for UsageWriterConfig

Source§

impl Debug for UsageWriterConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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: Sized + 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: Sized + 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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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