Tweaks to prometheus participant counter (#1240)

* Tweaks to prometheus participant counter

Ensure that we don't miss adding a count in migration scenarios

* avoid nil ICEConfig
This commit is contained in:
David Zhao
2022-12-19 14:30:14 -08:00
committed by GitHub
parent 50e39b9985
commit c1d7dbd4fc
2 changed files with 12 additions and 1 deletions
+1
View File
@@ -83,6 +83,7 @@ func NewTransportManager(params TransportManagerParams) (*TransportManager, erro
t := &TransportManager{ t := &TransportManager{
params: params, params: params,
mediaLossProxy: NewMediaLossProxy(MediaLossProxyParams{Logger: params.Logger}), mediaLossProxy: NewMediaLossProxy(MediaLossProxyParams{Logger: params.Logger}),
iceConfig: &livekit.ICEConfig{},
} }
t.mediaLossProxy.OnMediaLossUpdate(t.onMediaLossUpdate) t.mediaLossProxy.OnMediaLossUpdate(t.onMediaLossUpdate)
+11 -1
View File
@@ -110,6 +110,8 @@ func (t *telemetryService) ParticipantActive(
worker, ok := t.getWorker(livekit.ParticipantID(participant.Sid)) worker, ok := t.getWorker(livekit.ParticipantID(participant.Sid))
if !ok { if !ok {
// in case of session migration, we may not have seen a Join event take place.
// we'd need to create the worker here before being able to process events
worker = t.createWorker( worker = t.createWorker(
ctx, ctx,
livekit.RoomID(room.Sid), livekit.RoomID(room.Sid),
@@ -117,6 +119,9 @@ func (t *telemetryService) ParticipantActive(
livekit.ParticipantID(participant.Sid), livekit.ParticipantID(participant.Sid),
livekit.ParticipantIdentity(participant.Identity), livekit.ParticipantIdentity(participant.Identity),
) )
// need to also account for participant count
prometheus.AddParticipant()
} }
worker.SetConnected() worker.SetConnected()
@@ -138,12 +143,17 @@ func (t *telemetryService) ParticipantLeft(ctx context.Context,
) { ) {
t.enqueue(func() { t.enqueue(func() {
isConnected := false isConnected := false
hasWorker := false
if worker, ok := t.getWorker(livekit.ParticipantID(participant.Sid)); ok { if worker, ok := t.getWorker(livekit.ParticipantID(participant.Sid)); ok {
hasWorker = true
isConnected = worker.IsConnected() isConnected = worker.IsConnected()
worker.Close() worker.Close()
} }
prometheus.SubParticipant() if hasWorker {
// signifies we had incremented participant count
prometheus.SubParticipant()
}
if isConnected && shouldSendEvent { if isConnected && shouldSendEvent {
t.NotifyEvent(ctx, &livekit.WebhookEvent{ t.NotifyEvent(ctx, &livekit.WebhookEvent{