Use participant and room specific loggers (#252)

This commit is contained in:
David Zhao
2021-12-10 15:51:05 -08:00
committed by GitHub
parent bd42a39117
commit 8abd734d16
10 changed files with 132 additions and 154 deletions
+27 -15
View File
@@ -8,6 +8,7 @@ import (
"github.com/livekit/protocol/livekit"
"github.com/livekit/protocol/logger"
"github.com/livekit/protocol/utils"
"github.com/livekit/livekit-server/pkg/config"
"github.com/livekit/livekit-server/pkg/routing"
@@ -225,8 +226,11 @@ func (r *RoomManager) StartSession(ctx context.Context, roomName string, pi rout
pv := types.ProtocolVersion(pi.Client.Protocol)
rtcConf := *r.rtcConfig
rtcConf.SetBufferFactory(room.GetBufferFactor())
sid := utils.NewGuid(utils.ParticipantPrefix)
pLogger := rtc.LoggerWithParticipant(room.Logger, pi.Identity, sid)
participant, err = rtc.NewParticipant(rtc.ParticipantParams{
Identity: pi.Identity,
SID: sid,
Config: &rtcConf,
Sink: responseSink,
AudioConfig: r.config.Audio,
@@ -235,7 +239,7 @@ func (r *RoomManager) StartSession(ctx context.Context, roomName string, pi rout
ThrottleConfig: r.config.RTC.PLIThrottle,
EnabledCodecs: room.Room.EnabledCodecs,
Hidden: pi.Hidden,
Logger: room.Logger,
Logger: pLogger,
})
if err != nil {
logger.Errorw("could not create participant", err)
@@ -254,11 +258,11 @@ func (r *RoomManager) StartSession(ctx context.Context, roomName string, pi rout
AutoSubscribe: pi.AutoSubscribe,
}
if err = room.Join(participant, &opts, r.iceServersForRoom(room.Room)); err != nil {
logger.Errorw("could not join room", err)
pLogger.Errorw("could not join room", err)
return
}
if err = r.roomStore.StoreParticipant(ctx, roomName, participant.ToProto()); err != nil {
logger.Errorw("could not store participant", err)
pLogger.Errorw("could not store participant", err)
}
// update roomstore with new numParticipants
if !participant.Hidden() {
@@ -271,7 +275,7 @@ func (r *RoomManager) StartSession(ctx context.Context, roomName string, pi rout
r.telemetry.ParticipantJoined(ctx, room.Room, participant.ToProto())
participant.OnClose(func(p types.Participant) {
if err := r.roomStore.DeleteParticipant(ctx, roomName, p.Identity()); err != nil {
logger.Errorw("could not delete participant", err)
pLogger.Errorw("could not delete participant", err)
}
// update roomstore with new numParticipants
if !participant.Hidden() {
@@ -346,6 +350,11 @@ func (r *RoomManager) rtcSessionWorker(room *rtc.Room, participant types.Partici
}()
defer rtc.Recover()
pLogger := rtc.LoggerWithParticipant(
rtc.LoggerWithRoom(logger.Logger(logger.GetLogger()), room.Name()),
participant.Identity(), participant.ID(),
)
for {
select {
case <-time.After(time.Millisecond * 50):
@@ -361,7 +370,7 @@ func (r *RoomManager) rtcSessionWorker(room *rtc.Room, participant types.Partici
}
req := obj.(*livekit.SignalRequest)
if err := rtc.HandleParticipantSignal(room, participant, req); err != nil {
if err := rtc.HandleParticipantSignal(room, participant, req, pLogger); err != nil {
// more specific errors are already logged
// treat errors returned as fatal
return
@@ -382,22 +391,27 @@ func (r *RoomManager) handleRTCMessage(ctx context.Context, roomName, identity s
}
participant := room.GetParticipant(identity)
pLogger := rtc.LoggerWithParticipant(
rtc.LoggerWithRoom(logger.Logger(logger.GetLogger()), roomName),
identity,
"",
)
switch rm := msg.Message.(type) {
case *livekit.RTCNodeMessage_RemoveParticipant:
if participant == nil {
return
}
logger.Infow("removing participant", "room", roomName, "participant", identity)
pLogger.Infow("removing participant")
room.RemoveParticipant(identity)
case *livekit.RTCNodeMessage_MuteTrack:
if participant == nil {
return
}
logger.Debugw("setting track muted", "room", roomName, "participant", identity,
pLogger.Debugw("setting track muted",
"track", rm.MuteTrack.TrackSid, "muted", rm.MuteTrack.Muted)
if !rm.MuteTrack.Muted && !r.config.Room.EnableRemoteUnmute {
logger.Errorw("cannot unmute track, remote unmute is disabled", nil)
pLogger.Errorw("cannot unmute track, remote unmute is disabled", nil)
return
}
participant.SetTrackMuted(rm.MuteTrack.TrackSid, rm.MuteTrack.Muted, true)
@@ -405,7 +419,7 @@ func (r *RoomManager) handleRTCMessage(ctx context.Context, roomName, identity s
if participant == nil {
return
}
logger.Debugw("updating participant", "room", roomName, "participant", identity)
pLogger.Debugw("updating participant")
if rm.UpdateParticipant.Metadata != "" {
participant.SetMetadata(rm.UpdateParticipant.Metadata)
}
@@ -421,23 +435,21 @@ func (r *RoomManager) handleRTCMessage(ctx context.Context, roomName, identity s
if participant == nil {
return
}
logger.Debugw("updating participant subscriptions", "room", roomName, "participant", identity)
pLogger.Debugw("updating participant subscriptions")
if err := room.UpdateSubscriptions(participant, rm.UpdateSubscriptions.TrackSids, rm.UpdateSubscriptions.Subscribe); err != nil {
logger.Warnw("could not update subscription", err,
"participant", participant.Identity(),
"pID", participant.ID(),
pLogger.Warnw("could not update subscription", err,
"tracks", rm.UpdateSubscriptions.TrackSids,
"subscribe", rm.UpdateSubscriptions.Subscribe)
}
case *livekit.RTCNodeMessage_SendData:
logger.Debugw("SendData", "message", rm)
pLogger.Debugw("SendData", "size", len(rm.SendData.Data))
up := &livekit.UserPacket{
Payload: rm.SendData.Data,
DestinationSids: rm.SendData.DestinationSids,
}
room.SendDataPacket(up, rm.SendData.Kind)
case *livekit.RTCNodeMessage_UpdateRoomMetadata:
logger.Debugw("updating room", "room", roomName)
pLogger.Debugw("updating room")
room.SetMetadata(rm.UpdateRoomMetadata.Metadata)
}
}