diff --git a/livekit/types.go b/livekit/types.go index a091440f..27963637 100644 --- a/livekit/types.go +++ b/livekit/types.go @@ -14,69 +14,21 @@ package livekit -// ---------------------------------------------------------------- - type TrackID string - -func StringsAsTrackIDs(trackIDs []string) []TrackID { - asTrackID := make([]TrackID, 0, len(trackIDs)) - for _, trackID := range trackIDs { - asTrackID = append(asTrackID, TrackID(trackID)) - } - - return asTrackID -} - -// ---------------------------------------------------------------- - type ParticipantID string - -func ParticipantIDsAsStrings(ids []ParticipantID) []string { - strs := make([]string, 0, len(ids)) - for _, id := range ids { - strs = append(strs, string(id)) - } - return strs -} - -// ---------------------------------------------------------------- - type ParticipantIdentity string type ParticipantName string - type RoomID string - -// ---------------------------------------------------------------- - type RoomName string - -func RoomNamesAsStrings(roomNames []RoomName) []string { - asString := make([]string, 0, len(roomNames)) - for _, roomName := range roomNames { - asString = append(asString, string(roomName)) - } - - return asString -} - -func StringsAsRoomNames(roomNames []string) []RoomName { - asRoomName := make([]RoomName, 0, len(roomNames)) - for _, roomName := range roomNames { - asRoomName = append(asRoomName, RoomName(roomName)) - } - - return asRoomName -} - -// ---------------------------------------------------------------- - type ConnectionID string - -// ---------------------------------------------------------------- - type NodeID string +type ParticipantKey string + +type stringTypes interface { + ParticipantID | RoomID | TrackID | ParticipantIdentity | ParticipantName | RoomName | ConnectionID | NodeID | ParticipantKey +} -func NodeIDsAsStrings(ids []NodeID) []string { +func IDsAsStrings[T stringTypes](ids []T) []string { strs := make([]string, 0, len(ids)) for _, id := range ids { strs = append(strs, string(id)) @@ -84,10 +36,14 @@ func NodeIDsAsStrings(ids []NodeID) []string { return strs } -// ---------------------------------------------------------------- -type ParticipantKey string +func StringsAsIDs[T stringTypes](ids []string) []T { + asID := make([]T, 0, len(ids)) + for _, id := range ids { + asID = append(asID, T(id)) + } -// ---------------------------------------------------------------- + return asID +} type Guid interface { TrackID | ParticipantID | RoomID diff --git a/logger/config.go b/logger/config.go index bb8a8d08..1d1e7dee 100644 --- a/logger/config.go +++ b/logger/config.go @@ -17,8 +17,8 @@ package logger import "sync" type Config struct { - JSON bool `yaml:"json"` - Level string `yaml:"level"` + JSON bool `yaml:"json,omitempty"` + Level string `yaml:"level,omitempty"` // true to enable log sampling, where the same log message and level will be throttled. // we have two layers of sampling // 1. global sampling - within a second, it will log the first SampleInitial, then every SampleInterval messages. diff --git a/redis/redis.go b/redis/redis.go index 36ef627e..b5d613db 100644 --- a/redis/redis.go +++ b/redis/redis.go @@ -28,21 +28,21 @@ import ( var ErrNotConfigured = errors.New("Redis is not configured") type RedisConfig struct { - Address string `yaml:"address"` - Username string `yaml:"username"` - Password string `yaml:"password"` - DB int `yaml:"db"` - UseTLS bool `yaml:"use_tls"` - MasterName string `yaml:"sentinel_master_name"` - SentinelUsername string `yaml:"sentinel_username"` - SentinelPassword string `yaml:"sentinel_password"` - SentinelAddresses []string `yaml:"sentinel_addresses"` - ClusterAddresses []string `yaml:"cluster_addresses"` - DialTimeout int `yaml:"dial_timeout"` - ReadTimeout int `yaml:"read_timeout"` - WriteTimeout int `yaml:"write_timeout"` + Address string `yaml:"address,omitempty"` + Username string `yaml:"username,omitempty"` + Password string `yaml:"password,omitempty"` + DB int `yaml:"db,omitempty"` + UseTLS bool `yaml:"use_tls,omitempty"` + MasterName string `yaml:"sentinel_master_name,omitempty"` + SentinelUsername string `yaml:"sentinel_username,omitempty"` + SentinelPassword string `yaml:"sentinel_password,omitempty"` + SentinelAddresses []string `yaml:"sentinel_addresses,omitempty"` + ClusterAddresses []string `yaml:"cluster_addresses,omitempty"` + DialTimeout int `yaml:"dial_timeout,omitempty"` + ReadTimeout int `yaml:"read_timeout,omitempty"` + WriteTimeout int `yaml:"write_timeout,omitempty"` // for clustererd mode only, number of redirects to follow, defaults to 2 - MaxRedirects *int `yaml:"max_redirects"` + MaxRedirects *int `yaml:"max_redirects,omitempty"` } func (r *RedisConfig) IsConfigured() bool { diff --git a/rpc/egress_client.go b/rpc/egress_client.go index 2ceab134..1ba52cd5 100644 --- a/rpc/egress_client.go +++ b/rpc/egress_client.go @@ -50,7 +50,9 @@ func NewEgressClient(nodeID livekit.NodeID, bus psrpc.MessageBus) (EgressClient, if !errors.As(err, &e) { return true } - return e.Code() == psrpc.DeadlineExceeded || e.Code() == psrpc.ResourceExhausted + return e.Code() == psrpc.DeadlineExceeded || + e.Code() == psrpc.ResourceExhausted || + e.Code() == psrpc.Unavailable }, })) if err != nil { diff --git a/utils/lock_tracker.go b/utils/lock_tracker.go index f4ea6d74..6d8d3181 100644 --- a/utils/lock_tracker.go +++ b/utils/lock_tracker.go @@ -26,6 +26,7 @@ import ( var lockTrackerEnabled = false var enableLockTrackerOnce sync.Once var lowResTime uint32 = uint32(time.Now().Unix()) +var enableLockTrackerStackTrace uint32 // EnableLockTracker enable lock tracking background worker. This should be // called during init @@ -36,6 +37,14 @@ func EnableLockTracker() { }) } +func ToggleLockTrackerStackTraces(enable bool) { + var v uint32 + if enable { + v = 1 + } + atomic.StoreUint32(&enableLockTrackerStackTrace, v) +} + func updateLowResTime() { ticker := time.NewTicker(time.Second) for t := range ticker.C { @@ -151,13 +160,15 @@ func (t *lockTracker) trackLock() { if atomic.AddInt32(&t.held, 1) == 1 { atomic.StoreUint32(&t.ts, atomic.LoadUint32(&lowResTime)) - for { - n := runtime.Stack(t.stack[:cap(t.stack)], false) - if n < cap(t.stack) { - t.stack = t.stack[:n] - break + if atomic.LoadUint32(&enableLockTrackerStackTrace) == 1 { + for { + n := runtime.Stack(t.stack[:cap(t.stack)], false) + if n < cap(t.stack) { + t.stack = t.stack[:n] + break + } + t.stack = make([]byte, len(t.stack)*2) } - t.stack = make([]byte, len(t.stack)*2) } } }