multistore-metering 0.1.1

Usage metering and quota enforcement middleware for the S3 proxy gateway
Documentation

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

  • Pre-dispatch: [QuotaChecker::check_quota] runs before the request proceeds, using Content-Length as a byte estimate. Return Err(QuotaExceeded) to reject with HTTP 429.
  • Post-dispatch: [UsageRecorder::record_operation] runs after the response is available, recording actual status and byte counts from the backend response.