feat: implement shared watch stream - #176
Draft
smira wants to merge 2 commits into
Draft
Conversation
This ensures consistency across concurrent Watch* calls vs. the watch client, mostly important for COSI runtime. Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
There was a problem hiding this comment.
Pull request overview
This PR adds an optional “shared watch” mode to the etcd-backed State, where all Watch* calls (except bookmark-resume watches) are served by a single etcd watcher plus an internal dispatcher/queueing layer to provide consistent per-destination-channel delivery ordering—primarily to satisfy COSI controller runtime expectations.
Changes:
- Introduces a shared watcher multiplexer (
watchMux) and per-destination output queues (outQueue) to serialize delivery without blocking the dispatcher. - Adds
WithSharedWatch()state option and wires it intoState.Watch/State.WatchKind*to switch between shared vs dedicated watcher paths. - Expands test coverage to run existing suites in both modes and adds dedicated ordering/restart tests for shared watch.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/state/impl/etcd/watchqueue.go | New per-destination delivery queue used by the shared watch dispatcher. |
| pkg/state/impl/etcd/watchmux.go | New shared watcher multiplexer, subscription index, bootstrap splicing, and dispatch logic. |
| pkg/state/impl/etcd/options.go | Adds sharedWatch option and WithSharedWatch() API with detailed behavior docs. |
| pkg/state/impl/etcd/etcd.go | Adds State.mux and routes eligible Watch* calls through the shared watcher path. |
| pkg/state/impl/etcd/key.go | Adds helper to derive kind-prefix from a full etcd key for dispatch grouping. |
| pkg/state/impl/etcd/watch_test.go | Runs key watch regression tests in both dedicated and shared watch modes. |
| pkg/state/impl/etcd/watch_ordering_test.go | New tests verifying cross-kind ordering, bootstrap consistency, restart, and single etcd watcher behavior under shared watch. |
| pkg/state/impl/etcd/state_test.go | Runs state conformance suite with WithSharedWatch() enabled. |
| pkg/state/impl/etcd/controller_runtime_test.go | Runs controller runtime conformance suite with WithSharedWatch() enabled. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+86
to
+95
| case <-q.done: | ||
| // deliver whatever was enqueued just before the shutdown, notably the Errored events | ||
| // reporting why the shared watcher went away | ||
| for _, item := range q.take() { | ||
| if !item.sub.send(item.events) { | ||
| break | ||
| } | ||
| } | ||
|
|
||
| return |
Comment on lines
+418
to
+420
| for _, sub := range subs { | ||
| sub.deliver(converted) | ||
| } |
Pull in new etcd, update Go deps, rekres. Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
smira
marked this pull request as draft
August 4, 2026 12:29
smira
marked this pull request as draft
August 4, 2026 12:29
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This ensures consistency across concurrent Watch* calls vs. the watch client, mostly important for COSI runtime.