Skip to main content

Crate multistore_metering

Crate multistore_metering 

Source
Expand description

Usage metering and quota enforcement middleware.

This crate provides trait abstractions for tracking API usage and enforcing quotas, along with a MeteringMiddleware that wires them into the proxy’s middleware chain. Integrators bring their own storage backends by implementing UsageRecorder and QuotaChecker.

§Quick start

use multistore_metering::{MeteringMiddleware, UsageRecorder, QuotaChecker};

// Implement UsageRecorder and QuotaChecker for your storage backend,
// then register the middleware on the ProxyGateway builder:
let metering = MeteringMiddleware::new(my_quota_checker, my_usage_recorder);
gateway_builder.add_middleware(metering);

§Architecture

Structs§

MeteringMiddleware
Middleware that enforces quotas pre-dispatch and records usage post-dispatch.
NoopQuotaChecker
A QuotaChecker that always allows requests. Useful when only usage recording is needed, or for testing.
NoopRecorder
A UsageRecorder that does nothing. Useful when only quota checking is needed, or for testing.
QuotaExceeded
Quota violation error returned by QuotaChecker::check_quota.
UsageEvent
A completed operation’s metadata, passed to UsageRecorder::record_operation.

Traits§

QuotaChecker
Pre-dispatch quota enforcement.
UsageRecorder
Records completed operations for usage tracking.