mirror of
https://github.com/tailscale/tailscale.git
synced 2025-08-25 20:57:31 +00:00
util/eventbus: initial debugging facilities for the event bus
Enables monitoring events as they flow, listing bus clients, and snapshotting internal queues to troubleshoot stalls. Updates #15160 Signed-off-by: David Anderson <dave@tailscale.com>
This commit is contained in:

committed by
Dave Anderson

parent
5ce8cd5fec
commit
853abf8661
@@ -19,13 +19,15 @@ import (
|
||||
type Client struct {
|
||||
name string
|
||||
bus *Bus
|
||||
publishDebug hook[publishedEvent]
|
||||
publishDebug hook[PublishedEvent]
|
||||
|
||||
mu sync.Mutex
|
||||
pub set.Set[publisher]
|
||||
sub *subscribeState // Lazily created on first subscribe
|
||||
}
|
||||
|
||||
func (c *Client) Name() string { return c.name }
|
||||
|
||||
// Close closes the client. Implicitly closes all publishers and
|
||||
// subscribers obtained from this client.
|
||||
func (c *Client) Close() {
|
||||
@@ -47,6 +49,16 @@ func (c *Client) Close() {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Client) snapshotSubscribeQueue() []DeliveredEvent {
|
||||
return c.peekSubscribeState().snapshotQueue()
|
||||
}
|
||||
|
||||
func (c *Client) peekSubscribeState() *subscribeState {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
return c.sub
|
||||
}
|
||||
|
||||
func (c *Client) subscribeState() *subscribeState {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
@@ -76,7 +88,7 @@ func (c *Client) deleteSubscriber(t reflect.Type, s *subscribeState) {
|
||||
c.bus.unsubscribe(t, s)
|
||||
}
|
||||
|
||||
func (c *Client) publish() chan<- publishedEvent {
|
||||
func (c *Client) publish() chan<- PublishedEvent {
|
||||
return c.bus.write
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user