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{
params: params,
mediaLossProxy: NewMediaLossProxy(MediaLossProxyParams{Logger: params.Logger}),
iceConfig: &livekit.ICEConfig{},
}
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))
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(
ctx,
livekit.RoomID(room.Sid),
@@ -117,6 +119,9 @@ func (t *telemetryService) ParticipantActive(
livekit.ParticipantID(participant.Sid),
livekit.ParticipantIdentity(participant.Identity),
)
// need to also account for participant count
prometheus.AddParticipant()
}
worker.SetConnected()
@@ -138,12 +143,17 @@ func (t *telemetryService) ParticipantLeft(ctx context.Context,
) {
t.enqueue(func() {
isConnected := false
hasWorker := false
if worker, ok := t.getWorker(livekit.ParticipantID(participant.Sid)); ok {
hasWorker = true
isConnected = worker.IsConnected()
worker.Close()
}
prometheus.SubParticipant()
if hasWorker {
// signifies we had incremented participant count
prometheus.SubParticipant()
}
if isConnected && shouldSendEvent {
t.NotifyEvent(ctx, &livekit.WebhookEvent{