Documentation
¶
Overview ¶
Package posture builds the live `protocol.PostureDeps.Counters` and `protocol.PostureDeps.Metrics` seams over the real runtime subsystems.
Why this package exists (§17.6 F3) ¶
The posture surface takes a `Counters` and a `Metrics` callback. The `harbor dev` / `harbor console` boot path and the `harbortest/devstack` test-fixture assembler BOTH need to wire those callbacks to live state — not to an empty `types.RuntimeCounters{}` / `types.MetricsSnapshot{}` stub. A stub passes a fabricated-seam integration test while production returns all-zero; that is exactly the test↔production divergence CLAUDE.md §17.6 forbids. This package is the single shared implementation both call sites consume so the fixture cannot drift from production.
Counters reads the task registry's per-identity running / background task counts, the session registry's active-session count, and (when supplied) the MCP registry's healthy-server count. EventsPerSecond stays zero — the runtime exposes no bus-rate meter at V1; reporting zero for a counter the runtime genuinely cannot measure is honest, not a silent degradation of a known value.
Metrics projects the telemetry.MetricsRegistry's bus-fed counter snapshot onto the Protocol-shaped `types.MetricsSnapshot`.
Index ¶
- func CountersProvider(taskReg tasks.TaskRegistry, lister sessions.SessionLister, ...) func(context.Context, identity.Identity) types.RuntimeCounters
- func DriversFromConfig(cfg *config.Config) []types.SubsystemDriver
- func HealthFromConfig(cfg *config.Config) []types.SubsystemHealth
- func MetricsProvider(reg *telemetry.MetricsRegistry, log *slog.Logger) func(context.Context) types.MetricsSnapshot
- func RetentionProvider(bus events.EventBus, taskReg tasks.TaskRegistry, lister sessions.SessionLister) func(context.Context, identity.Identity) []types.RetentionHorizon
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CountersProvider ¶
func CountersProvider(taskReg tasks.TaskRegistry, lister sessions.SessionLister, mcpReg *mcpdrv.Registry) func(context.Context, identity.Identity) types.RuntimeCounters
CountersProvider returns a `protocol.PostureDeps.Counters` seam that reads live runtime state. taskReg supplies the running / background task counts for the caller's session; lister supplies the active-session count scoped to the requested identity's tenant; mcpReg supplies the healthy-MCP-connection count (server-wide, not per-identity — MCP servers are a runtime-shared resource).
The returned func never panics: a registry read error degrades that one counter to its zero value while the others still report — a posture read is a best-effort observability snapshot, never a load-bearing control path. A genuinely missing dependency (a nil taskReg / lister / mcpReg) is a wiring bug the caller must catch at boot, so CountersProvider returns a func that simply reports zeros for the missing subsystem rather than nil-panicking on first request.
a walkthrough fix: pre-fix the MCP counter was hard-coded zero (An earlier phase shipped previously F6 wired the MCP registry into the Console-facing surface). With the registry now reachable from the dev boot path, threading it into CountersProvider makes the Overview page's MCP CONNECTIONS pillar honest — it reports the actual count of `state == Online` servers, not a placeholder zero.
func DriversFromConfig ¶
func DriversFromConfig(cfg *config.Config) []types.SubsystemDriver
DriversFromConfig builds the `runtime.drivers` seam — the configured driver name per persistence-shaped subsystem. Never the DSN (CLAUDE.md §7) — the driver name only.
Like HealthFromConfig, this is the single shared implementation both the production boot path and the devstack fixture assembler consume.
func HealthFromConfig ¶
func HealthFromConfig(cfg *config.Config) []types.SubsystemHealth
HealthFromConfig builds the `runtime.health` seam from the resolved config. The in-process dev / devstack assembly is fully wired by the time the posture surface is constructed, so every persistence-shaped subsystem reports `ready`.
This is the single shared implementation consumed by BOTH the `harbor dev` / `harbor console` boot path and the `harbortest/devstack` fixture assembler — neither hand-rolls its own copy, so the fixture cannot drift from production (CLAUDE.md §17.6; a checkpoint cleanup).
func MetricsProvider ¶
func MetricsProvider(reg *telemetry.MetricsRegistry, log *slog.Logger) func(context.Context) types.MetricsSnapshot
MetricsProvider returns a `protocol.PostureDeps.Metrics` seam that projects the telemetry.MetricsRegistry's live counter snapshot onto the Protocol-shaped `types.MetricsSnapshot`.
A registry Snapshot failure is logged at Warn and degrades to an empty (but non-nil) snapshot — a metrics read failure must not fail the whole posture request, but it is never silent (CLAUDE.md §13: the failure is surfaced in the log, not swallowed).
func RetentionProvider ¶ added in v1.13.0
func RetentionProvider(bus events.EventBus, taskReg tasks.TaskRegistry, lister sessions.SessionLister) func(context.Context, identity.Identity) []types.RetentionHorizon
RetentionProvider returns a `protocol.PostureDeps.Retention` seam that reports the OBSERVED oldest-retained timestamp per durable surface — the honest, forward-looking retention horizon a fleet consumer reads before issuing a windowed read. Every value is read live from the store; NONE is a configured claim (Harbor has no retention knob — the durable log is gap-free and untrimmed).
Read scope mirrors CountersProvider — the shared posture-read posture:
- events: the bus's runtime-wide oldest retained event (a bare wall-clock instant, no identity content), sourced through the optional events.RetentionReporter capability both V1 bus drivers implement. A bus that reports none (empty log/ring, or a driver without the seam) contributes no events entry.
- tasks: the oldest CreatedAt across the tasks retained in the caller's session scope.
- sessions: the oldest OpenedAt across the sessions retained in the caller's tenant (open OR closed-but-retained — "oldest retained", not "oldest ever", since the registry's idle GC reaps old sessions).
A surface with no retained rows contributes no entry (its horizon is absent, never a fabricated zero). A registry read error degrades that one surface to absent while the others still report — a posture read is a best-effort observability snapshot, never a load-bearing path. A nil dependency simply omits that surface.
Types ¶
This section is empty.