Integrate QueuedNotifier, fixes out-of-order delivery (#1615)
This commit is contained in:
@@ -701,7 +701,7 @@ func newRoomWithParticipants(t *testing.T, opts testRoomOpts) *Room {
|
||||
NodeId: "testnode",
|
||||
Region: "testregion",
|
||||
},
|
||||
telemetry.NewTelemetryService(webhook.NewNotifier("", "", nil), &telemetryfakes.FakeAnalyticsService{}),
|
||||
telemetry.NewTelemetryService(webhook.NewDefaultNotifier("", "", nil), &telemetryfakes.FakeAnalyticsService{}),
|
||||
nil,
|
||||
)
|
||||
for i := 0; i < opts.num+opts.numHidden; i++ {
|
||||
|
||||
@@ -76,7 +76,10 @@ func TestSubscribe(t *testing.T) {
|
||||
|
||||
require.NotNil(t, s.getSubscribedTrack())
|
||||
require.Len(t, sm.GetSubscribedTracks(), 1)
|
||||
require.Len(t, sm.GetSubscribedParticipants(), 1)
|
||||
|
||||
require.Eventually(t, func() bool {
|
||||
return len(sm.GetSubscribedParticipants()) == 1
|
||||
}, subSettleTimeout, subCheckInterval, "GetSubscribedParticipants should have returned one item")
|
||||
require.Equal(t, "pubID", string(sm.GetSubscribedParticipants()[0]))
|
||||
|
||||
// ensure telemetry events are sent
|
||||
|
||||
+2
-2
@@ -114,7 +114,7 @@ func createKeyProvider(conf *config.Config) (auth.KeyProvider, error) {
|
||||
return auth.NewFileBasedKeyProviderFromMap(conf.Keys), nil
|
||||
}
|
||||
|
||||
func createWebhookNotifier(conf *config.Config, provider auth.KeyProvider) (webhook.Notifier, error) {
|
||||
func createWebhookNotifier(conf *config.Config, provider auth.KeyProvider) (webhook.QueuedNotifier, error) {
|
||||
wc := conf.WebHook
|
||||
if len(wc.URLs) == 0 {
|
||||
return nil, nil
|
||||
@@ -124,7 +124,7 @@ func createWebhookNotifier(conf *config.Config, provider auth.KeyProvider) (webh
|
||||
return nil, ErrWebHookMissingAPIKey
|
||||
}
|
||||
|
||||
return webhook.NewNotifier(wc.APIKey, secret, wc.URLs), nil
|
||||
return webhook.NewDefaultNotifier(wc.APIKey, secret, wc.URLs), nil
|
||||
}
|
||||
|
||||
func createRedisClient(conf *config.Config) (redis.UniversalClient, error) {
|
||||
|
||||
@@ -63,12 +63,12 @@ func InitializeServer(conf *config.Config, currentNode routing.LocalNode) (*Live
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
notifier, err := createWebhookNotifier(conf, keyProvider)
|
||||
queuedNotifier, err := createWebhookNotifier(conf, keyProvider)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
analyticsService := telemetry.NewAnalyticsService(conf, currentNode)
|
||||
telemetryService := telemetry.NewTelemetryService(notifier, analyticsService)
|
||||
telemetryService := telemetry.NewTelemetryService(queuedNotifier, analyticsService)
|
||||
rtcEgressLauncher := NewEgressLauncher(egressClient, rpcClient, egressStore, telemetryService)
|
||||
roomService, err := NewRoomService(roomConfig, apiConfig, router, roomAllocator, objectStore, rtcEgressLauncher)
|
||||
if err != nil {
|
||||
@@ -159,7 +159,7 @@ func createKeyProvider(conf *config.Config) (auth.KeyProvider, error) {
|
||||
return auth.NewFileBasedKeyProviderFromMap(conf.Keys), nil
|
||||
}
|
||||
|
||||
func createWebhookNotifier(conf *config.Config, provider auth.KeyProvider) (webhook.Notifier, error) {
|
||||
func createWebhookNotifier(conf *config.Config, provider auth.KeyProvider) (webhook.QueuedNotifier, error) {
|
||||
wc := conf.WebHook
|
||||
if len(wc.URLs) == 0 {
|
||||
return nil, nil
|
||||
@@ -169,7 +169,7 @@ func createWebhookNotifier(conf *config.Config, provider auth.KeyProvider) (webh
|
||||
return nil, ErrWebHookMissingAPIKey
|
||||
}
|
||||
|
||||
return webhook.NewNotifier(wc.APIKey, secret, wc.URLs), nil
|
||||
return webhook.NewDefaultNotifier(wc.APIKey, secret, wc.URLs), nil
|
||||
}
|
||||
|
||||
func createRedisClient(conf *config.Config) (redis.UniversalClient, error) {
|
||||
|
||||
@@ -21,11 +21,9 @@ func (t *telemetryService) NotifyEvent(ctx context.Context, event *livekit.Webho
|
||||
event.CreatedAt = time.Now().Unix()
|
||||
event.Id = utils.NewGuid("EV_")
|
||||
|
||||
t.webhookPool.Submit(func() {
|
||||
if err := t.notifier.Notify(ctx, event); err != nil {
|
||||
logger.Warnw("failed to notify webhook", err, "event", event.Event)
|
||||
}
|
||||
})
|
||||
if err := t.notifier.QueueNotify(ctx, event); err != nil {
|
||||
logger.Warnw("failed to notify webhook", err, "event", event.Event)
|
||||
}
|
||||
}
|
||||
|
||||
func (t *telemetryService) RoomStarted(ctx context.Context, room *livekit.Room) {
|
||||
|
||||
@@ -5,8 +5,6 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/gammazero/workerpool"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/config"
|
||||
"github.com/livekit/protocol/livekit"
|
||||
"github.com/livekit/protocol/logger"
|
||||
@@ -72,22 +70,20 @@ const (
|
||||
type telemetryService struct {
|
||||
AnalyticsService
|
||||
|
||||
notifier webhook.Notifier
|
||||
webhookPool *workerpool.WorkerPool
|
||||
jobsChan chan func()
|
||||
notifier webhook.QueuedNotifier
|
||||
jobsChan chan func()
|
||||
|
||||
lock sync.RWMutex
|
||||
workers map[livekit.ParticipantID]*StatsWorker
|
||||
}
|
||||
|
||||
func NewTelemetryService(notifier webhook.Notifier, analytics AnalyticsService) TelemetryService {
|
||||
func NewTelemetryService(notifier webhook.QueuedNotifier, analytics AnalyticsService) TelemetryService {
|
||||
t := &telemetryService{
|
||||
AnalyticsService: analytics,
|
||||
|
||||
notifier: notifier,
|
||||
webhookPool: workerpool.New(maxWebhookWorkers),
|
||||
jobsChan: make(chan func(), jobQueueBufferSize),
|
||||
workers: make(map[livekit.ParticipantID]*StatsWorker),
|
||||
notifier: notifier,
|
||||
jobsChan: make(chan func(), jobQueueBufferSize),
|
||||
workers: make(map[livekit.ParticipantID]*StatsWorker),
|
||||
}
|
||||
|
||||
go t.run()
|
||||
|
||||
Reference in New Issue
Block a user