Documentation
¶
Overview ¶
Package ops serves the plain-TCP HTTP operations endpoint (R9 M1, docs/13): /metrics (Prometheus), /healthz, and /statusz. It exists because the WebTransport server is HTTP/3-over-UDP only — Prometheus and curl need a TCP listener. The listener must never be exposed publicly; in the Helm chart it is reachable only through a ClusterIP Service.
Index ¶
- Constants
- func Handler(r *hub.Registry, g prometheus.Gatherer, log *slog.Logger, ready func() bool, ...) http.Handler
- func Run(ctx context.Context, addr string, h http.Handler, log *slog.Logger) error
- func Serve(ctx context.Context, l net.Listener, h http.Handler, log *slog.Logger) error
- func StatuszHandler(r *hub.Registry, log *slog.Logger) http.HandlerFunc
- type AdminAuth
- type AdminAuthOptions
- type AdminOptions
Constants ¶
const ( SchemaAdminBroadcasts = adminapi.SchemaBroadcasts SchemaAdminConfig = adminapi.SchemaConfig )
Schema names, from the shared contract package both this handler and gawk-admin's relayscan compile against (docs/42 §4.5).
Variables ¶
This section is empty.
Functions ¶
func Handler ¶
func Handler(r *hub.Registry, g prometheus.Gatherer, log *slog.Logger, ready func() bool, admin *AdminOptions) http.Handler
Handler builds the ops mux. ready reports whether the relay is accepting new work (false once the SIGTERM drain has begun — R17 W1); nil means always ready. /readyz is the kubelet readiness target and matters for scale-down/HPA hygiene; rollout correctness comes from the active drain, not from readiness (docs/22 Decision 2).
admin adds the R39 credential-gated /internal/admin/* routes (docs/42 §4.5). Nil — or an admin with no credential configured — registers nothing, so those paths 404 exactly as they did before R39. Everything else on this mux is unauthenticated and unchanged: /statusz in particular stays HMAC-only and byte-identical.
func Run ¶
Run listens on addr and serves h until ctx is cancelled. An empty addr means the ops endpoint is disabled: Run returns nil immediately.
func Serve ¶
Serve serves h on l until ctx is cancelled (split from Run so tests can pass an ephemeral-port listener). It returns nil after a graceful shutdown.
func StatuszHandler ¶
StatuszHandler serves the registry snapshot as JSON — the single definition shared by the H3 route (transport) and the TCP ops endpoint, so the two can never drift.
Types ¶
type AdminAuth ¶ added in v0.26.0
type AdminAuth struct {
// contains filtered or unexported fields
}
AdminAuth authorizes one request against the configured credentials.
func NewAdminAuth ¶ added in v0.26.0
func NewAdminAuth(ctx context.Context, opts AdminAuthOptions) *AdminAuth
NewAdminAuth builds the authenticator and, when OIDC is configured, starts background discovery.
It NEVER fails on an unreachable IdP: discovery is retried in the background for as long as ctx lives, and until it succeeds every JWT is rejected with 401. The relay starting is not allowed to depend on the identity provider (docs/42 §6: "the IdP is availability-critical for the portal, never for enforcement").
func (*AdminAuth) Configured ¶ added in v0.26.0
Configured reports whether ANY credential is available. False means the admin routes are never registered — the surface stays dark, not merely locked (docs/42 §4.3).
type AdminAuthOptions ¶ added in v0.26.0
type AdminAuthOptions struct {
// Token is the static -admin-api-token; empty disables that path.
Token string
// Issuer / Audience enable the JWT path; both or neither (config.ParseFlags
// rejects a half-configured pair before we ever get here).
Issuer string
Audience string
// RolesClaim is a dot-path template with oidcroles.Placeholder
// substituted per segment; Role is the value the resolved array must
// contain.
RolesClaim string
Role string
Log *slog.Logger
// HTTPClient talks to the IdP. Nil means a bounded-timeout default —
// never http.DefaultClient, whose zero timeout is an unbounded hang.
HTTPClient *http.Client
// Now defaults to time.Now (tests drive the fetch bucket with it).
Now func() time.Time
// JWKSFetchInterval and JWKSFetchBurst size the JWKS fetch bucket: one
// token accrues per interval, the bucket holds burst of them and starts
// full. Zero means the default (three fetches per minute).
JWKSFetchInterval time.Duration
JWKSFetchBurst int
// contains filtered or unexported fields
}
AdminAuthOptions configures NewAdminAuth. Everything but Log comes straight from config.Config; the rest are test seams.
type AdminOptions ¶ added in v0.26.0
type AdminOptions struct {
// Registry supplies AdminStats.
Registry *hub.Registry
// Config is reported (redacted) by GET /internal/admin/config.
Config config.Config
// Pod names this pod in every response — the portal's per-pod fleet view.
Pod string
// Version is the ldflags-stamped build version.
Version string
// PublisherRemote maps a broadcast ID to its live publisher's source
// address. Supplied by the transport (which owns session bookkeeping);
// nil simply omits the field.
PublisherRemote func(id string) (netip.Addr, bool)
// Auth gates both routes.
Auth *AdminAuth
Log *slog.Logger
}
AdminOptions wires the admin routes. A nil *AdminOptions — or one whose Auth reports no configured credential — leaves the routes UNREGISTERED, so they 404 from the mux rather than 401ing: an unconfigured surface must be indistinguishable from a relay that predates R39.