observability: logstream-hub — the Go log-stream hub behind its follow-function seam #806

Closed
opened 2026-08-25 10:58:30 +00:00 by matou-build-agent · 2 comments

Parent

Feature spec: #791 — control-panel observability child spec: logs (P10) (DDR 0203).
Design ticket #760; slice-map fan-in #770; wayfinder map #7.
Slice logstream-hub of docs/slices/observability.yaml; covers spec #791 stories 35–37.

What to build

The control plane gains a log-stream hub — a component of its own process, no new port and no
new ingress surface — seamed at its follow function (the prototype's FollowFunc shape) so
that multiplexing, ref-counting, tail, rate cap, ring and drop-oldest are all provable against a
fake follow with no containers, no units and no fleet.

The mechanics: N subscribers on one log target hold one underlying follow, ref-counted,
released when the last subscriber leaves — and a subscriber leaving never interrupts the others.
A new subscriber gets the target's tail of 200 lines immediately from the ring, then live
lines. A target producing faster than 200 lines/s is capped per target rather than flooding
every subscriber. The per-target 2000-line ring is drop-oldest, and it is what a reconnecting
or resuming client backfills from — backfill is the ring's job, not the client's, which is
why a reconnecting client need remember only its last line. A slow subscriber has lines
dropped for it rather than blocking the target or any other subscriber.

Bounds are configuration, not constants scattered through the code.

Acceptance criteria

  • (story 35) Given N subscribers on the same log target, then the hub holds exactly one underlying follow, ref-counted, and releases it when the last subscriber leaves — a subscriber leaving never interrupts the others.
  • (story 35) Given a new subscriber, then it receives the target's tail of 200 lines immediately from the ring, then live lines.
  • (story 35) Given a target producing faster than 200 lines/s, then the hub caps at that rate per target rather than flooding every subscriber.
  • (story 35) Given the per-target 2000-line ring, then it is drop-oldest and is what a reconnecting or resuming client backfills from.
  • (story 35) Given a slow subscriber, then the hub drops lines for that subscriber rather than blocking the target or any other subscriber.
  • Given a follow that errors, then it surfaces as a stream end rather than a hang.
  • (story 40) Given the hub, then it is a component of the control plane's own process with no new port and no new ingress surface, and the bounds are read from configuration rather than hard-coded at call sites.

Blocked by

  • bootstrap:skeleton (#23 — done, satisfied)

Task manifest

task: observability:logstream-hub
interface: a Go log-stream hub constructed over a follow function ("give me a follow on this target"),
  exposing subscribe / release with ref-counted multiplexing, tail-on-subscribe, a per-target rate cap,
  a per-target drop-oldest ring and slow-subscriber drop
seam: 'the hub''s own Go unit tests at its follow function (prior art: the prototype''s `hub_test` / `demux_test`
  / `follow_test` port, plus `monitor_test.go`''s shape) — driven against a fake follow with no containers,
  units or fleet'
acceptance:
- given: N subscribers on one log target
  when: they subscribe and one leaves
  then: one underlying follow is held throughout and the remaining subscribers are uninterrupted
- given: a new subscriber on a target with history
  when: it subscribes
  then: it receives the tail of 200 lines from the ring, then live lines
- given: a target emitting faster than 200 lines/s
  when: the hub forwards
  then: the per-target rate cap holds
- given: a subscriber that consumes slowly
  when: lines arrive
  then: lines are dropped for that subscriber and neither the target nor any other subscriber blocks
- given: a follow that errors
  when: the hub observes it
  then: it surfaces as a stream end, never a hang
depends_on:
- bootstrap:skeleton
out_of_scope:
- the SSE route and the bounded download (`transport-log-stream-sse`)
- scope → target resolution and the catalogue (`transport-log-catalogue`)
- any log store, index or time-range query — the ring and the bounded operation logs are the whole of
  retention
- dropped-line counting for slow clients — the bounds are stated honestly in the meta line instead
- a new port, ingress surface or agent
needs_human_decision: []

Emitted by /to-tickets over docs/slices/observability.yaml in an unattended session under ADR 0174 (two-way-door posture — Ben's veto is asynchronous, never blocking). Advances #797.

## Parent Feature spec: **#791** — control-panel observability child spec: logs (P10) (DDR 0203). Design ticket #760; slice-map fan-in **#770**; wayfinder map #7. Slice `logstream-hub` of `docs/slices/observability.yaml`; covers spec #791 stories 35–37. ## What to build The control plane gains a **log-stream hub** — a component of its own process, no new port and no new ingress surface — seamed at its **follow function** (the prototype's `FollowFunc` shape) so that multiplexing, ref-counting, tail, rate cap, ring and drop-oldest are all provable against a fake follow with **no containers, no units and no fleet**. The mechanics: N subscribers on one log target hold **one** underlying follow, ref-counted, released when the last subscriber leaves — and a subscriber leaving never interrupts the others. A new subscriber gets the target's **tail of 200 lines** immediately from the ring, then live lines. A target producing faster than **200 lines/s** is capped per target rather than flooding every subscriber. The per-target **2000-line ring** is drop-oldest, and it is what a reconnecting or resuming client backfills from — **backfill is the ring's job, not the client's**, which is why a reconnecting client need remember only its last line. A **slow subscriber** has lines dropped for it rather than blocking the target or any other subscriber. Bounds are configuration, not constants scattered through the code. ## Acceptance criteria - [ ] (story 35) Given N subscribers on the same log target, then the hub holds exactly **one** underlying follow, ref-counted, and releases it when the last subscriber leaves — a subscriber leaving never interrupts the others. - [ ] (story 35) Given a new subscriber, then it receives the target's tail of **200** lines immediately from the ring, then live lines. - [ ] (story 35) Given a target producing faster than **200 lines/s**, then the hub caps at that rate per target rather than flooding every subscriber. - [ ] (story 35) Given the per-target **2000-line** ring, then it is drop-oldest and is what a reconnecting or resuming client backfills from. - [ ] (story 35) Given a slow subscriber, then the hub drops lines for that subscriber rather than blocking the target or any other subscriber. - [ ] Given a follow that errors, then it surfaces as a stream end rather than a hang. - [ ] (story 40) Given the hub, then it is a component of the control plane's own process with **no new port and no new ingress surface**, and the bounds are read from configuration rather than hard-coded at call sites. ## Blocked by - `bootstrap:skeleton` (#23 — done, satisfied) ## Task manifest ```yaml task: observability:logstream-hub interface: a Go log-stream hub constructed over a follow function ("give me a follow on this target"), exposing subscribe / release with ref-counted multiplexing, tail-on-subscribe, a per-target rate cap, a per-target drop-oldest ring and slow-subscriber drop seam: 'the hub''s own Go unit tests at its follow function (prior art: the prototype''s `hub_test` / `demux_test` / `follow_test` port, plus `monitor_test.go`''s shape) — driven against a fake follow with no containers, units or fleet' acceptance: - given: N subscribers on one log target when: they subscribe and one leaves then: one underlying follow is held throughout and the remaining subscribers are uninterrupted - given: a new subscriber on a target with history when: it subscribes then: it receives the tail of 200 lines from the ring, then live lines - given: a target emitting faster than 200 lines/s when: the hub forwards then: the per-target rate cap holds - given: a subscriber that consumes slowly when: lines arrive then: lines are dropped for that subscriber and neither the target nor any other subscriber blocks - given: a follow that errors when: the hub observes it then: it surfaces as a stream end, never a hang depends_on: - bootstrap:skeleton out_of_scope: - the SSE route and the bounded download (`transport-log-stream-sse`) - scope → target resolution and the catalogue (`transport-log-catalogue`) - any log store, index or time-range query — the ring and the bounded operation logs are the whole of retention - dropped-line counting for slow clients — the bounds are stated honestly in the meta line instead - a new port, ingress surface or agent needs_human_decision: [] ``` --- *Emitted by `/to-tickets` over `docs/slices/observability.yaml` in an unattended session under ADR 0174 (two-way-door posture — Ben's veto is asynchronous, never blocking). Advances #797.*
Author
Member

swarm-claim host=matou-dev-server-01 run=10067
(automated multi-host claim — lowest live claim id works this ticket)

swarm-claim host=matou-dev-server-01 run=10067 (automated multi-host claim — lowest live claim id works this ticket)
Author
Member

close-report for #806 — status success

✅ close-report gates passed — every claim verified against main; issue closed.

envelope
{
  "issue": 806,
  "status": "success",
  "commits": [
    "edc901877005ae21e0d7365acf80d527dd02b79a"
  ],
  "changed_files": [
    "STATUS.md",
    "internal/logstream/logstream.go",
    "internal/logstream/logstream_test.go"
  ],
  "tests": [
    {
      "command": "go test -race -count=1 ./internal/logstream/",
      "exit_code": 0
    },
    {
      "command": "golangci-lint run ./internal/logstream/...",
      "exit_code": 0
    },
    {
      "command": "go vet ./internal/logstream/",
      "exit_code": 0
    },
    {
      "command": "gofmt -l internal/logstream/",
      "exit_code": 0
    }
  ],
  "criteria": {
    "(story 35) N subscribers → exactly one ref-counted follow, released on last leave, a leaver never interrupts the others": "internal/logstream/logstream.go Hub.subscribe/targetStream.remove/newTargetStream; TestOneFollowPerTargetRefCounted (opens==1 for 3 subs, others keep receiving after one Release, follow released on last leave)",
    "(story 35) a new subscriber receives the tail of 200 lines from the ring, then live lines": "ring.tail + subscribe snapshotting under ts.mu; TestTailOnSubscribeThenLive (late subscriber gets seq 51..250 then live 251)",
    "(story 35) a target producing faster than 200 lines/s is capped per target": "targetStream.forward + limiter.allow (token bucket on injected clock); TestPerTargetRateCap (exactly 200 of 1000 admitted) + TestRateLimiterRefills (200/s refill)",
    "(story 35) the per-target 2000-line ring is drop-oldest and is what a reconnecting/resuming client backfills from": "ring (drop-oldest circular) + Hub.Resume/ring.after; TestResumeBackfillsFromRing (Resume after 250 → 251..300) + TestRingDropsOldestToItsBound (RingSize 10 → only 21..30 backfilled)",
    "(story 35) a slow subscriber has lines dropped for it rather than blocking the target or any other subscriber": "forward non-blocking fan-out into bounded sub.live; TestSlowSubscriberDropsNotBlocks (fast sub gets all 150 in order while unread slow sub drops)",
    "a follow that errors surfaces as a stream end rather than a hang": "pump closes on lines-channel close or ctx; shutdown closes every sub.live → relay closes out; TestFollowEndSurfacesAsStreamEnd (stream ends, targets==0)",
    "(story 40) the hub is a component of the control plane's own process with no new port/ingress, and bounds are read from configuration": "internal/logstream is a library package (no port/binary/ingress); Config{Tail,RingSize,RatePerSecond,SubscriberBuffer} with withDefaults; TestConfigDefaults pins the DDR 0203 bounds"
  },
  "summary": "Built the control-plane log-stream hub (internal/logstream) — ref-counted multiplexed follows, tail-on-subscribe, per-target rate cap, 2000-line drop-oldest ring for backfill, slow-subscriber drop, follow-end-as-stream-end — behind its FollowFunc seam, proved by 12 tests against a fake follow and fake clock.",
  "blockers": []
}
**close-report** for #806 — status `success` :white_check_mark: **close-report gates passed** — every claim verified against main; issue closed. <details><summary>envelope</summary> ```json { "issue": 806, "status": "success", "commits": [ "edc901877005ae21e0d7365acf80d527dd02b79a" ], "changed_files": [ "STATUS.md", "internal/logstream/logstream.go", "internal/logstream/logstream_test.go" ], "tests": [ { "command": "go test -race -count=1 ./internal/logstream/", "exit_code": 0 }, { "command": "golangci-lint run ./internal/logstream/...", "exit_code": 0 }, { "command": "go vet ./internal/logstream/", "exit_code": 0 }, { "command": "gofmt -l internal/logstream/", "exit_code": 0 } ], "criteria": { "(story 35) N subscribers → exactly one ref-counted follow, released on last leave, a leaver never interrupts the others": "internal/logstream/logstream.go Hub.subscribe/targetStream.remove/newTargetStream; TestOneFollowPerTargetRefCounted (opens==1 for 3 subs, others keep receiving after one Release, follow released on last leave)", "(story 35) a new subscriber receives the tail of 200 lines from the ring, then live lines": "ring.tail + subscribe snapshotting under ts.mu; TestTailOnSubscribeThenLive (late subscriber gets seq 51..250 then live 251)", "(story 35) a target producing faster than 200 lines/s is capped per target": "targetStream.forward + limiter.allow (token bucket on injected clock); TestPerTargetRateCap (exactly 200 of 1000 admitted) + TestRateLimiterRefills (200/s refill)", "(story 35) the per-target 2000-line ring is drop-oldest and is what a reconnecting/resuming client backfills from": "ring (drop-oldest circular) + Hub.Resume/ring.after; TestResumeBackfillsFromRing (Resume after 250 → 251..300) + TestRingDropsOldestToItsBound (RingSize 10 → only 21..30 backfilled)", "(story 35) a slow subscriber has lines dropped for it rather than blocking the target or any other subscriber": "forward non-blocking fan-out into bounded sub.live; TestSlowSubscriberDropsNotBlocks (fast sub gets all 150 in order while unread slow sub drops)", "a follow that errors surfaces as a stream end rather than a hang": "pump closes on lines-channel close or ctx; shutdown closes every sub.live → relay closes out; TestFollowEndSurfacesAsStreamEnd (stream ends, targets==0)", "(story 40) the hub is a component of the control plane's own process with no new port/ingress, and bounds are read from configuration": "internal/logstream is a library package (no port/binary/ingress); Config{Tail,RingSize,RatePerSecond,SubscriberBuffer} with withDefaults; TestConfigDefaults pins the DDR 0203 bounds" }, "summary": "Built the control-plane log-stream hub (internal/logstream) — ref-counted multiplexed follows, tail-on-subscribe, per-target rate cap, 2000-line drop-oldest ring for backfill, slow-subscriber drop, follow-end-as-stream-end — behind its FollowFunc seam, proved by 12 tests against a fake follow and fake clock.", "blockers": [] } ``` </details>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
Matou/idss#806
No description provided.