[management] Add peer connected and disconnected activity events

Closed
ML
1d ago
+366-4

Describe your changes

Admins have no audit trail of when a peer's session with management started or ended, only the last-seen timestamp.

New peer.connect (149) and peer.disconnect (150) events, emitted only when the connection state change is applied, so stale sessions stay silent. Meta is Peer.EventMeta; disconnect adds session_duration in seconds. The initiator is the peer owner, or sys for setup-key peers, which keeps GET /api/events from looking up a user per event.

A management restart makes every peer reconnect, so no session events are recorded during a startup window set by NB_PEER_SESSION_EVENTS_STARTUP_GRACE (Go duration, default 2m, 0 disables), and no disconnect events once shutdown starts draining.

The dashboard login location change that was part of this PR moved to netbirdio/netbird#8626.

Issue ticket number and link

https://github.com/netbirdio/netbird/issues/8616

Stack

Checklist

  • Is it a bug fix
  • Is a typo/documentation fix
  • Is a feature enhancement
  • It is a refactor
  • Created tests that fail without the change (if possible)
  • I ran and tested this change locally — I did not rely on CI to find out whether it works
  • This PR has a single purpose (not a fix + refactor + feature in one)
  • This change is a trivial fix, OR it links an issue the NetBird team agreed on beforehand. Changes to the public API, gRPC protocols, functionality behavior, CLI / service flags, or new features always need that agreement first. See CONTRIBUTING.md.

By submitting this pull request, you confirm that you have read and agree to the terms of the Contributor License Agreement.

Documentation

Select exactly one:

  • I added/updated documentation for this change
  • Documentation is not needed for this change (explain why)

The events are documented in netbirdio/docs#1117; NB_PEER_SESSION_EVENTS_STARTUP_GRACE in netbirdio/docs#1118.

Docs PR URL (required if "docs added" is checked)

Paste the PR link from https://github.com/netbirdio/docs here:

https://github.com/netbirdio/docs/pull/1117