Analytics: send local node room state/info (#2335)
* Analytics: send local node room state/info Signed-off-by: shishir gowda <shishir@livekit.io>
This commit is contained in:
@@ -17,6 +17,9 @@ package telemetry
|
||||
import (
|
||||
"context"
|
||||
|
||||
"go.uber.org/atomic"
|
||||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
|
||||
"github.com/livekit/protocol/livekit"
|
||||
"github.com/livekit/protocol/logger"
|
||||
|
||||
@@ -28,14 +31,17 @@ import (
|
||||
type AnalyticsService interface {
|
||||
SendStats(ctx context.Context, stats []*livekit.AnalyticsStat)
|
||||
SendEvent(ctx context.Context, events *livekit.AnalyticsEvent)
|
||||
SendNodeRoomStates(ctx context.Context, nodeRooms *livekit.AnalyticsNodeRooms)
|
||||
}
|
||||
|
||||
type analyticsService struct {
|
||||
analyticsKey string
|
||||
nodeID string
|
||||
analyticsKey string
|
||||
nodeID string
|
||||
sequenceNumber atomic.Uint64
|
||||
|
||||
events livekit.AnalyticsRecorderService_IngestEventsClient
|
||||
stats livekit.AnalyticsRecorderService_IngestStatsClient
|
||||
events livekit.AnalyticsRecorderService_IngestEventsClient
|
||||
stats livekit.AnalyticsRecorderService_IngestStatsClient
|
||||
nodeRooms livekit.AnalyticsRecorderService_IngestNodeRoomStatesClient
|
||||
}
|
||||
|
||||
func NewAnalyticsService(_ *config.Config, currentNode routing.LocalNode) AnalyticsService {
|
||||
@@ -71,3 +77,16 @@ func (a *analyticsService) SendEvent(_ context.Context, event *livekit.Analytics
|
||||
logger.Errorw("failed to send event", err, "eventType", event.Type.String())
|
||||
}
|
||||
}
|
||||
|
||||
func (a *analyticsService) SendNodeRoomStates(_ context.Context, nodeRooms *livekit.AnalyticsNodeRooms) {
|
||||
if a.nodeRooms == nil {
|
||||
return
|
||||
}
|
||||
|
||||
nodeRooms.NodeId = a.nodeID
|
||||
nodeRooms.SequenceNumber = a.sequenceNumber.Add(1)
|
||||
nodeRooms.Timestamp = timestamppb.Now()
|
||||
if err := a.nodeRooms.Send(nodeRooms); err != nil {
|
||||
logger.Errorw("failed to send node room states", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,12 @@ type FakeAnalyticsService struct {
|
||||
arg1 context.Context
|
||||
arg2 *livekit.AnalyticsEvent
|
||||
}
|
||||
SendNodeRoomStatesStub func(context.Context, *livekit.AnalyticsNodeRooms)
|
||||
sendNodeRoomStatesMutex sync.RWMutex
|
||||
sendNodeRoomStatesArgsForCall []struct {
|
||||
arg1 context.Context
|
||||
arg2 *livekit.AnalyticsNodeRooms
|
||||
}
|
||||
SendStatsStub func(context.Context, []*livekit.AnalyticsStat)
|
||||
sendStatsMutex sync.RWMutex
|
||||
sendStatsArgsForCall []struct {
|
||||
@@ -59,6 +65,39 @@ func (fake *FakeAnalyticsService) SendEventArgsForCall(i int) (context.Context,
|
||||
return argsForCall.arg1, argsForCall.arg2
|
||||
}
|
||||
|
||||
func (fake *FakeAnalyticsService) SendNodeRoomStates(arg1 context.Context, arg2 *livekit.AnalyticsNodeRooms) {
|
||||
fake.sendNodeRoomStatesMutex.Lock()
|
||||
fake.sendNodeRoomStatesArgsForCall = append(fake.sendNodeRoomStatesArgsForCall, struct {
|
||||
arg1 context.Context
|
||||
arg2 *livekit.AnalyticsNodeRooms
|
||||
}{arg1, arg2})
|
||||
stub := fake.SendNodeRoomStatesStub
|
||||
fake.recordInvocation("SendNodeRoomStates", []interface{}{arg1, arg2})
|
||||
fake.sendNodeRoomStatesMutex.Unlock()
|
||||
if stub != nil {
|
||||
fake.SendNodeRoomStatesStub(arg1, arg2)
|
||||
}
|
||||
}
|
||||
|
||||
func (fake *FakeAnalyticsService) SendNodeRoomStatesCallCount() int {
|
||||
fake.sendNodeRoomStatesMutex.RLock()
|
||||
defer fake.sendNodeRoomStatesMutex.RUnlock()
|
||||
return len(fake.sendNodeRoomStatesArgsForCall)
|
||||
}
|
||||
|
||||
func (fake *FakeAnalyticsService) SendNodeRoomStatesCalls(stub func(context.Context, *livekit.AnalyticsNodeRooms)) {
|
||||
fake.sendNodeRoomStatesMutex.Lock()
|
||||
defer fake.sendNodeRoomStatesMutex.Unlock()
|
||||
fake.SendNodeRoomStatesStub = stub
|
||||
}
|
||||
|
||||
func (fake *FakeAnalyticsService) SendNodeRoomStatesArgsForCall(i int) (context.Context, *livekit.AnalyticsNodeRooms) {
|
||||
fake.sendNodeRoomStatesMutex.RLock()
|
||||
defer fake.sendNodeRoomStatesMutex.RUnlock()
|
||||
argsForCall := fake.sendNodeRoomStatesArgsForCall[i]
|
||||
return argsForCall.arg1, argsForCall.arg2
|
||||
}
|
||||
|
||||
func (fake *FakeAnalyticsService) SendStats(arg1 context.Context, arg2 []*livekit.AnalyticsStat) {
|
||||
var arg2Copy []*livekit.AnalyticsStat
|
||||
if arg2 != nil {
|
||||
@@ -102,6 +141,8 @@ func (fake *FakeAnalyticsService) Invocations() map[string][][]interface{} {
|
||||
defer fake.invocationsMutex.RUnlock()
|
||||
fake.sendEventMutex.RLock()
|
||||
defer fake.sendEventMutex.RUnlock()
|
||||
fake.sendNodeRoomStatesMutex.RLock()
|
||||
defer fake.sendNodeRoomStatesMutex.RUnlock()
|
||||
fake.sendStatsMutex.RLock()
|
||||
defer fake.sendStatsMutex.RUnlock()
|
||||
copiedInvocations := map[string][][]interface{}{}
|
||||
|
||||
@@ -62,6 +62,12 @@ type FakeTelemetryService struct {
|
||||
arg1 context.Context
|
||||
arg2 *livekit.IngressInfo
|
||||
}
|
||||
LocalRoomStateStub func(context.Context, *livekit.AnalyticsNodeRooms)
|
||||
localRoomStateMutex sync.RWMutex
|
||||
localRoomStateArgsForCall []struct {
|
||||
arg1 context.Context
|
||||
arg2 *livekit.AnalyticsNodeRooms
|
||||
}
|
||||
NotifyEventStub func(context.Context, *livekit.WebhookEvent)
|
||||
notifyEventMutex sync.RWMutex
|
||||
notifyEventArgsForCall []struct {
|
||||
@@ -122,6 +128,12 @@ type FakeTelemetryService struct {
|
||||
arg1 context.Context
|
||||
arg2 *livekit.AnalyticsEvent
|
||||
}
|
||||
SendNodeRoomStatesStub func(context.Context, *livekit.AnalyticsNodeRooms)
|
||||
sendNodeRoomStatesMutex sync.RWMutex
|
||||
sendNodeRoomStatesArgsForCall []struct {
|
||||
arg1 context.Context
|
||||
arg2 *livekit.AnalyticsNodeRooms
|
||||
}
|
||||
SendStatsStub func(context.Context, []*livekit.AnalyticsStat)
|
||||
sendStatsMutex sync.RWMutex
|
||||
sendStatsArgsForCall []struct {
|
||||
@@ -533,6 +545,39 @@ func (fake *FakeTelemetryService) IngressUpdatedArgsForCall(i int) (context.Cont
|
||||
return argsForCall.arg1, argsForCall.arg2
|
||||
}
|
||||
|
||||
func (fake *FakeTelemetryService) LocalRoomState(arg1 context.Context, arg2 *livekit.AnalyticsNodeRooms) {
|
||||
fake.localRoomStateMutex.Lock()
|
||||
fake.localRoomStateArgsForCall = append(fake.localRoomStateArgsForCall, struct {
|
||||
arg1 context.Context
|
||||
arg2 *livekit.AnalyticsNodeRooms
|
||||
}{arg1, arg2})
|
||||
stub := fake.LocalRoomStateStub
|
||||
fake.recordInvocation("LocalRoomState", []interface{}{arg1, arg2})
|
||||
fake.localRoomStateMutex.Unlock()
|
||||
if stub != nil {
|
||||
fake.LocalRoomStateStub(arg1, arg2)
|
||||
}
|
||||
}
|
||||
|
||||
func (fake *FakeTelemetryService) LocalRoomStateCallCount() int {
|
||||
fake.localRoomStateMutex.RLock()
|
||||
defer fake.localRoomStateMutex.RUnlock()
|
||||
return len(fake.localRoomStateArgsForCall)
|
||||
}
|
||||
|
||||
func (fake *FakeTelemetryService) LocalRoomStateCalls(stub func(context.Context, *livekit.AnalyticsNodeRooms)) {
|
||||
fake.localRoomStateMutex.Lock()
|
||||
defer fake.localRoomStateMutex.Unlock()
|
||||
fake.LocalRoomStateStub = stub
|
||||
}
|
||||
|
||||
func (fake *FakeTelemetryService) LocalRoomStateArgsForCall(i int) (context.Context, *livekit.AnalyticsNodeRooms) {
|
||||
fake.localRoomStateMutex.RLock()
|
||||
defer fake.localRoomStateMutex.RUnlock()
|
||||
argsForCall := fake.localRoomStateArgsForCall[i]
|
||||
return argsForCall.arg1, argsForCall.arg2
|
||||
}
|
||||
|
||||
func (fake *FakeTelemetryService) NotifyEvent(arg1 context.Context, arg2 *livekit.WebhookEvent) {
|
||||
fake.notifyEventMutex.Lock()
|
||||
fake.notifyEventArgsForCall = append(fake.notifyEventArgsForCall, struct {
|
||||
@@ -809,6 +854,39 @@ func (fake *FakeTelemetryService) SendEventArgsForCall(i int) (context.Context,
|
||||
return argsForCall.arg1, argsForCall.arg2
|
||||
}
|
||||
|
||||
func (fake *FakeTelemetryService) SendNodeRoomStates(arg1 context.Context, arg2 *livekit.AnalyticsNodeRooms) {
|
||||
fake.sendNodeRoomStatesMutex.Lock()
|
||||
fake.sendNodeRoomStatesArgsForCall = append(fake.sendNodeRoomStatesArgsForCall, struct {
|
||||
arg1 context.Context
|
||||
arg2 *livekit.AnalyticsNodeRooms
|
||||
}{arg1, arg2})
|
||||
stub := fake.SendNodeRoomStatesStub
|
||||
fake.recordInvocation("SendNodeRoomStates", []interface{}{arg1, arg2})
|
||||
fake.sendNodeRoomStatesMutex.Unlock()
|
||||
if stub != nil {
|
||||
fake.SendNodeRoomStatesStub(arg1, arg2)
|
||||
}
|
||||
}
|
||||
|
||||
func (fake *FakeTelemetryService) SendNodeRoomStatesCallCount() int {
|
||||
fake.sendNodeRoomStatesMutex.RLock()
|
||||
defer fake.sendNodeRoomStatesMutex.RUnlock()
|
||||
return len(fake.sendNodeRoomStatesArgsForCall)
|
||||
}
|
||||
|
||||
func (fake *FakeTelemetryService) SendNodeRoomStatesCalls(stub func(context.Context, *livekit.AnalyticsNodeRooms)) {
|
||||
fake.sendNodeRoomStatesMutex.Lock()
|
||||
defer fake.sendNodeRoomStatesMutex.Unlock()
|
||||
fake.SendNodeRoomStatesStub = stub
|
||||
}
|
||||
|
||||
func (fake *FakeTelemetryService) SendNodeRoomStatesArgsForCall(i int) (context.Context, *livekit.AnalyticsNodeRooms) {
|
||||
fake.sendNodeRoomStatesMutex.RLock()
|
||||
defer fake.sendNodeRoomStatesMutex.RUnlock()
|
||||
argsForCall := fake.sendNodeRoomStatesArgsForCall[i]
|
||||
return argsForCall.arg1, argsForCall.arg2
|
||||
}
|
||||
|
||||
func (fake *FakeTelemetryService) SendStats(arg1 context.Context, arg2 []*livekit.AnalyticsStat) {
|
||||
var arg2Copy []*livekit.AnalyticsStat
|
||||
if arg2 != nil {
|
||||
@@ -1359,6 +1437,8 @@ func (fake *FakeTelemetryService) Invocations() map[string][][]interface{} {
|
||||
defer fake.ingressStartedMutex.RUnlock()
|
||||
fake.ingressUpdatedMutex.RLock()
|
||||
defer fake.ingressUpdatedMutex.RUnlock()
|
||||
fake.localRoomStateMutex.RLock()
|
||||
defer fake.localRoomStateMutex.RUnlock()
|
||||
fake.notifyEventMutex.RLock()
|
||||
defer fake.notifyEventMutex.RUnlock()
|
||||
fake.participantActiveMutex.RLock()
|
||||
@@ -1375,6 +1455,8 @@ func (fake *FakeTelemetryService) Invocations() map[string][][]interface{} {
|
||||
defer fake.roomStartedMutex.RUnlock()
|
||||
fake.sendEventMutex.RLock()
|
||||
defer fake.sendEventMutex.RUnlock()
|
||||
fake.sendNodeRoomStatesMutex.RLock()
|
||||
defer fake.sendNodeRoomStatesMutex.RUnlock()
|
||||
fake.sendStatsMutex.RLock()
|
||||
defer fake.sendStatsMutex.RUnlock()
|
||||
fake.trackMaxSubscribedVideoQualityMutex.RLock()
|
||||
|
||||
@@ -73,6 +73,7 @@ type TelemetryService interface {
|
||||
IngressStarted(ctx context.Context, info *livekit.IngressInfo)
|
||||
IngressUpdated(ctx context.Context, info *livekit.IngressInfo)
|
||||
IngressEnded(ctx context.Context, info *livekit.IngressInfo)
|
||||
LocalRoomState(ctx context.Context, info *livekit.AnalyticsNodeRooms)
|
||||
|
||||
// helpers
|
||||
AnalyticsService
|
||||
@@ -187,3 +188,9 @@ func (t *telemetryService) cleanupWorkers() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (t *telemetryService) LocalRoomState(ctx context.Context, info *livekit.AnalyticsNodeRooms) {
|
||||
t.enqueue(func() {
|
||||
t.SendNodeRoomStates(ctx, info)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user