Add stats for data channel and signal (#1198)
* Add stats for data channel and signal * Solve comment
This commit is contained in:
+11
-1
@@ -129,6 +129,8 @@ type ParticipantImpl struct {
|
||||
subscribedTo map[livekit.ParticipantID]struct{}
|
||||
unpublishedTracks []*livekit.TrackInfo
|
||||
|
||||
dataChannelStats *telemetry.BytesTrackStats
|
||||
|
||||
rttUpdatedAt time.Time
|
||||
lastRTT uint32
|
||||
|
||||
@@ -184,7 +186,11 @@ func NewParticipant(params ParticipantParams) (*ParticipantImpl, error) {
|
||||
subscriptionInProgress: make(map[livekit.TrackID]bool),
|
||||
subscriptionRequestsQueue: make(map[livekit.TrackID][]SubscribeRequest),
|
||||
trackPublisherVersion: make(map[livekit.TrackID]uint32),
|
||||
supervisor: supervisor.NewParticipantSupervisor(supervisor.ParticipantSupervisorParams{Logger: params.Logger}),
|
||||
dataChannelStats: telemetry.NewBytesTrackStats(
|
||||
telemetry.BytesTrackIDForParticipantID(telemetry.BytesTrackTypeData, params.SID),
|
||||
params.SID,
|
||||
params.Telemetry),
|
||||
supervisor: supervisor.NewParticipantSupervisor(supervisor.ParticipantSupervisorParams{Logger: params.Logger}),
|
||||
}
|
||||
p.version.Store(params.InitialVersion)
|
||||
p.migrateState.Store(types.MigrateStateInit)
|
||||
@@ -601,6 +607,8 @@ func (p *ParticipantImpl) Close(sendLeave bool, reason types.ParticipantCloseRea
|
||||
|
||||
p.TransportManager.Close()
|
||||
}()
|
||||
|
||||
p.dataChannelStats.Report()
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1187,6 +1195,8 @@ func (p *ParticipantImpl) onDataMessage(kind livekit.DataPacket_Kind, data []byt
|
||||
return
|
||||
}
|
||||
|
||||
p.dataChannelStats.AddBytes(uint64(len(data)), false)
|
||||
|
||||
dp := livekit.DataPacket{}
|
||||
if err := proto.Unmarshal(data, &dp); err != nil {
|
||||
p.params.Logger.Warnw("could not parse data packet", err)
|
||||
|
||||
@@ -104,12 +104,16 @@ func (p *ParticipantImpl) SendSpeakerUpdate(speakers []*livekit.SpeakerInfo) err
|
||||
})
|
||||
}
|
||||
|
||||
func (p *ParticipantImpl) SendDataPacket(dp *livekit.DataPacket) error {
|
||||
func (p *ParticipantImpl) SendDataPacket(dp *livekit.DataPacket, data []byte) error {
|
||||
if p.State() != livekit.ParticipantInfo_ACTIVE {
|
||||
return ErrDataChannelUnavailable
|
||||
}
|
||||
|
||||
return p.TransportManager.SendDataPacket(dp)
|
||||
err := p.TransportManager.SendDataPacket(dp, data)
|
||||
if err == nil {
|
||||
p.dataChannelStats.AddBytes(uint64(len(data)), true)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (p *ParticipantImpl) SendRoomUpdate(room *livekit.Room) error {
|
||||
|
||||
+21
-2
@@ -772,6 +772,7 @@ func (r *Room) onParticipantUpdate(p types.LocalParticipant) {
|
||||
|
||||
func (r *Room) onDataPacket(source types.LocalParticipant, dp *livekit.DataPacket) {
|
||||
dest := dp.GetUser().GetDestinationSids()
|
||||
var dpData []byte
|
||||
|
||||
for _, op := range r.GetParticipants() {
|
||||
if op.State() != livekit.ParticipantInfo_ACTIVE {
|
||||
@@ -792,7 +793,16 @@ func (r *Room) onDataPacket(source types.LocalParticipant, dp *livekit.DataPacke
|
||||
continue
|
||||
}
|
||||
}
|
||||
err := op.SendDataPacket(dp)
|
||||
if dpData == nil {
|
||||
var err error
|
||||
dpData, err = proto.Marshal(dp)
|
||||
if err != nil {
|
||||
r.Logger.Errorw("failed to marshal data packet", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
err := op.SendDataPacket(dp, dpData)
|
||||
if err != nil {
|
||||
r.Logger.Infow("send data packet error", "error", err, "participant", op.Identity())
|
||||
}
|
||||
@@ -879,9 +889,18 @@ func (r *Room) sendActiveSpeakers(speakers []*livekit.SpeakerInfo) {
|
||||
},
|
||||
}
|
||||
|
||||
var dpData []byte
|
||||
for _, p := range r.GetParticipants() {
|
||||
if p.ProtocolVersion().HandlesDataPackets() && !p.ProtocolVersion().SupportsSpeakerChanged() {
|
||||
_ = p.SendDataPacket(dp)
|
||||
if dpData == nil {
|
||||
var err error
|
||||
dpData, err = proto.Marshal(dp)
|
||||
if err != nil {
|
||||
r.Logger.Errorw("failed to marshal ActiveSpeaker data packet", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
_ = p.SendDataPacket(dp, dpData)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -554,7 +554,8 @@ func TestDataChannel(t *testing.T) {
|
||||
continue
|
||||
}
|
||||
require.Equal(t, 1, fp.SendDataPacketCallCount())
|
||||
require.Equal(t, packet.Value, fp.SendDataPacketArgsForCall(0).Value)
|
||||
dp, _ := fp.SendDataPacketArgsForCall(0)
|
||||
require.Equal(t, packet.Value, dp.Value)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -585,7 +586,8 @@ func TestDataChannel(t *testing.T) {
|
||||
}
|
||||
}
|
||||
require.Equal(t, 1, p1.SendDataPacketCallCount())
|
||||
require.Equal(t, packet.Value, p1.SendDataPacketArgsForCall(0).Value)
|
||||
dp, _ := p1.SendDataPacketArgsForCall(0)
|
||||
require.Equal(t, packet.Value, dp.Value)
|
||||
})
|
||||
|
||||
t.Run("publishing disallowed", func(t *testing.T) {
|
||||
|
||||
@@ -18,7 +18,6 @@ import (
|
||||
"github.com/pion/webrtc/v3"
|
||||
"github.com/pkg/errors"
|
||||
"go.uber.org/atomic"
|
||||
"google.golang.org/protobuf/proto"
|
||||
|
||||
"github.com/livekit/protocol/livekit"
|
||||
"github.com/livekit/protocol/logger"
|
||||
@@ -726,12 +725,7 @@ func (t *PCTransport) WriteRTCP(pkts []rtcp.Packet) error {
|
||||
return t.pc.WriteRTCP(pkts)
|
||||
}
|
||||
|
||||
func (t *PCTransport) SendDataPacket(dp *livekit.DataPacket) error {
|
||||
data, err := proto.Marshal(dp)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
func (t *PCTransport) SendDataPacket(dp *livekit.DataPacket, data []byte) error {
|
||||
var dc *webrtc.DataChannel
|
||||
t.lock.RLock()
|
||||
if dp.Kind == livekit.DataPacket_RELIABLE {
|
||||
|
||||
@@ -284,9 +284,9 @@ func (t *TransportManager) OnDataMessage(f func(kind livekit.DataPacket_Kind, da
|
||||
t.publisher.OnDataPacket(f)
|
||||
}
|
||||
|
||||
func (t *TransportManager) SendDataPacket(dp *livekit.DataPacket) error {
|
||||
func (t *TransportManager) SendDataPacket(dp *livekit.DataPacket, data []byte) error {
|
||||
// downstream data is sent via primary peer connection
|
||||
return t.getTransport(true).SendDataPacket(dp)
|
||||
return t.getTransport(true).SendDataPacket(dp, data)
|
||||
}
|
||||
|
||||
func (t *TransportManager) createDataChannelsForSubscriber(pendingDataChannels []*livekit.DataChannelInfo) error {
|
||||
|
||||
@@ -289,7 +289,7 @@ type LocalParticipant interface {
|
||||
SendJoinResponse(joinResponse *livekit.JoinResponse) error
|
||||
SendParticipantUpdate(participants []*livekit.ParticipantInfo) error
|
||||
SendSpeakerUpdate(speakers []*livekit.SpeakerInfo) error
|
||||
SendDataPacket(packet *livekit.DataPacket) error
|
||||
SendDataPacket(packet *livekit.DataPacket, data []byte) error
|
||||
SendRoomUpdate(room *livekit.Room) error
|
||||
SendConnectionQualityUpdate(update *livekit.ConnectionQualityUpdate) error
|
||||
SubscriptionPermissionUpdate(publisherID livekit.ParticipantID, trackID livekit.TrackID, allowed bool)
|
||||
|
||||
@@ -540,10 +540,11 @@ type FakeLocalParticipant struct {
|
||||
sendConnectionQualityUpdateReturnsOnCall map[int]struct {
|
||||
result1 error
|
||||
}
|
||||
SendDataPacketStub func(*livekit.DataPacket) error
|
||||
SendDataPacketStub func(*livekit.DataPacket, []byte) error
|
||||
sendDataPacketMutex sync.RWMutex
|
||||
sendDataPacketArgsForCall []struct {
|
||||
arg1 *livekit.DataPacket
|
||||
arg2 []byte
|
||||
}
|
||||
sendDataPacketReturns struct {
|
||||
result1 error
|
||||
@@ -3591,18 +3592,24 @@ func (fake *FakeLocalParticipant) SendConnectionQualityUpdateReturnsOnCall(i int
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *FakeLocalParticipant) SendDataPacket(arg1 *livekit.DataPacket) error {
|
||||
func (fake *FakeLocalParticipant) SendDataPacket(arg1 *livekit.DataPacket, arg2 []byte) error {
|
||||
var arg2Copy []byte
|
||||
if arg2 != nil {
|
||||
arg2Copy = make([]byte, len(arg2))
|
||||
copy(arg2Copy, arg2)
|
||||
}
|
||||
fake.sendDataPacketMutex.Lock()
|
||||
ret, specificReturn := fake.sendDataPacketReturnsOnCall[len(fake.sendDataPacketArgsForCall)]
|
||||
fake.sendDataPacketArgsForCall = append(fake.sendDataPacketArgsForCall, struct {
|
||||
arg1 *livekit.DataPacket
|
||||
}{arg1})
|
||||
arg2 []byte
|
||||
}{arg1, arg2Copy})
|
||||
stub := fake.SendDataPacketStub
|
||||
fakeReturns := fake.sendDataPacketReturns
|
||||
fake.recordInvocation("SendDataPacket", []interface{}{arg1})
|
||||
fake.recordInvocation("SendDataPacket", []interface{}{arg1, arg2Copy})
|
||||
fake.sendDataPacketMutex.Unlock()
|
||||
if stub != nil {
|
||||
return stub(arg1)
|
||||
return stub(arg1, arg2)
|
||||
}
|
||||
if specificReturn {
|
||||
return ret.result1
|
||||
@@ -3616,17 +3623,17 @@ func (fake *FakeLocalParticipant) SendDataPacketCallCount() int {
|
||||
return len(fake.sendDataPacketArgsForCall)
|
||||
}
|
||||
|
||||
func (fake *FakeLocalParticipant) SendDataPacketCalls(stub func(*livekit.DataPacket) error) {
|
||||
func (fake *FakeLocalParticipant) SendDataPacketCalls(stub func(*livekit.DataPacket, []byte) error) {
|
||||
fake.sendDataPacketMutex.Lock()
|
||||
defer fake.sendDataPacketMutex.Unlock()
|
||||
fake.SendDataPacketStub = stub
|
||||
}
|
||||
|
||||
func (fake *FakeLocalParticipant) SendDataPacketArgsForCall(i int) *livekit.DataPacket {
|
||||
func (fake *FakeLocalParticipant) SendDataPacketArgsForCall(i int) (*livekit.DataPacket, []byte) {
|
||||
fake.sendDataPacketMutex.RLock()
|
||||
defer fake.sendDataPacketMutex.RUnlock()
|
||||
argsForCall := fake.sendDataPacketArgsForCall[i]
|
||||
return argsForCall.arg1
|
||||
return argsForCall.arg1, argsForCall.arg2
|
||||
}
|
||||
|
||||
func (fake *FakeLocalParticipant) SendDataPacketReturns(result1 error) {
|
||||
|
||||
Reference in New Issue
Block a user