plecto_control/control_observability.rs
1//! `Control`'s observability surface (ADR 000009 Stage A): the host-aggregated filter-execution
2//! metrics snapshot and the operator-configured admin/access-log settings the fast path reads.
3
4use std::sync::Arc;
5
6use plecto_host::MetricsSnapshot;
7use plecto_host::otlp::OtlpBuffer;
8
9use crate::Control;
10
11impl Control {
12 /// A snapshot of the host-aggregated filter-execution metrics (ADR 000009): the tally the
13 /// `MetricsSink` wired at construction has accumulated. The fast path's admin `/metrics`
14 /// endpoint renders this alongside its native RED metrics.
15 pub fn filter_metrics(&self) -> MetricsSnapshot {
16 self.filter_metrics.snapshot()
17 }
18
19 /// The admin endpoint bind address (`[observability] admin_addr`), or `None` when no admin
20 /// listener is configured (the default). The fast path binds a separate listener there for
21 /// `/metrics` + liveness/readiness (ADR 000009 Stage A).
22 pub fn admin_addr(&self) -> Option<&str> {
23 self.observability.admin_addr.as_deref()
24 }
25
26 /// Whether the structured access log is enabled (`[observability] access_log`, ADR 000009).
27 pub fn access_log_enabled(&self) -> bool {
28 self.observability.access_log
29 }
30
31 /// The OTLP/HTTP collector base URL (`[observability] otlp_endpoint`, ADR 000040), or `None`
32 /// when trace export is off (the default). The exporter appends `/v1/traces`.
33 pub fn otlp_endpoint(&self) -> Option<&str> {
34 self.observability.otlp_endpoint.as_deref()
35 }
36
37 /// The OTLP span buffer (ADR 000040): filter spans fan into it from the host sink, the fast
38 /// path pushes its request span, and the export pump drains it. Present iff
39 /// [`otlp_endpoint`](Self::otlp_endpoint) is set.
40 pub fn otlp_buffer(&self) -> Option<Arc<OtlpBuffer>> {
41 self.otlp.clone()
42 }
43
44 /// The manifest's data-plane bind address (`[listen] addr`), or `None` for the binary default.
45 /// Captured at construction, like `admin_addr` — a reload does not re-bind; the CLI's explicit
46 /// positional arg overrides it.
47 pub fn listen_addr(&self) -> Option<&str> {
48 self.listen.addr.as_deref()
49 }
50
51 /// The `Alt-Svc` h3 advertisement port override (`[listen] advertised_port`), or `None` to
52 /// advertise the bound port. For container port mappings where the published port differs
53 /// from the bound one (moka-1 field report §3.4).
54 pub fn advertised_port(&self) -> Option<u16> {
55 self.listen.advertised_port
56 }
57
58 /// The parsed `[listen.proxy_protocol]` trusted networks (ADR 000057), or `None` when PROXY
59 /// v2 reception is off (the default). Captured at construction like `listen_addr` — the TCP
60 /// listener consults it once at startup; a reload does not change it. The h3/UDP listener is
61 /// out of scope (ADR 000057 decision 5).
62 pub fn proxy_protocol_trust(&self) -> Option<crate::manifest::ProxyProtocolTrust> {
63 self.proxy_protocol.clone()
64 }
65
66 /// The readiness grace (`[listen.drain] readiness_grace_ms`, ADR 000059): how long `/readyz`
67 /// reports not-ready — while connections are still accepted — before the drain starts, so a
68 /// front load balancer can take the replica out of rotation first. Zero (the default) starts
69 /// the drain immediately. Captured at construction like the rest of `[listen]`.
70 pub fn readiness_grace(&self) -> std::time::Duration {
71 let ms = self
72 .listen
73 .drain
74 .as_ref()
75 .and_then(|d| d.readiness_grace_ms)
76 .unwrap_or(0);
77 std::time::Duration::from_millis(ms)
78 }
79
80 /// The drain window (`[listen.drain] window_ms`, ADR 000059): how long in-flight work may
81 /// finish at shutdown before remaining connections are cut. `None` = the server's default
82 /// (30 s). One setting shared by every drain path (TCP requests, h3 GOAWAY, tunnels).
83 pub fn drain_window(&self) -> Option<std::time::Duration> {
84 self.listen
85 .drain
86 .as_ref()
87 .and_then(|d| d.window_ms)
88 .map(std::time::Duration::from_millis)
89 }
90}