Log join duration. (#4433)
* Log join duration. Also revert the "unresolved" init. Defeated the purpose of log resolver as it was resolving with those values even if not forced. Instead set it to "unresolved" if not set when forced. Join duration is not reset if resolver is reset as that happens on moving a participant and there is no new join duration in that case. * explode
This commit is contained in:
@@ -289,11 +289,13 @@ func (s *RTCService) serve(w http.ResponseWriter, r *http.Request, needsJoinRequ
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
startedAt := time.Now()
|
||||||
var (
|
var (
|
||||||
roomName livekit.RoomName = "unresolved"
|
roomName livekit.RoomName
|
||||||
roomID livekit.RoomID = "unresolved"
|
roomID livekit.RoomID
|
||||||
participantIdentity livekit.ParticipantIdentity = "unresolved"
|
participantIdentity livekit.ParticipantIdentity
|
||||||
pID livekit.ParticipantID = "unresolved"
|
pID livekit.ParticipantID
|
||||||
|
joinDuration time.Duration
|
||||||
loggerResolved bool
|
loggerResolved bool
|
||||||
|
|
||||||
pi routing.ParticipantInit
|
pi routing.ParticipantInit
|
||||||
@@ -309,6 +311,7 @@ func (s *RTCService) serve(w http.ResponseWriter, r *http.Request, needsJoinRequ
|
|||||||
"roomID", roomID,
|
"roomID", roomID,
|
||||||
"participant", participantIdentity,
|
"participant", participantIdentity,
|
||||||
"participantID", pID,
|
"participantID", pID,
|
||||||
|
"joinDuration", joinDuration,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -317,7 +320,25 @@ func (s *RTCService) serve(w http.ResponseWriter, r *http.Request, needsJoinRequ
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if force || (roomName != "" && roomID != "" && participantIdentity != "" && pID != "") {
|
if force {
|
||||||
|
if roomName == "" {
|
||||||
|
roomName = "unresolved"
|
||||||
|
}
|
||||||
|
if roomID == "" {
|
||||||
|
roomID = "unresolved"
|
||||||
|
}
|
||||||
|
if participantIdentity == "" {
|
||||||
|
participantIdentity = "unresolved"
|
||||||
|
}
|
||||||
|
if pID == "" {
|
||||||
|
pID = "unresolved"
|
||||||
|
}
|
||||||
|
if joinDuration == 0 {
|
||||||
|
joinDuration = time.Since(startedAt)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if roomName != "" && roomID != "" && participantIdentity != "" && pID != "" {
|
||||||
loggerResolved = true
|
loggerResolved = true
|
||||||
loggerResolver.Resolve(getLoggerFields()...)
|
loggerResolver.Resolve(getLoggerFields()...)
|
||||||
}
|
}
|
||||||
@@ -335,6 +356,7 @@ func (s *RTCService) serve(w http.ResponseWriter, r *http.Request, needsJoinRequ
|
|||||||
|
|
||||||
roomName, pi, code, err = s.validateInternal(pLogger, r, needsJoinRequest, false)
|
roomName, pi, code, err = s.validateInternal(pLogger, r, needsJoinRequest, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
resolveLogger(true)
|
||||||
HandleError(w, r, code, err, getLoggerFields()...)
|
HandleError(w, r, code, err, getLoggerFields()...)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -343,7 +365,7 @@ func (s *RTCService) serve(w http.ResponseWriter, r *http.Request, needsJoinRequ
|
|||||||
if pi.ID != "" {
|
if pi.ID != "" {
|
||||||
pID = pi.ID
|
pID = pi.ID
|
||||||
}
|
}
|
||||||
pLogger.Debugw("join request validated", append(getLoggerFields(), "participantInit", &pi))
|
pLogger.Debugw("join request validated", append(getLoggerFields(), "participantInit", &pi)...)
|
||||||
|
|
||||||
// give it a few attempts to start session
|
// give it a few attempts to start session
|
||||||
var cr connectionResult
|
var cr connectionResult
|
||||||
@@ -364,11 +386,13 @@ func (s *RTCService) serve(w http.ResponseWriter, r *http.Request, needsJoinRequ
|
|||||||
if errors.As(err, &psrpcErr) {
|
if errors.As(err, &psrpcErr) {
|
||||||
status = psrpcErr.ToHttp()
|
status = psrpcErr.ToHttp()
|
||||||
}
|
}
|
||||||
|
resolveLogger(true)
|
||||||
HandleError(w, r, status, err, getLoggerFields()...)
|
HandleError(w, r, status, err, getLoggerFields()...)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
prometheus.IncrementParticipantJoin(1)
|
prometheus.IncrementParticipantJoin(1)
|
||||||
|
joinDuration = time.Since(startedAt)
|
||||||
|
|
||||||
pLogger = pLogger.WithValues("connID", cr.ConnectionID)
|
pLogger = pLogger.WithValues("connID", cr.ConnectionID)
|
||||||
if !pi.Reconnect && initialResponse.GetJoin() != nil {
|
if !pi.Reconnect && initialResponse.GetJoin() != nil {
|
||||||
@@ -399,6 +423,7 @@ func (s *RTCService) serve(w http.ResponseWriter, r *http.Request, needsJoinRequ
|
|||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
// function exits when websocket terminates, it'll close the event reading off of request sink and response source as well
|
// function exits when websocket terminates, it'll close the event reading off of request sink and response source as well
|
||||||
defer func() {
|
defer func() {
|
||||||
|
resolveLogger(true)
|
||||||
pLogger.Debugw("finishing WS connection", "closedByClient", closedByClient.Load())
|
pLogger.Debugw("finishing WS connection", "closedByClient", closedByClient.Load())
|
||||||
cr.ResponseSource.Close()
|
cr.ResponseSource.Close()
|
||||||
cr.RequestSink.Close()
|
cr.RequestSink.Close()
|
||||||
@@ -410,6 +435,7 @@ func (s *RTCService) serve(w http.ResponseWriter, r *http.Request, needsJoinRequ
|
|||||||
// upgrade only once the basics are good to go
|
// upgrade only once the basics are good to go
|
||||||
conn, err := s.upgrader.Upgrade(w, r, nil)
|
conn, err := s.upgrader.Upgrade(w, r, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
resolveLogger(true)
|
||||||
HandleError(w, r, http.StatusInternalServerError, err, getLoggerFields()...)
|
HandleError(w, r, http.StatusInternalServerError, err, getLoggerFields()...)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user