moonzero · control plane v0.15.0 · 49 packages · 4 targets · Apache-2.0 docs / routing / serverinterceptors GitHub

09 / ROUTING

serverinterceptors

Authentication, tracing, recovery, the stat log, the Prometheus families, the breaker, shedding and the deadline — the eight layers a call passes on its way in, with authentication outermost so a refused peer cannot push the breaker open.

pub(open) trait Authenticator

itemWhat a peer must prove before its call runs. The framework owns the seam and not the scheme: a token check over redis, a signed request, an mTLS peer identity — each is an implementation of this trait, so the interceptor never grows a branch per mechanism.

fn server_tracing( tracer : @trace.Tracer, now~ : () -> Int64 = @telemetry.trace_clock()) -> Interceptor

fnThe server tracing interceptor: open a server span for the call, as a child of the context the client sent, and record the resulting status on it.

fn server_recover(logger? : @logx.Logger) -> Interceptor

fnThe recovery interceptor: an error raised anywhere below is reported as Internal instead of reaching the transport, and logged with its method so the reason is not lost. A handler itself cannot raise — the transport hands it a request and takes back bytes — but a layer added below can.

struct StatConf

structWhat the stat interceptor logs: the slow-call threshold, and the methods whose payload must not reach a log line.

fn StatConf::new( slow_ms~ : Int64 = 500L, ignore_content_methods~ : Array[String] = []) -> StatConf

fnThe default stat policy: half a second counts as slow, and every payload is logged.

fn server_stat( clock : @clock.Clock, conf~ : StatConf = StatConf::new(), logger? : @logx.Logger) -> Interceptor

fnThe stat interceptor: every call is timed, and a slow one is logged with its method. A method in ignore_content_methods is logged without the payload size, so a credential never reaches a log file.

fn server_prometheus( metrics : RpcMetrics, clock : @clock.Clock) -> Interceptor

fnThe server Prometheus interceptor: time the call and count it under its method and status code.

fn server_breaker(breaker : @breaker.Breaker) -> Interceptor

fnThe server breaker interceptor: a shed call never reaches the handler and answers Unavailable. A deadline or a shed on the way in says nothing about this service, so it does not count as a failure.

fn server_shedding(shedder : @shedder.Shedder) -> Interceptor

fnThe shedding interceptor: a call is admitted against the adaptive shedder, and refused with ResourceExhausted when the machine is past its threshold. A refused call is reported to the shedder as a drop; an admitted one is reported by how it ended.

struct MethodTimeout

structA per-method deadline: path gets budget_ms instead of the service's.

fn server_timeout( budget_ms : Int64, clock : @clock.Clock, methods~ : Array[MethodTimeout] = []) -> Interceptor

fnThe timeout interceptor: a call that ran past its budget is reported as DeadlineExceeded. methods overrides the service budget for named paths. The deadline is checked when the handler returns, not raced against a timer: this transport runs the peer in the caller's task, so there is no frame to abandon. A socket-backed server hands the same budget to its read deadline, which does preempt.

fn server_auth(authenticator : &Authenticator) -> Interceptor

fnThe authentication interceptor: a peer that cannot prove itself is refused with Unauthenticated and its call never reaches the handler. It runs outermost, ahead of the breaker and the metric families, so a stream of unauthenticated calls cannot push the breaker open or fill the counters with traffic the service never served.

struct ServerDeps

structEverything the server chain needs that is not a flag.

fn ServerDeps::new( clock~ : @clock.Clock = @clock.Clock::system(), tracer? : @trace.Tracer, breaker? : @breaker.Breaker, shedder? : @shedder.Shedder, metrics? : RpcMetrics, authenticator? : &Authenticator, now? : () -> Int64, timeout_ms~ : Int64 = 2000L, stat~ : StatConf = StatConf::new()) -> ServerDeps raise @metric.Refused

fnThe dependencies for a server config, with every seam at its default: a system clock, a discarding tracer, a fresh breaker and shedder, and no authenticator — a server that does not say who may call it accepts anybody, which is what Auth: false means.

fn server_interceptors( conf : @conf.RpcServerMiddlewaresConf, deps : ServerDeps) -> Array[Interceptor]

fnThe server chain conf asks for, outermost first: authentication, tracing, recovery, the stat log, the metric families, the breaker, shedding and the deadline.