Stats collect v2 (#1291)

* initial commit

* add correct label

* clean up

* more cleanup on adding stats

* cleanup

* move things to pub and sub monitors, ensure stats are correctly updated

* fix merge conflict

* Fix panic on MacOS (#1296)

* fixing last feedback

Co-authored-by: Raja Subramanian <raja.gobi@tutanota.com>
This commit is contained in:
Dan McFaul
2023-01-11 14:49:50 -07:00
committed by GitHub
co-authored by Raja Subramanian
parent 0ca80a4fa7
commit 4d6f0cd0f7
14 changed files with 147 additions and 273 deletions
+4 -9
View File
@@ -155,7 +155,6 @@ func (s *RTCService) validate(r *http.Request) (livekit.RoomName, routing.Partic
func (s *RTCService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// reject non websocket requests
if !websocket.IsWebSocketUpgrade(r) {
prometheus.ServiceOperationCounter.WithLabelValues("signal_ws", "error", "reject").Add(1)
w.WriteHeader(404)
return
}
@@ -177,10 +176,10 @@ func (s *RTCService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if !s.config.Room.AutoCreate {
_, _, err := s.store.LoadRoom(context.Background(), roomName, false)
if err == ErrRoomNotFound {
handleError(w, 404, err, loggerFields...)
handleError(w, http.StatusNotFound, err, loggerFields...)
return
} else if err != nil {
handleError(w, 500, err, loggerFields...)
handleError(w, http.StatusInternalServerError, err, loggerFields...)
return
}
}
@@ -188,7 +187,6 @@ func (s *RTCService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// create room if it doesn't exist, also assigns an RTC node for the room
rm, err := s.roomAllocator.CreateRoom(r.Context(), &livekit.CreateRoomRequest{Name: string(roomName)})
if err != nil {
prometheus.ServiceOperationCounter.WithLabelValues("signal_ws", "error", "create_room").Add(1)
handleError(w, http.StatusInternalServerError, err, loggerFields...)
return
}
@@ -196,7 +194,6 @@ func (s *RTCService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// this needs to be started first *before* using router functions on this node
connId, reqSink, resSource, err := s.router.StartParticipantSignal(r.Context(), roomName, pi)
if err != nil {
prometheus.ServiceOperationCounter.WithLabelValues("signal_ws", "error", "start_signal").Add(1)
handleError(w, http.StatusInternalServerError, err, loggerFields...)
return
}
@@ -206,11 +203,12 @@ func (s *RTCService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// instead of waiting forever on the WebSocket
initialResponse, err := readInitialResponse(resSource, maxInitialResponseWait)
if err != nil {
prometheus.ServiceOperationCounter.WithLabelValues("signal_ws", "error", "initial_response").Add(1)
handleError(w, http.StatusInternalServerError, err, loggerFields...)
return
}
prometheus.IncrementParticipantJoin(1)
if !pi.Reconnect && initialResponse.GetJoin() != nil {
pi.ID = livekit.ParticipantID(initialResponse.GetJoin().GetParticipant().GetSid())
}
@@ -246,7 +244,6 @@ func (s *RTCService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// upgrade only once the basics are good to go
conn, err := s.upgrader.Upgrade(w, r, nil)
if err != nil {
prometheus.ServiceOperationCounter.WithLabelValues("signal_ws", "error", "upgrade").Add(1)
handleError(w, http.StatusInternalServerError, err, loggerFields...)
return
}
@@ -261,8 +258,6 @@ func (s *RTCService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
signalStats.AddBytes(uint64(count), true)
}
}
prometheus.ServiceOperationCounter.WithLabelValues("signal_ws", "success", "").Add(1)
pLogger.Infow("new client WS connected", "connID", connId)
// handle responses