ops

package
v0.42.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 20, 2026 License: Apache-2.0 Imports: 21 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const (
	SchemaAdminBroadcasts = adminapi.SchemaBroadcasts
	SchemaAdminConfig     = adminapi.SchemaConfig
	SchemaAdminRooms      = adminapi.SchemaRooms
	SchemaAdminPops       = adminapi.SchemaPops
)

Schema names, from the shared contract package both this handler and gawk-admin's relayscan compile against (docs/42 §4.5).

View Source
const PublicStatuszMaxAge = time.Second

PublicStatuszMaxAge is how long the public H3 route serves one snapshot. That route is unauthenticated, and a snapshot walks every broadcast and subscriber under Registry.mu, the lock every relayed datagram takes, so without a bound anyone could stall fan-out by polling it. One second keeps the document useful for a human watching counters and makes a flood cost one snapshot per second however many requests arrive.

Variables

This section is empty.

Functions

func CachedStatuszHandler added in v0.41.1

func CachedStatuszHandler(r *hub.Registry, rooms RoomStatsSource, log *slog.Logger, maxAge time.Duration) http.HandlerFunc

CachedStatuszHandler is StatuszHandler for a listener strangers can reach: it builds at most one snapshot per maxAge and serves the stored bytes to everyone else. Requests that arrive while a snapshot is being built wait for it instead of building their own. The document is the same one StatuszHandler writes, up to maxAge old.

func Handler

func Handler(r *hub.Registry, rooms RoomStatsSource, g prometheus.Gatherer, log *slog.Logger, ready func() bool, admin *AdminOptions, screening *ScreeningOptions, extra ...Route) 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.

screening adds R40's keyframe route under its own token (docs/71 D1). Nil — or an empty token — registers nothing: the path 404s. extra adds routes only the ops listener serves, unauthenticated like /statusz there: R77's /internal/telemetry/pops (docs/78 D7).

func Run

func Run(ctx context.Context, addr string, h http.Handler, log *slog.Logger) error

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

func Serve(ctx context.Context, l net.Listener, h http.Handler, log *slog.Logger) error

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

func StatuszHandler(r *hub.Registry, rooms RoomStatsSource, log *slog.Logger) http.HandlerFunc

StatuszHandler serves the registry snapshot as JSON, built fresh for each request. It is the ops listener's handler; the public H3 route serves the same document through CachedStatuszHandler. rooms may be nil (no rooms section).

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

func (a *AdminAuth) Configured() bool

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)
	// Rooms snapshots the rooms this pod is home for, with raw codes and
	// the live roster (R49, docs/50 D2). Nil — -rooms off — serves an
	// empty list: a relay without rooms has nothing to say, and the
	// credential gate is the only gate the route needs (D11).
	Rooms func() []adminapi.Room
	// Pops snapshots the PoPs whose link this pod holds (R74, docs/76 §9),
	// with their public and LAN addresses. Nil — -pops off — serves an
	// empty list.
	Pops func() []adminapi.PopState
	// Auth gates every route.
	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.

type RoomStatsSource added in v0.27.0

type RoomStatsSource interface {
	Stats() map[string]roomsrv.RoomStats
}

RoomStatsSource is the /statusz rooms section (R42, docs/44 §4.10): rows keyed by the per-process HMAC of the code, never the code. An interface so ops keeps its one-way dependency shape; roomsrv.Registry implements it.

type Route added in v0.37.0

type Route struct {
	Pattern string
	Handler http.Handler
}

Route is one extra ops-only route (Handler's extra).

type ScreeningOptions added in v0.33.0

type ScreeningOptions struct {
	Registry *hub.Registry
	// Token is -screening-token, already trimmed by config.ParseFlags.
	Token string
	Log   *slog.Logger
}

ScreeningOptions wires the keyframe route. A nil *ScreeningOptions, an empty Token or a nil Registry leaves it UNREGISTERED.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL