Skip to content

Watch event pipeline refactor - #746

Merged
brandond merged 14 commits into
k3s-io:masterfrom
brandond:watch-rewrite
Sep 14, 2026
Merged

brandond merged 14 commits into
k3s-io:masterfrom
brandond:watch-rewrite

Conversation

@brandond

@brandond brandond commented Aug 20, 2026 •

Copy link
Copy Markdown
Member

Major refactor of the watch event pipeline, along the lines of the plain laid out in:

Todo:

  • Backends must implement a single watcher that observes events for all keys.
  • Backends must use the existing broadcaster package to fan-out events to multiple client watchers, without filtering events by key prefix.
  • The watch server must see all events from the backend, and perform key range filtering based on the client's requested range.
  • The watch server must track the max revision that each watch has seen, where "seen" means the event was either dropped due to not matching the range, or the event has been enqueued for send to the client if it did match the range.
  • The watch server must only send progress notification messages to a watch if its max seen revision is equal to the backend's current revision. A watcher that has seen the current revision is "synced" in etcd parlance.
  • The watch server must not block the event channels; it should always read all events from the channel
  • The watch server should drop GRPC clients that fall behind on receiving messages. Etcd uses a WatchResponse message queue for this, and drops clients if the queue reaches a maximum size, or if the send fails.
    Leaving this unhandled for now, as it is not something we have done in the past, nor has it caused any problems.

In addition to actually guaranteeing that watchers are synced before sending progress notifications (instead of simply checking that the poll loop has sent events for a revision into the channel), this also does away with the 100 millisecond delay that was artificially added to progress notification responses. This plus the 1 second poll interval was a cause of significant slowness (0.1 to 1.1 seconds * number of namespaced resource types present in the cluster) when the apiserver requested progress notifications to ensure that all resources are deleted from a namespace. (ref k3s-io/k3s#14399)

@brandond
brandond force-pushed the watch-rewrite branch 9 times, most recently from 9ed2fcc to efedd0a Compare August 22, 2026 02:30
@brandond
brandond force-pushed the watch-rewrite branch 3 times, most recently from 3d9263c to 48ef16e Compare September 11, 2026 06:49
@brandond
brandond marked this pull request as ready for review September 11, 2026 07:00
@brandond
brandond requested a review from a team as a code owner September 11, 2026 07:00
@brandond
brandond force-pushed the watch-rewrite branch 3 times, most recently from 843c5a1 to 6e04e69 Compare September 11, 2026 08:36
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
Use test dir as DB path, instead of hash to prevent writing files into working dir

Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
Fixes error where compact would succeed but update compact rev would time out

Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
Allows sending current revision along with events even when no events
pass the key or revision filter.

Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
Avoid allocating the response until we know its actually going to be
sent. Since most eventless sends end up getting surpressed by to the
notification interval, this reduces the number of WatchResponse
allocations by several orders of magnitude.

Signed-off-by: Brad Davidson <brad.davidson@rancher.com>

@manuelbuil manuelbuil left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks very good Brad. It addresses all the points in the issue and the logging looks good for debugging revisions,etc. My only concern is that, If I understand correctly, messages will now stay a bit longer inside Kine before being filtered out. I was wondering if that means any relevant extra CPU/Memory requirement. I guess not

@brandond

brandond commented Sep 14, 2026 •

Copy link
Copy Markdown
Member Author

@manuelbuil they make it through an additional channel before being filtered out now yes, but since all receivers get the same event list there's no additional memory utilization. Just a bit more work for the final goroutine that is now seeing more than it used to.

@brandond
brandond merged commit 4d2a3e4 into k3s-io:master Sep 14, 2026
67 of 68 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants