Initial plumbing for metrics. (#2950)

* Initial plumbing for metrics.

This implements
- metrics received from participant.
- callback to room.
- room distributes it to all other participants (excluding the sending
  participant).
- other participants forward to client.
- counting metrics bytes in data channel stats

TODO:
  - recording/processing/batching
  - should recording/processing/batching happen on publisher side or
    subscriber side?
  - should metrics be echoed back to publisher?
  - grants to publish/subscribe metrics.

* mage generate

* clear OnMetrics on close

* - CanSubscribeMetrics permission.
- Echo back to sender.

* update deps

* No destination identities for metrics

* WIP

* use normalized timestamp for server injected timestamps

* compile

* debug log metrics batch

* correct comment

* add baseTime to wire

* protocol dep

* Scope metrics forwarding to only participants that a participant is
subscribed to.

Also remove the participant_metrics.go file as it was not doing anything
useful.

* update comment

* utils.ErrorIsOneOf

* couple of more utils.CloneProto
This commit is contained in:
Raja Subramanian
2024-09-19 11:42:31 +05:30
committed by GitHub
parent 4deaac2f3f
commit 7df6f86693
23 changed files with 488 additions and 55 deletions
+6
View File
@@ -66,6 +66,8 @@ type iceConfigCacheKey struct {
type RoomManager struct {
lock sync.RWMutex
baseTime time.Time
config *config.Config
rtcConfig *rtc.WebRTCConfig
serverInfo *livekit.ServerInfo
@@ -95,6 +97,7 @@ type RoomManager struct {
}
func NewLocalRoomManager(
baseTime time.Time,
conf *config.Config,
roomStore ObjectStore,
currentNode routing.LocalNode,
@@ -116,6 +119,7 @@ func NewLocalRoomManager(
}
r := &RoomManager{
baseTime: baseTime,
config: conf,
rtcConfig: rtcConf,
currentNode: currentNode,
@@ -444,6 +448,7 @@ func (r *RoomManager) StartSession(
subscriberAllowPause = *pi.SubscriberAllowPause
}
participant, err = rtc.NewParticipant(rtc.ParticipantParams{
BaseTime: r.baseTime,
Identity: pi.Identity,
Name: pi.Name,
SID: sid,
@@ -486,6 +491,7 @@ func (r *RoomManager) StartSession(
PlayoutDelay: roomInternal.GetPlayoutDelay(),
SyncStreams: roomInternal.GetSyncStreams(),
ForwardStats: r.forwardStats,
MetricConfig: r.config.Metric,
})
if err != nil {
return err
+6
View File
@@ -20,6 +20,7 @@ package service
import (
"fmt"
"os"
"time"
"github.com/google/wire"
"github.com/pion/turn/v2"
@@ -45,6 +46,7 @@ import (
func InitializeServer(conf *config.Config, currentNode routing.LocalNode) (*LivekitServer, error) {
wire.Build(
getTimeNow,
getNodeID,
createRedisClient,
createStore,
@@ -122,6 +124,10 @@ func InitializeRouter(conf *config.Config, currentNode routing.LocalNode) (routi
return nil, nil
}
func getTimeNow() time.Time {
return time.Now()
}
func getNodeID(currentNode routing.LocalNode) livekit.NodeID {
return livekit.NodeID(currentNode.Id)
}
+7 -1
View File
@@ -27,6 +27,7 @@ import (
"github.com/redis/go-redis/v9"
"gopkg.in/yaml.v3"
"os"
"time"
)
import (
@@ -124,6 +125,7 @@ func InitializeServer(conf *config.Config, currentNode routing.LocalNode) (*Live
if err != nil {
return nil, err
}
time := getTimeNow()
clientConfigurationManager := createClientConfiguration()
client, err := agent.NewAgentClient(messageBus)
if err != nil {
@@ -133,7 +135,7 @@ func InitializeServer(conf *config.Config, currentNode routing.LocalNode) (*Live
timedVersionGenerator := utils.NewDefaultTimedVersionGenerator()
turnAuthHandler := NewTURNAuthHandler(keyProvider)
forwardStats := createForwardStats(conf)
roomManager, err := NewLocalRoomManager(conf, objectStore, currentNode, router, roomAllocator, telemetryService, clientConfigurationManager, client, agentStore, rtcEgressLauncher, timedVersionGenerator, turnAuthHandler, messageBus, forwardStats)
roomManager, err := NewLocalRoomManager(time, conf, objectStore, currentNode, router, roomAllocator, telemetryService, clientConfigurationManager, client, agentStore, rtcEgressLauncher, timedVersionGenerator, turnAuthHandler, messageBus, forwardStats)
if err != nil {
return nil, err
}
@@ -182,6 +184,10 @@ func InitializeRouter(conf *config.Config, currentNode routing.LocalNode) (routi
// wire.go:
func getTimeNow() time.Time {
return time.Now()
}
func getNodeID(currentNode routing.LocalNode) livekit.NodeID {
return livekit.NodeID(currentNode.Id)
}