Add more logging to response lines

This commit is contained in:
Kegan Dougal 2023-07-31 10:24:36 +01:00
parent 13673175b5
commit 8b6f48a24b
3 changed files with 25 additions and 9 deletions

View File

@ -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
}

View File

@ -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")

View File

@ -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))