Update to new logging library, using sampling participant logger (#1219)
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/bep/debounce"
|
||||
|
||||
"github.com/livekit/protocol/livekit"
|
||||
"github.com/livekit/protocol/logger"
|
||||
|
||||
@@ -35,6 +36,9 @@ type DynacastManager struct {
|
||||
}
|
||||
|
||||
func NewDynacastManager(params DynacastManagerParams) *DynacastManager {
|
||||
if params.Logger == nil {
|
||||
params.Logger = logger.GetLogger()
|
||||
}
|
||||
d := &DynacastManager{
|
||||
params: params,
|
||||
dynacastQuality: make(map[string]*DynacastQuality),
|
||||
@@ -84,22 +88,18 @@ func (d *DynacastManager) Close() {
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// THere are situations like track unmute or streaming from a sifferent node
|
||||
// where subscribed quality needs to sent to the provider immediately.
|
||||
// This bypasses any debouncing and forces a subscribed quality update
|
||||
// with immediate effect.
|
||||
//
|
||||
func (d *DynacastManager) ForceUpdate() {
|
||||
d.update(true)
|
||||
}
|
||||
|
||||
//
|
||||
// It is possible for tracks to be in pending close state. When track
|
||||
// is waiting to be closed, a node is not streaming a track. This can
|
||||
// be used to force an update announcing that subscribed quality is OFF,
|
||||
// i.e. indicating not pulling track any more.
|
||||
//
|
||||
func (d *DynacastManager) ForceQuality(quality livekit.VideoQuality) {
|
||||
d.lock.Lock()
|
||||
defer d.lock.Unlock()
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
|
||||
"github.com/livekit/protocol/auth"
|
||||
"github.com/livekit/protocol/livekit"
|
||||
"github.com/livekit/protocol/logger"
|
||||
"github.com/livekit/protocol/utils"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/config"
|
||||
@@ -467,8 +468,9 @@ func newParticipantForTestWithOpts(identity livekit.ParticipantIdentity, opts *p
|
||||
FmtpLine: c.FmtpLine,
|
||||
})
|
||||
}
|
||||
sid := livekit.ParticipantID(utils.NewGuid(utils.ParticipantPrefix))
|
||||
p, _ := NewParticipant(ParticipantParams{
|
||||
SID: livekit.ParticipantID(utils.NewGuid(utils.ParticipantPrefix)),
|
||||
SID: sid,
|
||||
Identity: identity,
|
||||
Config: rtcConf,
|
||||
Sink: &routingfakes.FakeMessageSink{},
|
||||
@@ -478,6 +480,7 @@ func newParticipantForTestWithOpts(identity livekit.ParticipantIdentity, opts *p
|
||||
EnabledCodecs: enabledCodecs,
|
||||
ClientConf: opts.clientConf,
|
||||
ClientInfo: ClientInfo{ClientInfo: opts.clientInfo},
|
||||
Logger: LoggerWithParticipant(logger.GetLogger(), identity, sid, false),
|
||||
})
|
||||
p.isPublisher.Store(opts.publisher)
|
||||
|
||||
|
||||
+1
-1
@@ -85,7 +85,7 @@ func NewRoom(
|
||||
r := &Room{
|
||||
protoRoom: proto.Clone(room).(*livekit.Room),
|
||||
internal: internal,
|
||||
Logger: LoggerWithRoom(logger.GetDefaultLogger(), livekit.RoomName(room.Name), livekit.RoomID(room.Sid)),
|
||||
Logger: LoggerWithRoom(logger.GetLogger(), livekit.RoomName(room.Name), livekit.RoomID(room.Sid)),
|
||||
config: config,
|
||||
audioConfig: audioConfig,
|
||||
telemetry: telemetry,
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/bep/debounce"
|
||||
"github.com/go-logr/logr"
|
||||
"github.com/pion/ice/v2"
|
||||
"github.com/pion/interceptor"
|
||||
"github.com/pion/interceptor/pkg/cc"
|
||||
@@ -257,7 +256,7 @@ func newPeerConnection(params TransportParams, onBandwidthEstimator func(estimat
|
||||
se.SetDTLSRetransmissionInterval(dtlsRetransmissionInterval)
|
||||
se.SetICETimeouts(iceDisconnectedTimeout, iceFailedTimeout, iceKeepaliveInterval)
|
||||
|
||||
lf := serverlogger.NewLoggerFactory(logr.Logger(params.Logger))
|
||||
lf := serverlogger.NewLoggerFactory(params.Logger)
|
||||
if lf != nil {
|
||||
se.LoggerFactory = lf
|
||||
}
|
||||
@@ -318,6 +317,9 @@ func newPeerConnection(params TransportParams, onBandwidthEstimator func(estimat
|
||||
}
|
||||
|
||||
func NewPCTransport(params TransportParams) (*PCTransport, error) {
|
||||
if params.Logger == nil {
|
||||
params.Logger = logger.GetLogger()
|
||||
}
|
||||
t := &PCTransport{
|
||||
params: params,
|
||||
debouncedNegotiate: debounce.New(negotiationFrequency),
|
||||
|
||||
@@ -76,6 +76,9 @@ type TransportManager struct {
|
||||
}
|
||||
|
||||
func NewTransportManager(params TransportManagerParams) (*TransportManager, error) {
|
||||
if params.Logger == nil {
|
||||
params.Logger = logger.GetLogger()
|
||||
}
|
||||
t := &TransportManager{
|
||||
params: params,
|
||||
mediaLossProxy: NewMediaLossProxy(MediaLossProxyParams{Logger: params.Logger}),
|
||||
|
||||
@@ -6,14 +6,19 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/livekit/protocol/livekit"
|
||||
"github.com/livekit/protocol/logger"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/rtc/types"
|
||||
"github.com/livekit/livekit-server/pkg/rtc/types/typesfakes"
|
||||
)
|
||||
|
||||
var defaultUptrackManagerParams = UpTrackManagerParams{
|
||||
Logger: logger.GetLogger(),
|
||||
}
|
||||
|
||||
func TestUpdateSubscriptionPermission(t *testing.T) {
|
||||
t.Run("updates subscription permission", func(t *testing.T) {
|
||||
um := NewUpTrackManager(UpTrackManagerParams{})
|
||||
um := NewUpTrackManager(defaultUptrackManagerParams)
|
||||
|
||||
tra := &typesfakes.FakeMediaTrack{}
|
||||
tra.IDReturns("audio")
|
||||
@@ -103,7 +108,7 @@ func TestUpdateSubscriptionPermission(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("updates subscription permission using both", func(t *testing.T) {
|
||||
um := NewUpTrackManager(UpTrackManagerParams{})
|
||||
um := NewUpTrackManager(defaultUptrackManagerParams)
|
||||
|
||||
tra := &typesfakes.FakeMediaTrack{}
|
||||
tra.IDReturns("audio")
|
||||
@@ -176,7 +181,7 @@ func TestUpdateSubscriptionPermission(t *testing.T) {
|
||||
|
||||
func TestSubscriptionPermission(t *testing.T) {
|
||||
t.Run("checks subscription permission", func(t *testing.T) {
|
||||
um := NewUpTrackManager(UpTrackManagerParams{})
|
||||
um := NewUpTrackManager(defaultUptrackManagerParams)
|
||||
|
||||
tra := &typesfakes.FakeMediaTrack{}
|
||||
tra.IDReturns("audio")
|
||||
|
||||
+15
-24
@@ -6,7 +6,6 @@ import (
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
"github.com/go-logr/logr"
|
||||
"github.com/pion/webrtc/v3"
|
||||
|
||||
"github.com/livekit/protocol/livekit"
|
||||
@@ -130,51 +129,43 @@ func Recover() {
|
||||
|
||||
// logger helpers
|
||||
func LoggerWithParticipant(l logger.Logger, identity livekit.ParticipantIdentity, sid livekit.ParticipantID, isRemote bool) logger.Logger {
|
||||
lr := logr.Logger(l)
|
||||
values := make([]interface{}, 0, 4)
|
||||
if identity != "" {
|
||||
lr = lr.WithValues("participant", identity)
|
||||
values = append(values, "participant", identity)
|
||||
}
|
||||
if sid != "" {
|
||||
lr = lr.WithValues("pID", sid)
|
||||
values = append(values, "pID", sid)
|
||||
}
|
||||
lr = lr.WithValues("remote", isRemote)
|
||||
return logger.Logger(lr)
|
||||
values = append(values, "remote", isRemote)
|
||||
// enable sampling per participant
|
||||
return l.WithItemSampler().WithValues(values...)
|
||||
}
|
||||
|
||||
func LoggerWithRoom(l logger.Logger, name livekit.RoomName, roomID livekit.RoomID) logger.Logger {
|
||||
lr := logr.Logger(l)
|
||||
values := make([]interface{}, 0, 2)
|
||||
if name != "" {
|
||||
lr = lr.WithValues("room", name)
|
||||
values = append(values, "room", name)
|
||||
}
|
||||
if roomID != "" {
|
||||
lr = lr.WithValues("roomID", roomID)
|
||||
values = append(values, "roomID", roomID)
|
||||
}
|
||||
return logger.Logger(lr)
|
||||
return l.WithValues(values...)
|
||||
}
|
||||
|
||||
func LoggerWithTrack(l logger.Logger, trackID livekit.TrackID, isRelayed bool) logger.Logger {
|
||||
lr := logr.Logger(l)
|
||||
if trackID != "" {
|
||||
lr = lr.WithValues("trackID", trackID)
|
||||
lr = lr.WithValues("relayed", isRelayed)
|
||||
return l.WithValues("trackID", trackID, "relayed", isRelayed)
|
||||
}
|
||||
return logger.Logger(lr)
|
||||
return l
|
||||
}
|
||||
|
||||
func LoggerWithPCTarget(l logger.Logger, target livekit.SignalTarget) logger.Logger {
|
||||
lr := logr.Logger(l)
|
||||
if lr.GetSink() == nil {
|
||||
return l
|
||||
}
|
||||
|
||||
lr = lr.WithValues("transport", target)
|
||||
return logger.Logger(lr)
|
||||
return l.WithValues("transport", target)
|
||||
}
|
||||
|
||||
func LoggerWithCodecMime(l logger.Logger, mime string) logger.Logger {
|
||||
lr := logr.Logger(l)
|
||||
if mime != "" {
|
||||
lr = lr.WithValues("mime", mime)
|
||||
return l.WithValues("mime", mime)
|
||||
}
|
||||
return logger.Logger(lr)
|
||||
return l
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user