agent service: new protocol & namespaces (#2545)

* initial worker impl

* fix test

* fix build

* TestAgentNamespaces

* log err

* nit cmt

* TestAgentMultiNode

* Update pkg/agent/worker.go

Co-authored-by: David Zhao <dz@livekit.io>

* retry on worker selection & fix review comments

* Update roommanager.go

* license

* use testutils.WIthTimeout

* abstract namespace/enabled logic into agent.Client, incrementally dispatch

* typos and dates

* lock

* timeout is now optional

* pass in topics instead of fixed

* handler handles connections

* onIdle, numConnections

* fix WithGrants

* update protocol

* check agent client

* broadcast after unlock

* fix data race

* remove ReadChan, fix dispatcher

---------

Co-authored-by: David Zhao <dz@livekit.io>
Co-authored-by: David Colburn <xero73@gmail.com>
This commit is contained in:
Théo Monnom
2024-04-03 15:25:42 -07:00
committed by GitHub
co-authored by David Zhao David Colburn
parent 63b1fba082
commit dc67f505a5
22 changed files with 1326 additions and 560 deletions
+11 -17
View File
@@ -22,12 +22,12 @@ import (
"github.com/pkg/errors"
"github.com/twitchtv/twirp"
"github.com/livekit/livekit-server/pkg/agent"
"github.com/livekit/livekit-server/pkg/config"
"github.com/livekit/livekit-server/pkg/routing"
"github.com/livekit/livekit-server/pkg/rtc"
"github.com/livekit/protocol/livekit"
"github.com/livekit/protocol/rpc"
"github.com/livekit/protocol/utils"
"github.com/livekit/psrpc"
)
@@ -39,7 +39,7 @@ type RoomService struct {
router routing.MessageRouter
roomAllocator RoomAllocator
roomStore ServiceStore
agentClient rtc.AgentClient
agentClient agent.Client
egressLauncher rtc.EgressLauncher
topicFormatter rpc.TopicFormatter
roomClient rpc.TypedRoomClient
@@ -53,7 +53,7 @@ func NewRoomService(
router routing.MessageRouter,
roomAllocator RoomAllocator,
serviceStore ServiceStore,
agentClient rtc.AgentClient,
agentClient agent.Client,
egressLauncher rtc.EgressLauncher,
topicFormatter rpc.TopicFormatter,
roomClient rpc.TypedRoomClient,
@@ -101,13 +101,10 @@ func (s *RoomService) CreateRoom(ctx context.Context, req *livekit.CreateRoomReq
defer res.ResponseSource.Close()
if created {
go func() {
s.agentClient.JobRequest(ctx, &livekit.Job{
Id: utils.NewGuid("JR_"),
Type: livekit.JobType_JT_ROOM,
Room: rm,
})
}()
go s.agentClient.LaunchJob(ctx, &agent.JobDescription{
JobType: livekit.JobType_JT_ROOM,
Room: rm,
})
if req.Egress != nil && req.Egress.Room != nil {
_, err = s.egressLauncher.StartEgress(ctx, &rpc.StartEgressRequest{
@@ -301,13 +298,10 @@ func (s *RoomService) UpdateRoomMetadata(ctx context.Context, req *livekit.Updat
}
if created {
go func() {
s.agentClient.JobRequest(ctx, &livekit.Job{
Id: utils.NewGuid("JR_"),
Type: livekit.JobType_JT_ROOM,
Room: room,
})
}()
go s.agentClient.LaunchJob(ctx, &agent.JobDescription{
JobType: livekit.JobType_JT_ROOM,
Room: room,
})
}
return room, nil