util/eventbus: add debugger methods to list pub/sub types

This lets debug tools list the types that clients are wielding, so
that they can build a dataflow graph and other debugging views.

Updates #15160

Signed-off-by: David Anderson <dave@tailscale.com>
This commit is contained in:
David Anderson
2025-03-07 08:16:53 -08:00
committed by Dave Anderson
parent e71e95b841
commit 346a35f612
3 changed files with 50 additions and 0 deletions

View File

@@ -120,6 +120,20 @@ func (s *subscribeState) snapshotQueue() []DeliveredEvent {
}
}
func (s *subscribeState) subscribeTypes() []reflect.Type {
if s == nil {
return nil
}
s.outputsMu.Lock()
defer s.outputsMu.Unlock()
ret := make([]reflect.Type, 0, len(s.outputs))
for t := range s.outputs {
ret = append(ret, t)
}
return ret
}
func (s *subscribeState) addSubscriber(t reflect.Type, sub subscriber) {
s.outputsMu.Lock()
defer s.outputsMu.Unlock()