Track buffer sizes in summary line

This commit is contained in:
Kegan Dougal 2023-07-24 14:42:02 +01:00
parent 7dc999a44e
commit 3536307204
2 changed files with 19 additions and 0 deletions

View File

@ -2,6 +2,8 @@ package internal
import (
"context"
"fmt"
"github.com/getsentry/sentry-go"
"github.com/rs/zerolog"
@ -17,6 +19,7 @@ var (
type data struct {
userID string
deviceID string
bufferSummary string
since int64
next int64
numRooms int
@ -53,6 +56,15 @@ func SetRequestContextUserID(ctx context.Context, userID, deviceID string) {
}
}
func SetConnBufferInfo(ctx context.Context, bufferLen, nextLen, bufferCap int) {
d := ctx.Value(ctxData)
if d == nil {
return
}
da := d.(*data)
da.bufferSummary = fmt.Sprintf("%d/%d/%d", bufferLen, nextLen, bufferCap)
}
func SetRequestContextResponseInfo(
ctx context.Context, since, next int64, numRooms int, txnID string, numToDeviceEvents, numGlobalAccountData int,
numChangedDevices, numLeftDevices int,
@ -108,5 +120,8 @@ func DecorateLogger(ctx context.Context, l *zerolog.Event) *zerolog.Event {
if da.numLeftDevices > 0 {
l = l.Int("dl-l", da.numLeftDevices)
}
if da.bufferSummary != "" {
l = l.Str("b", da.bufferSummary)
}
return l
}

View File

@ -57,6 +57,7 @@ func (s *connStateLive) liveUpdate(
if req.TimeoutMSecs() < 100 {
req.SetTimeoutMSecs(100)
}
startBufferSize := len(s.updates)
// block until we get a new event, with appropriate timeout
startTime := time.Now()
hasLiveStreamed := false
@ -104,6 +105,9 @@ func (s *connStateLive) liveUpdate(
}
log.Trace().Bool("live_streamed", hasLiveStreamed).Msg("liveUpdate: returning")
internal.SetConnBufferInfo(ctx, startBufferSize, len(s.updates), cap(s.updates))
// TODO: op consolidation
}