Consolidate operations on LocalNode. (#3140)
This commit is contained in:
+1
-1
@@ -272,7 +272,7 @@ func startServer(c *cli.Context) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := prometheus.Init(currentNode.Id, currentNode.Type); err != nil {
|
if err := prometheus.Init(string(currentNode.NodeID()), currentNode.NodeType()); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import (
|
|||||||
|
|
||||||
"github.com/livekit/livekit-server/pkg/agent"
|
"github.com/livekit/livekit-server/pkg/agent"
|
||||||
"github.com/livekit/livekit-server/pkg/config"
|
"github.com/livekit/livekit-server/pkg/config"
|
||||||
|
"github.com/livekit/livekit-server/pkg/routing"
|
||||||
"github.com/livekit/livekit-server/pkg/service"
|
"github.com/livekit/livekit-server/pkg/service"
|
||||||
"github.com/livekit/protocol/auth"
|
"github.com/livekit/protocol/auth"
|
||||||
"github.com/livekit/protocol/livekit"
|
"github.com/livekit/protocol/livekit"
|
||||||
@@ -35,9 +36,10 @@ type TestServer struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewTestServer(bus psrpc.MessageBus) *TestServer {
|
func NewTestServer(bus psrpc.MessageBus) *TestServer {
|
||||||
|
localNode, _ := routing.NewLocalNode(nil)
|
||||||
return NewTestServerWithService(must.Get(service.NewAgentService(
|
return NewTestServerWithService(must.Get(service.NewAgentService(
|
||||||
&config.Config{Region: "test"},
|
&config.Config{Region: "test"},
|
||||||
&livekit.Node{Id: guid.New("N_")},
|
localNode,
|
||||||
bus,
|
bus,
|
||||||
auth.NewSimpleKeyProvider("test", "verysecretsecret"),
|
auth.NewSimpleKeyProvider("test", "verysecretsecret"),
|
||||||
)))
|
)))
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ import (
|
|||||||
|
|
||||||
"github.com/livekit/protocol/livekit"
|
"github.com/livekit/protocol/livekit"
|
||||||
"github.com/livekit/protocol/logger"
|
"github.com/livekit/protocol/logger"
|
||||||
"github.com/livekit/protocol/utils"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ Router = (*LocalRouter)(nil)
|
var _ Router = (*LocalRouter)(nil)
|
||||||
@@ -56,10 +55,7 @@ func NewLocalRouter(
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *LocalRouter) GetNodeForRoom(_ context.Context, _ livekit.RoomName) (*livekit.Node, error) {
|
func (r *LocalRouter) GetNodeForRoom(_ context.Context, _ livekit.RoomName) (*livekit.Node, error) {
|
||||||
r.lock.Lock()
|
return r.currentNode.Clone(), nil
|
||||||
defer r.lock.Unlock()
|
|
||||||
node := utils.CloneProto((*livekit.Node)(r.currentNode))
|
|
||||||
return node, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *LocalRouter) SetNodeForRoom(_ context.Context, _ livekit.RoomName, _ livekit.NodeID) error {
|
func (r *LocalRouter) SetNodeForRoom(_ context.Context, _ livekit.RoomName, _ livekit.NodeID) error {
|
||||||
@@ -83,20 +79,20 @@ func (r *LocalRouter) RemoveDeadNodes() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *LocalRouter) GetNode(nodeID livekit.NodeID) (*livekit.Node, error) {
|
func (r *LocalRouter) GetNode(nodeID livekit.NodeID) (*livekit.Node, error) {
|
||||||
if nodeID == livekit.NodeID(r.currentNode.Id) {
|
if nodeID == r.currentNode.NodeID() {
|
||||||
return r.currentNode, nil
|
return r.currentNode.Clone(), nil
|
||||||
}
|
}
|
||||||
return nil, ErrNotFound
|
return nil, ErrNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *LocalRouter) ListNodes() ([]*livekit.Node, error) {
|
func (r *LocalRouter) ListNodes() ([]*livekit.Node, error) {
|
||||||
return []*livekit.Node{
|
return []*livekit.Node{
|
||||||
r.currentNode,
|
r.currentNode.Clone(),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *LocalRouter) CreateRoom(ctx context.Context, req *livekit.CreateRoomRequest) (res *livekit.Room, err error) {
|
func (r *LocalRouter) CreateRoom(ctx context.Context, req *livekit.CreateRoomRequest) (res *livekit.Room, err error) {
|
||||||
return r.CreateRoomWithNodeID(ctx, req, livekit.NodeID(r.currentNode.Id))
|
return r.CreateRoomWithNodeID(ctx, req, r.currentNode.NodeID())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *LocalRouter) CreateRoomWithNodeID(ctx context.Context, req *livekit.CreateRoomRequest, nodeID livekit.NodeID) (res *livekit.Room, err error) {
|
func (r *LocalRouter) CreateRoomWithNodeID(ctx context.Context, req *livekit.CreateRoomRequest, nodeID livekit.NodeID) (res *livekit.Room, err error) {
|
||||||
@@ -104,7 +100,7 @@ func (r *LocalRouter) CreateRoomWithNodeID(ctx context.Context, req *livekit.Cre
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *LocalRouter) StartParticipantSignal(ctx context.Context, roomName livekit.RoomName, pi ParticipantInit) (res StartParticipantSignalResults, err error) {
|
func (r *LocalRouter) StartParticipantSignal(ctx context.Context, roomName livekit.RoomName, pi ParticipantInit) (res StartParticipantSignalResults, err error) {
|
||||||
return r.StartParticipantSignalWithNodeID(ctx, roomName, pi, livekit.NodeID(r.currentNode.Id))
|
return r.StartParticipantSignalWithNodeID(ctx, roomName, pi, r.currentNode.NodeID())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *LocalRouter) StartParticipantSignalWithNodeID(ctx context.Context, roomName livekit.RoomName, pi ParticipantInit, nodeID livekit.NodeID) (res StartParticipantSignalResults, err error) {
|
func (r *LocalRouter) StartParticipantSignalWithNodeID(ctx context.Context, roomName livekit.RoomName, pi ParticipantInit, nodeID livekit.NodeID) (res StartParticipantSignalResults, err error) {
|
||||||
@@ -136,15 +132,13 @@ func (r *LocalRouter) Start() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *LocalRouter) Drain() {
|
func (r *LocalRouter) Drain() {
|
||||||
r.lock.Lock()
|
r.currentNode.SetState(livekit.NodeState_SHUTTING_DOWN)
|
||||||
defer r.lock.Unlock()
|
|
||||||
r.currentNode.State = livekit.NodeState_SHUTTING_DOWN
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *LocalRouter) Stop() {}
|
func (r *LocalRouter) Stop() {}
|
||||||
|
|
||||||
func (r *LocalRouter) GetRegion() string {
|
func (r *LocalRouter) GetRegion() string {
|
||||||
return r.currentNode.Region
|
return r.currentNode.Region()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *LocalRouter) statsWorker() {
|
func (r *LocalRouter) statsWorker() {
|
||||||
@@ -154,9 +148,7 @@ func (r *LocalRouter) statsWorker() {
|
|||||||
}
|
}
|
||||||
// update every 10 seconds
|
// update every 10 seconds
|
||||||
<-time.After(statsUpdateInterval)
|
<-time.After(statsUpdateInterval)
|
||||||
r.lock.Lock()
|
r.currentNode.UpdateNodeStats()
|
||||||
r.currentNode.Stats.UpdatedAt = time.Now().Unix()
|
|
||||||
r.lock.Unlock()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+126
-13
@@ -16,33 +16,146 @@ package routing
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/livekit/protocol/livekit"
|
"github.com/livekit/protocol/livekit"
|
||||||
|
"github.com/livekit/protocol/logger"
|
||||||
"github.com/livekit/protocol/utils"
|
"github.com/livekit/protocol/utils"
|
||||||
"github.com/livekit/protocol/utils/guid"
|
"github.com/livekit/protocol/utils/guid"
|
||||||
|
|
||||||
"github.com/livekit/livekit-server/pkg/config"
|
"github.com/livekit/livekit-server/pkg/config"
|
||||||
|
"github.com/livekit/livekit-server/pkg/telemetry/prometheus"
|
||||||
)
|
)
|
||||||
|
|
||||||
type LocalNode *livekit.Node
|
type LocalNode interface {
|
||||||
|
Clone() *livekit.Node
|
||||||
|
SetNodeID(nodeID livekit.NodeID)
|
||||||
|
NodeID() livekit.NodeID
|
||||||
|
NodeType() livekit.NodeType
|
||||||
|
NodeIP() string
|
||||||
|
Region() string
|
||||||
|
SetState(state livekit.NodeState)
|
||||||
|
SetStats(stats *livekit.NodeStats)
|
||||||
|
UpdateNodeStats() bool
|
||||||
|
SecondsSinceNodeStatsUpdate() float64
|
||||||
|
}
|
||||||
|
|
||||||
func NewLocalNode(conf *config.Config) (LocalNode, error) {
|
type LocalNodeImpl struct {
|
||||||
|
lock sync.RWMutex
|
||||||
|
node *livekit.Node
|
||||||
|
|
||||||
|
// previous stats for computing averages
|
||||||
|
prevStats *livekit.NodeStats
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewLocalNode(conf *config.Config) (*LocalNodeImpl, error) {
|
||||||
nodeID := guid.New(utils.NodePrefix)
|
nodeID := guid.New(utils.NodePrefix)
|
||||||
if conf.RTC.NodeIP == "" {
|
if conf != nil && conf.RTC.NodeIP == "" {
|
||||||
return nil, ErrIPNotSet
|
return nil, ErrIPNotSet
|
||||||
}
|
}
|
||||||
node := &livekit.Node{
|
l := &LocalNodeImpl{
|
||||||
Id: nodeID,
|
node: &livekit.Node{
|
||||||
Ip: conf.RTC.NodeIP,
|
Id: nodeID,
|
||||||
NumCpus: uint32(runtime.NumCPU()),
|
NumCpus: uint32(runtime.NumCPU()),
|
||||||
Region: conf.Region,
|
State: livekit.NodeState_SERVING,
|
||||||
State: livekit.NodeState_SERVING,
|
Stats: &livekit.NodeStats{
|
||||||
Stats: &livekit.NodeStats{
|
StartedAt: time.Now().Unix(),
|
||||||
StartedAt: time.Now().Unix(),
|
UpdatedAt: time.Now().Unix(),
|
||||||
UpdatedAt: time.Now().Unix(),
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
if conf != nil {
|
||||||
|
l.node.Ip = conf.RTC.NodeIP
|
||||||
|
l.node.Region = conf.Region
|
||||||
|
}
|
||||||
|
return l, nil
|
||||||
|
}
|
||||||
|
|
||||||
return node, nil
|
func NewLocalNodeFromNodeProto(node *livekit.Node) (*LocalNodeImpl, error) {
|
||||||
|
return &LocalNodeImpl{node: utils.CloneProto(node)}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *LocalNodeImpl) Clone() *livekit.Node {
|
||||||
|
l.lock.RLock()
|
||||||
|
defer l.lock.RUnlock()
|
||||||
|
|
||||||
|
return utils.CloneProto(l.node)
|
||||||
|
}
|
||||||
|
|
||||||
|
// for testing only
|
||||||
|
func (l *LocalNodeImpl) SetNodeID(nodeID livekit.NodeID) {
|
||||||
|
l.lock.Lock()
|
||||||
|
defer l.lock.Unlock()
|
||||||
|
|
||||||
|
l.node.Id = string(nodeID)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *LocalNodeImpl) NodeID() livekit.NodeID {
|
||||||
|
l.lock.RLock()
|
||||||
|
defer l.lock.RUnlock()
|
||||||
|
|
||||||
|
return livekit.NodeID(l.node.Id)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *LocalNodeImpl) NodeType() livekit.NodeType {
|
||||||
|
l.lock.RLock()
|
||||||
|
defer l.lock.RUnlock()
|
||||||
|
|
||||||
|
return l.node.Type
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *LocalNodeImpl) NodeIP() string {
|
||||||
|
l.lock.RLock()
|
||||||
|
defer l.lock.RUnlock()
|
||||||
|
|
||||||
|
return l.node.Ip
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *LocalNodeImpl) Region() string {
|
||||||
|
l.lock.RLock()
|
||||||
|
defer l.lock.RUnlock()
|
||||||
|
|
||||||
|
return l.node.Region
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *LocalNodeImpl) SetState(state livekit.NodeState) {
|
||||||
|
l.lock.Lock()
|
||||||
|
defer l.lock.Unlock()
|
||||||
|
|
||||||
|
l.node.State = state
|
||||||
|
}
|
||||||
|
|
||||||
|
// for testing only
|
||||||
|
func (l *LocalNodeImpl) SetStats(stats *livekit.NodeStats) {
|
||||||
|
l.lock.Lock()
|
||||||
|
defer l.lock.Unlock()
|
||||||
|
|
||||||
|
l.node.Stats = utils.CloneProto(stats)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *LocalNodeImpl) UpdateNodeStats() bool {
|
||||||
|
l.lock.Lock()
|
||||||
|
defer l.lock.Unlock()
|
||||||
|
|
||||||
|
if l.prevStats == nil {
|
||||||
|
l.prevStats = l.node.Stats
|
||||||
|
}
|
||||||
|
updated, computedAvg, err := prometheus.GetUpdatedNodeStats(l.node.Stats, l.prevStats)
|
||||||
|
if err != nil {
|
||||||
|
logger.Errorw("could not update node stats", err)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
l.node.Stats = updated
|
||||||
|
if computedAvg {
|
||||||
|
l.prevStats = updated
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *LocalNodeImpl) SecondsSinceNodeStatsUpdate() float64 {
|
||||||
|
l.lock.RLock()
|
||||||
|
defer l.lock.RUnlock()
|
||||||
|
|
||||||
|
return time.Since(time.Unix(0, l.node.Stats.UpdatedAt)).Seconds()
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-35
@@ -18,7 +18,6 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"runtime/pprof"
|
"runtime/pprof"
|
||||||
"sync"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
@@ -31,14 +30,13 @@ import (
|
|||||||
"github.com/livekit/protocol/rpc"
|
"github.com/livekit/protocol/rpc"
|
||||||
|
|
||||||
"github.com/livekit/livekit-server/pkg/routing/selector"
|
"github.com/livekit/livekit-server/pkg/routing/selector"
|
||||||
"github.com/livekit/livekit-server/pkg/telemetry/prometheus"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// expire participant mappings after a day
|
// expire participant mappings after a day
|
||||||
participantMappingTTL = 24 * time.Hour
|
participantMappingTTL = 24 * time.Hour
|
||||||
statsUpdateInterval = 2 * time.Second
|
statsUpdateInterval = 2 * time.Second
|
||||||
statsMaxDelaySeconds = 30
|
statsMaxDelaySeconds = float64(30)
|
||||||
|
|
||||||
// hash of node_id => Node proto
|
// hash of node_id => Node proto
|
||||||
NodesKey = "nodes"
|
NodesKey = "nodes"
|
||||||
@@ -59,9 +57,6 @@ type RedisRouter struct {
|
|||||||
kps rpc.KeepalivePubSub
|
kps rpc.KeepalivePubSub
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
isStarted atomic.Bool
|
isStarted atomic.Bool
|
||||||
nodeMu sync.RWMutex
|
|
||||||
// previous stats for computing averages
|
|
||||||
prevStats *livekit.NodeStats
|
|
||||||
|
|
||||||
cancel func()
|
cancel func()
|
||||||
}
|
}
|
||||||
@@ -77,13 +72,11 @@ func NewRedisRouter(lr *LocalRouter, rc redis.UniversalClient, kps rpc.Keepalive
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *RedisRouter) RegisterNode() error {
|
func (r *RedisRouter) RegisterNode() error {
|
||||||
r.nodeMu.RLock()
|
data, err := proto.Marshal(r.currentNode.Clone())
|
||||||
data, err := proto.Marshal((*livekit.Node)(r.currentNode))
|
|
||||||
r.nodeMu.RUnlock()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := r.rc.HSet(r.ctx, NodesKey, r.currentNode.Id, data).Err(); err != nil {
|
if err := r.rc.HSet(r.ctx, NodesKey, string(r.currentNode.NodeID()), data).Err(); err != nil {
|
||||||
return errors.Wrap(err, "could not register node")
|
return errors.Wrap(err, "could not register node")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@@ -91,7 +84,7 @@ func (r *RedisRouter) RegisterNode() error {
|
|||||||
|
|
||||||
func (r *RedisRouter) UnregisterNode() error {
|
func (r *RedisRouter) UnregisterNode() error {
|
||||||
// could be called after Stop(), so we'd want to use an unrelated context
|
// could be called after Stop(), so we'd want to use an unrelated context
|
||||||
return r.rc.HDel(context.Background(), NodesKey, r.currentNode.Id).Err()
|
return r.rc.HDel(context.Background(), NodesKey, string(r.currentNode.NodeID())).Err()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *RedisRouter) RemoveDeadNodes() error {
|
func (r *RedisRouter) RemoveDeadNodes() error {
|
||||||
@@ -195,11 +188,9 @@ func (r *RedisRouter) Start() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *RedisRouter) Drain() {
|
func (r *RedisRouter) Drain() {
|
||||||
r.nodeMu.Lock()
|
r.currentNode.SetState(livekit.NodeState_SHUTTING_DOWN)
|
||||||
r.currentNode.State = livekit.NodeState_SHUTTING_DOWN
|
|
||||||
r.nodeMu.Unlock()
|
|
||||||
if err := r.RegisterNode(); err != nil {
|
if err := r.RegisterNode(); err != nil {
|
||||||
logger.Errorw("failed to mark as draining", err, "nodeID", r.currentNode.Id)
|
logger.Errorw("failed to mark as draining", err, "nodeID", r.currentNode.NodeID())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -219,13 +210,9 @@ func (r *RedisRouter) statsWorker() {
|
|||||||
// update periodically
|
// update periodically
|
||||||
select {
|
select {
|
||||||
case <-time.After(statsUpdateInterval):
|
case <-time.After(statsUpdateInterval):
|
||||||
r.kps.PublishPing(r.ctx, livekit.NodeID(r.currentNode.Id), &rpc.KeepalivePing{Timestamp: time.Now().Unix()})
|
r.kps.PublishPing(r.ctx, r.currentNode.NodeID(), &rpc.KeepalivePing{Timestamp: time.Now().Unix()})
|
||||||
|
|
||||||
r.nodeMu.RLock()
|
delaySeconds := r.currentNode.SecondsSinceNodeStatsUpdate()
|
||||||
stats := r.currentNode.Stats
|
|
||||||
r.nodeMu.RUnlock()
|
|
||||||
|
|
||||||
delaySeconds := time.Now().Unix() - stats.UpdatedAt
|
|
||||||
if delaySeconds > statsMaxDelaySeconds {
|
if delaySeconds > statsMaxDelaySeconds {
|
||||||
if !goroutineDumped {
|
if !goroutineDumped {
|
||||||
goroutineDumped = true
|
goroutineDumped = true
|
||||||
@@ -245,7 +232,7 @@ func (r *RedisRouter) statsWorker() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *RedisRouter) keepaliveWorker(startedChan chan error) {
|
func (r *RedisRouter) keepaliveWorker(startedChan chan error) {
|
||||||
pings, err := r.kps.SubscribePing(r.ctx, livekit.NodeID(r.currentNode.Id))
|
pings, err := r.kps.SubscribePing(r.ctx, r.currentNode.NodeID())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
startedChan <- err
|
startedChan <- err
|
||||||
return
|
return
|
||||||
@@ -258,21 +245,9 @@ func (r *RedisRouter) keepaliveWorker(startedChan chan error) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
r.nodeMu.Lock()
|
if !r.currentNode.UpdateNodeStats() {
|
||||||
if r.prevStats == nil {
|
|
||||||
r.prevStats = r.currentNode.Stats
|
|
||||||
}
|
|
||||||
updated, computedAvg, err := prometheus.GetUpdatedNodeStats(r.currentNode.Stats, r.prevStats)
|
|
||||||
if err != nil {
|
|
||||||
logger.Errorw("could not update node stats", err)
|
|
||||||
r.nodeMu.Unlock()
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
r.currentNode.Stats = updated
|
|
||||||
if computedAvg {
|
|
||||||
r.prevStats = updated
|
|
||||||
}
|
|
||||||
r.nodeMu.Unlock()
|
|
||||||
|
|
||||||
// TODO: check stats against config.Limit values
|
// TODO: check stats against config.Limit values
|
||||||
if err := r.RegisterNode(); err != nil {
|
if err := r.RegisterNode(); err != nil {
|
||||||
|
|||||||
@@ -165,7 +165,7 @@ func NewAgentService(conf *config.Config,
|
|||||||
Protocol: types.CurrentProtocol,
|
Protocol: types.CurrentProtocol,
|
||||||
AgentProtocol: agent.CurrentProtocol,
|
AgentProtocol: agent.CurrentProtocol,
|
||||||
Region: conf.Region,
|
Region: conf.Region,
|
||||||
NodeId: currentNode.Id,
|
NodeId: string(currentNode.NodeID()),
|
||||||
}
|
}
|
||||||
|
|
||||||
agentServer, err := rpc.NewAgentInternalServer(s, bus)
|
agentServer, err := rpc.NewAgentInternalServer(s, bus)
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ func TestCreateRoom(t *testing.T) {
|
|||||||
node, err := routing.NewLocalNode(conf)
|
node, err := routing.NewLocalNode(conf)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
ra, conf := newTestRoomAllocator(t, conf, node)
|
ra, conf := newTestRoomAllocator(t, conf, node.Clone())
|
||||||
|
|
||||||
room, _, _, err := ra.CreateRoom(context.Background(), &livekit.CreateRoomRequest{Name: "myroom"}, true)
|
room, _, _, err := ra.CreateRoom(context.Background(), &livekit.CreateRoomRequest{Name: "myroom"}, true)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
@@ -55,10 +55,12 @@ func SelectRoomNode(t *testing.T) {
|
|||||||
|
|
||||||
node, err := routing.NewLocalNode(conf)
|
node, err := routing.NewLocalNode(conf)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
node.Stats.NumTracksIn = 100
|
node.SetStats(&livekit.NodeStats{
|
||||||
node.Stats.NumTracksOut = 100
|
NumTracksIn: 100,
|
||||||
|
NumTracksOut: 100,
|
||||||
|
})
|
||||||
|
|
||||||
ra, _ := newTestRoomAllocator(t, conf, node)
|
ra, _ := newTestRoomAllocator(t, conf, node.Clone())
|
||||||
|
|
||||||
err = ra.SelectRoomNode(context.Background(), "low-limit-room", "")
|
err = ra.SelectRoomNode(context.Background(), "low-limit-room", "")
|
||||||
require.ErrorIs(t, err, routing.ErrNodeLimitReached)
|
require.ErrorIs(t, err, routing.ErrNodeLimitReached)
|
||||||
@@ -71,10 +73,12 @@ func SelectRoomNode(t *testing.T) {
|
|||||||
|
|
||||||
node, err := routing.NewLocalNode(conf)
|
node, err := routing.NewLocalNode(conf)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
node.Stats.BytesInPerSec = 1000
|
node.SetStats(&livekit.NodeStats{
|
||||||
node.Stats.BytesOutPerSec = 1000
|
BytesInPerSec: 1000,
|
||||||
|
BytesOutPerSec: 1000,
|
||||||
|
})
|
||||||
|
|
||||||
ra, _ := newTestRoomAllocator(t, conf, node)
|
ra, _ := newTestRoomAllocator(t, conf, node.Clone())
|
||||||
|
|
||||||
err = ra.SelectRoomNode(context.Background(), "low-limit-room", "")
|
err = ra.SelectRoomNode(context.Background(), "low-limit-room", "")
|
||||||
require.ErrorIs(t, err, routing.ErrNodeLimitReached)
|
require.ErrorIs(t, err, routing.ErrNodeLimitReached)
|
||||||
|
|||||||
@@ -142,7 +142,7 @@ func NewLocalRoomManager(
|
|||||||
Protocol: types.CurrentProtocol,
|
Protocol: types.CurrentProtocol,
|
||||||
AgentProtocol: agent.CurrentProtocol,
|
AgentProtocol: agent.CurrentProtocol,
|
||||||
Region: conf.Region,
|
Region: conf.Region,
|
||||||
NodeId: currentNode.Id,
|
NodeId: string(currentNode.NodeID()),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,7 +150,7 @@ func NewLocalRoomManager(
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if err := r.roomManagerServer.RegisterAllNodeTopics(livekit.NodeID(currentNode.Id)); err != nil {
|
if err := r.roomManagerServer.RegisterAllNodeTopics(currentNode.NodeID()); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -315,7 +315,7 @@ func (r *RoomManager) StartSession(
|
|||||||
// It is possible that the client did not get that send request. So, send it again.
|
// It is possible that the client did not get that send request. So, send it again.
|
||||||
logger.Infow("cannot restart a closed participant",
|
logger.Infow("cannot restart a closed participant",
|
||||||
"room", room.Name(),
|
"room", room.Name(),
|
||||||
"nodeID", r.currentNode.Id,
|
"nodeID", r.currentNode.NodeID(),
|
||||||
"participant", pi.Identity,
|
"participant", pi.Identity,
|
||||||
"reason", pi.ReconnectReason,
|
"reason", pi.ReconnectReason,
|
||||||
)
|
)
|
||||||
@@ -342,7 +342,7 @@ func (r *RoomManager) StartSession(
|
|||||||
}
|
}
|
||||||
|
|
||||||
participant.GetLogger().Infow("resuming RTC session",
|
participant.GetLogger().Infow("resuming RTC session",
|
||||||
"nodeID", r.currentNode.Id,
|
"nodeID", r.currentNode.NodeID(),
|
||||||
"reason", pi.ReconnectReason,
|
"reason", pi.ReconnectReason,
|
||||||
"numParticipants", room.GetParticipantCount(),
|
"numParticipants", room.GetParticipantCount(),
|
||||||
)
|
)
|
||||||
@@ -362,7 +362,7 @@ func (r *RoomManager) StartSession(
|
|||||||
participant.GetLogger().Warnw("could not resume participant", err)
|
participant.GetLogger().Warnw("could not resume participant", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
r.telemetry.ParticipantResumed(ctx, room.ToProto(), participant.ToProto(), livekit.NodeID(r.currentNode.Id), pi.ReconnectReason)
|
r.telemetry.ParticipantResumed(ctx, room.ToProto(), participant.ToProto(), r.currentNode.NodeID(), pi.ReconnectReason)
|
||||||
go r.rtcSessionWorker(room, participant, requestSource)
|
go r.rtcSessionWorker(room, participant, requestSource)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -403,7 +403,7 @@ func (r *RoomManager) StartSession(
|
|||||||
)
|
)
|
||||||
pLogger.Infow("starting RTC session",
|
pLogger.Infow("starting RTC session",
|
||||||
"room", room.Name(),
|
"room", room.Name(),
|
||||||
"nodeID", r.currentNode.Id,
|
"nodeID", r.currentNode.NodeID(),
|
||||||
"clientInfo", logger.Proto(pi.Client),
|
"clientInfo", logger.Proto(pi.Client),
|
||||||
"reconnect", pi.Reconnect,
|
"reconnect", pi.Reconnect,
|
||||||
"reconnectReason", pi.ReconnectReason,
|
"reconnectReason", pi.ReconnectReason,
|
||||||
@@ -532,7 +532,7 @@ func (r *RoomManager) StartSession(
|
|||||||
// update room store with new numParticipants
|
// update room store with new numParticipants
|
||||||
persistRoomForParticipantCount(room.ToProto())
|
persistRoomForParticipantCount(room.ToProto())
|
||||||
|
|
||||||
clientMeta := &livekit.AnalyticsClientMeta{Region: r.currentNode.Region, Node: r.currentNode.Id}
|
clientMeta := &livekit.AnalyticsClientMeta{Region: r.currentNode.Region(), Node: string(r.currentNode.NodeID())}
|
||||||
r.telemetry.ParticipantJoined(ctx, protoRoom, participant.ToProto(), pi.Client, clientMeta, true)
|
r.telemetry.ParticipantJoined(ctx, protoRoom, participant.ToProto(), pi.Client, clientMeta, true)
|
||||||
participant.OnClose(func(p types.LocalParticipant) {
|
participant.OnClose(func(p types.LocalParticipant) {
|
||||||
killParticipantServer()
|
killParticipantServer()
|
||||||
|
|||||||
@@ -172,7 +172,7 @@ func NewLivekitServer(conf *config.Config,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *LivekitServer) Node() *livekit.Node {
|
func (s *LivekitServer) Node() *livekit.Node {
|
||||||
return s.currentNode
|
return s.currentNode.Clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *LivekitServer) HTTPPort() int {
|
func (s *LivekitServer) HTTPPort() int {
|
||||||
@@ -232,8 +232,8 @@ func (s *LivekitServer) Start() error {
|
|||||||
|
|
||||||
values := []interface{}{
|
values := []interface{}{
|
||||||
"portHttp", s.config.Port,
|
"portHttp", s.config.Port,
|
||||||
"nodeID", s.currentNode.Id,
|
"nodeID", s.currentNode.NodeID(),
|
||||||
"nodeIP", s.currentNode.Ip,
|
"nodeIP", s.currentNode.NodeIP(),
|
||||||
"version", version.Version,
|
"version", version.Version,
|
||||||
}
|
}
|
||||||
if s.config.BindAddresses != nil {
|
if s.config.BindAddresses != nil {
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ func NewDefaultSignalServer(
|
|||||||
router routing.Router,
|
router routing.Router,
|
||||||
roomManager *RoomManager,
|
roomManager *RoomManager,
|
||||||
) (r *SignalServer, err error) {
|
) (r *SignalServer, err error) {
|
||||||
return NewSignalServer(livekit.NodeID(currentNode.Id), currentNode.Region, bus, config, &defaultSessionHandler{currentNode, router, roomManager})
|
return NewSignalServer(currentNode.NodeID(), currentNode.Region(), bus, config, &defaultSessionHandler{currentNode, router, roomManager})
|
||||||
}
|
}
|
||||||
|
|
||||||
type defaultSessionHandler struct {
|
type defaultSessionHandler struct {
|
||||||
@@ -105,7 +105,7 @@ func (s *defaultSessionHandler) HandleSession(
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if rtcNode.Id != s.currentNode.Id {
|
if livekit.NodeID(rtcNode.Id) != s.currentNode.NodeID() {
|
||||||
err = routing.ErrIncorrectRTCNode
|
err = routing.ErrIncorrectRTCNode
|
||||||
logger.Errorw("called participant on incorrect node", err,
|
logger.Errorw("called participant on incorrect node", err,
|
||||||
"rtcNode", rtcNode,
|
"rtcNode", rtcNode,
|
||||||
|
|||||||
+1
-1
@@ -123,7 +123,7 @@ func InitializeRouter(conf *config.Config, currentNode routing.LocalNode) (routi
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getNodeID(currentNode routing.LocalNode) livekit.NodeID {
|
func getNodeID(currentNode routing.LocalNode) livekit.NodeID {
|
||||||
return livekit.NodeID(currentNode.Id)
|
return currentNode.NodeID()
|
||||||
}
|
}
|
||||||
|
|
||||||
func createKeyProvider(conf *config.Config) (auth.KeyProvider, error) {
|
func createKeyProvider(conf *config.Config) (auth.KeyProvider, error) {
|
||||||
|
|||||||
@@ -183,7 +183,7 @@ func InitializeRouter(conf *config.Config, currentNode routing.LocalNode) (routi
|
|||||||
// wire.go:
|
// wire.go:
|
||||||
|
|
||||||
func getNodeID(currentNode routing.LocalNode) livekit.NodeID {
|
func getNodeID(currentNode routing.LocalNode) livekit.NodeID {
|
||||||
return livekit.NodeID(currentNode.Id)
|
return currentNode.NodeID()
|
||||||
}
|
}
|
||||||
|
|
||||||
func createKeyProvider(conf *config.Config) (auth.KeyProvider, error) {
|
func createKeyProvider(conf *config.Config) (auth.KeyProvider, error) {
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ type analyticsService struct {
|
|||||||
func NewAnalyticsService(_ *config.Config, currentNode routing.LocalNode) AnalyticsService {
|
func NewAnalyticsService(_ *config.Config, currentNode routing.LocalNode) AnalyticsService {
|
||||||
return &analyticsService{
|
return &analyticsService{
|
||||||
analyticsKey: "", // TODO: conf.AnalyticsKey
|
analyticsKey: "", // TODO: conf.AnalyticsKey
|
||||||
nodeID: currentNode.Id,
|
nodeID: string(currentNode.NodeID()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -161,7 +161,7 @@ func createSingleNodeServer(configUpdater func(*config.Config)) *service.Livekit
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Sprintf("could not create local node: %v", err))
|
panic(fmt.Sprintf("could not create local node: %v", err))
|
||||||
}
|
}
|
||||||
currentNode.Id = guid.New(nodeID1)
|
currentNode.SetNodeID(livekit.NodeID(guid.New(nodeID1)))
|
||||||
|
|
||||||
s, err := service.InitializeServer(conf, currentNode)
|
s, err := service.InitializeServer(conf, currentNode)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -188,7 +188,7 @@ func createMultiNodeServer(nodeID string, port uint32) *service.LivekitServer {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
currentNode.Id = nodeID
|
currentNode.SetNodeID(livekit.NodeID(nodeID))
|
||||||
|
|
||||||
// redis routing and store
|
// redis routing and store
|
||||||
s, err := service.InitializeServer(conf, currentNode)
|
s, err := service.InitializeServer(conf, currentNode)
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ func setupServerWithWebhook() (server *service.LivekitServer, testServer *webhoo
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
currentNode.Id = guid.New(nodeID1)
|
currentNode.SetNodeID(livekit.NodeID(guid.New(nodeID1)))
|
||||||
|
|
||||||
server, err = service.InitializeServer(conf, currentNode)
|
server, err = service.InitializeServer(conf, currentNode)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user