Skip to main content

EdgeConfig

Struct EdgeConfig 

Source
pub struct EdgeConfig { /* private fields */ }
Expand description

Runtime configuration shared by every cloned metering service.

Implementations§

Source§

impl EdgeConfig

Source

pub fn new(tenants: Arc<dyn TenantStore>) -> Self

Construct an edge using API-key tenants and a no-op billing recorder.

Source

pub fn with_strict_protocol_version(self, strict: bool) -> Self

Refuse requests that predate the mirrored headers instead of reading their body.

By default a legacy request is classified from its JSON-RPC body, which is what lets clients older than mcp_usage_core::version::HEADER_VALIDATION_SINCE - still the majority - reach the origin at all. The body is the document the origin executes, so pricing on it cannot be gamed the way pricing on unvalidated headers can; the cost is one bounded JSON parse per legacy request.

Set this when a deployment would rather serve only modern clients than spend that parse, or when an upstream proxy already guarantees the revision.

Source

pub fn with_recorder(self, recorder: SharedRecorder) -> Self

Install the hot-path usage recorder.

Source

pub fn with_task_store(self, tasks: Arc<dyn TaskAttributionStore>) -> Self

Install a durable task-attribution store.

Source

pub fn with_meter_name(self, meter_name: impl Into<String>) -> Self

Set the provider meter event name.

Source

pub fn with_cache(self, max_entries: usize, max_ttl: Duration) -> Self

Configure cache capacity and the maximum honored server TTL.

Source

pub fn with_public_cache_sharing(self, share: bool) -> Self

Share results the origin marks cacheScope: "public" across tenants.

Disabled by default. A "public" result is an assertion by the origin that the body does not depend on who asked for it; honoring it puts one entry in a bucket every authorization context reads, so an origin that mislabels a tenant-specific result turns that mistake into a cross-tenant disclosure at the edge. Cacheable methods include resources/read, so the blast radius is resource contents, not just discovery listings.

Enable this only when the origin’s public results are genuinely tenant-independent. Leaving it off costs cache hit rate and nothing else: a cache may always decline to reuse a response.

Source

pub fn with_credential_forwarding(self, forward: bool) -> Self

Forward the API key to the inner service after authenticating it.

Disabled by default: the edge consumes the credential, so passing it on hands the inner service a secret it was not issued. That is harmless when the origin runs in-process, and an exposure the moment this layer fronts an origin in another trust domain.

Enable it when the origin performs its own check against the same key.

Source

pub fn with_max_request_body(self, bytes: usize) -> Self

Bound bytes accepted from one MCP request body.

Source

pub fn with_max_response_capture(self, bytes: usize) -> Self

Bound bytes retained while observing a response. Oversized responses continue streaming but fail toward not charging and not caching.

Source

pub fn metrics(&self) -> Arc<EdgeMetrics> ⓘ

Shared edge counters.

Source

pub fn deferred(&self) -> Arc<DeferredCompletions> ⓘ

Terminal accounting parked because it could not finish without awaiting.

Only a durable task store parks anything: its futures perform real I/O, and the body is released from Drop, where nothing may await. Every subsequent authenticated request runs a bounded number of them, so an application that ignores this still converges. Draining explicitly is better, and draining after graceful shutdown is what stops a departing process from taking durable-task charges with it.

Take the handle before passing the configuration to the layer.

Source

pub fn with_deferred_drain_per_request(self, completions: usize) -> Self

Bound how much parked accounting each authenticated request runs.

Zero leaves draining entirely to EdgeConfig::deferred. Raising it clears a backlog sooner at the cost of latency on the requests that do the work.

Source

pub fn with_deferred_capacity(self, capacity: usize) -> Self

Bound how many completions may be parked before the oldest is discarded.

Source

pub fn with_auth_failure_limit( self, max_failures: u64, window: Duration, ) -> Result<Self, EdgeConfigError>

Refuse further guessing after max_failures bad credentials in window.

Disabled by default, because the useful ceiling depends entirely on how many clients an edge serves. Only failures consume the budget, so a caller with a valid key is never affected: exhausting it turns a wrong key’s 401 into a 429 and nothing more.

This bounds sustained guessing across the whole edge. It is not per-client limiting, which needs a client identity this layer cannot trust, and belongs in the proxy in front of it.

§Errors

Returns EdgeConfigError::InvalidAuthFailureWindow when window is zero.

Trait Implementations§

Source§

impl Clone for EdgeConfig

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 Debug for EdgeConfig

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<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> 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<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