From 8b6f48a24b79b3afaab8cc312d1dd914ead0807f Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Mon, 31 Jul 2023 10:24:36 +0100 Subject: [PATCH] Add more logging to response lines --- internal/context.go | 21 ++++++++++++++++++++- sync3/handler/handler.go | 2 +- sync3/response.go | 11 ++++------- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/internal/context.go b/internal/context.go index bfb87b6..f3a48b4 100644 --- a/internal/context.go +++ b/internal/context.go @@ -20,6 +20,7 @@ type data struct { userID string deviceID string bufferSummary string + connID string since int64 next int64 numRooms int @@ -28,6 +29,9 @@ type data struct { numGlobalAccountData int numChangedDevices int numLeftDevices int + numLists int + roomSubs int + roomUnsubs int } // prepare a request context so it can contain syncv3 info @@ -67,7 +71,7 @@ func SetConnBufferInfo(ctx context.Context, bufferLen, nextLen, bufferCap int) { func SetRequestContextResponseInfo( ctx context.Context, since, next int64, numRooms int, txnID string, numToDeviceEvents, numGlobalAccountData int, - numChangedDevices, numLeftDevices int, + numChangedDevices, numLeftDevices int, connID string, numLists int, roomSubs, roomUnsubs int, ) { d := ctx.Value(ctxData) if d == nil { @@ -82,6 +86,10 @@ func SetRequestContextResponseInfo( da.numGlobalAccountData = numGlobalAccountData da.numChangedDevices = numChangedDevices da.numLeftDevices = numLeftDevices + da.connID = connID + da.numLists = numLists + da.roomSubs = roomSubs + da.roomUnsubs = roomUnsubs } func DecorateLogger(ctx context.Context, l *zerolog.Event) *zerolog.Event { @@ -123,5 +131,16 @@ func DecorateLogger(ctx context.Context, l *zerolog.Event) *zerolog.Event { if da.bufferSummary != "" { l = l.Str("b", da.bufferSummary) } + if da.roomSubs > 0 { + l = l.Int("sub", da.roomSubs) + } + if da.roomUnsubs > 0 { + l = l.Int("usub", da.roomUnsubs) + } + if da.numLists > 0 { + l = l.Int("l", da.numLists) + } + // always log the connection ID so we know when it isn't set + l = l.Str("c", da.connID) return l } diff --git a/sync3/handler/handler.go b/sync3/handler/handler.go index c02c5a2..dce1f2a 100644 --- a/sync3/handler/handler.go +++ b/sync3/handler/handler.go @@ -288,7 +288,7 @@ func (h *SyncLiveHandler) serve(w http.ResponseWriter, req *http.Request) error } internal.SetRequestContextResponseInfo( req.Context(), cpos, resp.PosInt(), len(resp.Rooms), requestBody.TxnID, numToDeviceEvents, numGlobalAccountData, - numChangedDevices, numLeftDevices, + numChangedDevices, numLeftDevices, requestBody.ConnID, len(requestBody.Lists), len(requestBody.RoomSubscriptions), len(requestBody.UnsubscribeRooms), ) w.Header().Set("Content-Type", "application/json") diff --git a/sync3/response.go b/sync3/response.go index fa0df50..8cf8a1d 100644 --- a/sync3/response.go +++ b/sync3/response.go @@ -21,9 +21,8 @@ type Response struct { Rooms map[string]Room `json:"rooms"` Extensions extensions.Response `json:"extensions"` - Pos string `json:"pos"` - TxnID string `json:"txn_id,omitempty"` - Session string `json:"session_id,omitempty"` + Pos string `json:"pos"` + TxnID string `json:"txn_id,omitempty"` } type ResponseList struct { @@ -68,9 +67,8 @@ func (r *Response) UnmarshalJSON(b []byte) error { } `json:"lists"` Extensions extensions.Response `json:"extensions"` - Pos string `json:"pos"` - TxnID string `json:"txn_id,omitempty"` - Session string `json:"session_id,omitempty"` + Pos string `json:"pos"` + TxnID string `json:"txn_id,omitempty"` }{} if err := json.Unmarshal(b, &temporary); err != nil { return err @@ -78,7 +76,6 @@ func (r *Response) UnmarshalJSON(b []byte) error { r.Rooms = temporary.Rooms r.Pos = temporary.Pos r.TxnID = temporary.TxnID - r.Session = temporary.Session r.Extensions = temporary.Extensions r.Lists = make(map[string]ResponseList, len(temporary.Lists))