gotd: reduce unnecessary debug logs

This commit is contained in:
Tulir Asokan
2025-12-04 14:44:13 +02:00
parent c6dd85040c
commit c83a361c0b
9 changed files with 16 additions and 41 deletions
-4
View File
@@ -10,8 +10,6 @@ import (
) )
func (c *Conn) ackLoop(ctx context.Context) error { func (c *Conn) ackLoop(ctx context.Context) error {
log := c.log.Named("ack")
var buf []int64 var buf []int64
send := func() { send := func() {
defer func() { buf = buf[:0] }() defer func() { buf = buf[:0] }()
@@ -20,8 +18,6 @@ func (c *Conn) ackLoop(ctx context.Context) error {
c.log.Error("Failed to ACK", zap.Error(err)) c.log.Error("Failed to ACK", zap.Error(err))
return return
} }
log.Debug("Ack", zap.Int64s("msg_ids", buf))
} }
ticker := c.clock.Ticker(c.ackInterval) ticker := c.clock.Ticker(c.ackInterval)
-2
View File
@@ -2,7 +2,6 @@ package mtproto
import ( import (
"github.com/go-faster/errors" "github.com/go-faster/errors"
"go.uber.org/zap"
"go.mau.fi/mautrix-telegram/pkg/gotd/bin" "go.mau.fi/mautrix-telegram/pkg/gotd/bin"
"go.mau.fi/mautrix-telegram/pkg/gotd/mt" "go.mau.fi/mautrix-telegram/pkg/gotd/mt"
@@ -14,7 +13,6 @@ func (c *Conn) handleAck(b *bin.Buffer) error {
return errors.Wrap(err, "decode") return errors.Wrap(err, "decode")
} }
c.log.Debug("Received ack", zap.Int64s("msg_ids", ack.MsgIDs))
c.rpc.NotifyAcks(ack.MsgIDs) c.rpc.NotifyAcks(ack.MsgIDs)
return nil return nil
-3
View File
@@ -2,7 +2,6 @@ package mtproto
import ( import (
"github.com/go-faster/errors" "github.com/go-faster/errors"
"go.uber.org/zap"
"go.mau.fi/mautrix-telegram/pkg/gotd/bin" "go.mau.fi/mautrix-telegram/pkg/gotd/bin"
"go.mau.fi/mautrix-telegram/pkg/gotd/mt" "go.mau.fi/mautrix-telegram/pkg/gotd/mt"
@@ -16,8 +15,6 @@ func (c *Conn) handleMessage(msgID int64, b *bin.Buffer) error {
return errors.Wrap(err, "peek message type") return errors.Wrap(err, "peek message type")
} }
c.logWithBuffer(b).Debug("Handle message", zap.Int64("msg_id", msgID))
switch id { switch id {
case mt.NewSessionCreatedTypeID: case mt.NewSessionCreatedTypeID:
return c.handleSessionCreated(b) return c.handleSessionCreated(b)
-2
View File
@@ -21,7 +21,6 @@ func (c *Conn) handleResult(b *bin.Buffer) error {
b.ResetTo(res.Result) b.ResetTo(res.Result)
msgID := zap.Int64("msg_id", res.RequestMessageID) msgID := zap.Int64("msg_id", res.RequestMessageID)
c.logWithBuffer(b).Debug("Handle result", msgID)
// Handling gzipped results. // Handling gzipped results.
id, err := b.PeekID() id, err := b.PeekID()
@@ -36,7 +35,6 @@ func (c *Conn) handleResult(b *bin.Buffer) error {
// Replacing buffer so callback will deal with uncompressed data. // Replacing buffer so callback will deal with uncompressed data.
b = content b = content
c.logWithBuffer(b).Debug("Decompressed", msgID)
// Replacing id with inner id if error is compressed for any reason. // Replacing id with inner id if error is compressed for any reason.
if id, err = b.PeekID(); err != nil { if id, err = b.PeekID(); err != nil {
+1 -10
View File
@@ -2,7 +2,6 @@ package mtproto
import ( import (
"github.com/go-faster/errors" "github.com/go-faster/errors"
"go.uber.org/zap"
"go.mau.fi/mautrix-telegram/pkg/gotd/bin" "go.mau.fi/mautrix-telegram/pkg/gotd/bin"
"go.mau.fi/mautrix-telegram/pkg/gotd/crypto" "go.mau.fi/mautrix-telegram/pkg/gotd/crypto"
@@ -16,14 +15,8 @@ func (c *Conn) newEncryptedMessage(id int64, seq int32, payload bin.Encoder, b *
// 1) Generate Length() method for every encoder, to count length without encoding. // 1) Generate Length() method for every encoder, to count length without encoding.
// 2) Re-use buffer instead of using yet one. // 2) Re-use buffer instead of using yet one.
// 3) Do not send proto.GZIP if gzipped size is equal or bigger. // 3) Do not send proto.GZIP if gzipped size is equal or bigger.
var ( var d crypto.EncryptedMessageData
d crypto.EncryptedMessageData
log = c.log
)
if c.compressThreshold <= 0 { if c.compressThreshold <= 0 {
if obj, ok := payload.(interface{ TypeID() uint32 }); ok {
log = c.logWithTypeID(obj.TypeID())
}
d = crypto.EncryptedMessageData{ d = crypto.EncryptedMessageData{
SessionID: s.ID, SessionID: s.ID,
Salt: s.Salt, Salt: s.Salt,
@@ -38,7 +31,6 @@ func (c *Conn) newEncryptedMessage(id int64, seq int32, payload bin.Encoder, b *
return errors.Wrap(err, "encode payload") return errors.Wrap(err, "encode payload")
} }
log = c.logWithType(payloadBuf)
if payloadBuf.Len() > c.compressThreshold { if payloadBuf.Len() > c.compressThreshold {
d = crypto.EncryptedMessageData{ d = crypto.EncryptedMessageData{
SessionID: s.ID, SessionID: s.ID,
@@ -59,7 +51,6 @@ func (c *Conn) newEncryptedMessage(id int64, seq int32, payload bin.Encoder, b *
} }
} }
log.Debug("Request", zap.Int64("msg_id", id))
if err := c.cipher.Encrypt(s.Key, d, b); err != nil { if err := c.cipher.Encrypt(s.Key, d, b); err != nil {
return errors.Wrap(err, "encrypt") return errors.Wrap(err, "encrypt")
} }
+1 -9
View File
@@ -23,22 +23,14 @@ func (c *Conn) Invoke(ctx context.Context, input bin.Encoder, output bin.Decoder
Output: output, Output: output,
} }
log := c.log.With(
zap.Int64("msg_id", req.MsgID),
)
log.Debug("Invoke start")
defer log.Debug("Invoke end")
if err := c.rpc.Do(ctx, req); err != nil { if err := c.rpc.Do(ctx, req); err != nil {
var badMsgErr *badMessageError var badMsgErr *badMessageError
if errors.As(err, &badMsgErr) && badMsgErr.Code == codeIncorrectServerSalt { if errors.As(err, &badMsgErr) && badMsgErr.Code == codeIncorrectServerSalt {
// Should retry with new salt.
c.log.Debug("Setting server salt")
// Store salt from server. // Store salt from server.
c.storeSalt(badMsgErr.NewSalt) c.storeSalt(badMsgErr.NewSalt)
// Reset saved salts to fetch new. // Reset saved salts to fetch new.
c.salts.Reset() c.salts.Reset()
c.log.Info("Retrying request after basMsgErr", zap.Int64("msg_id", req.MsgID)) c.log.Info("Retrying request after updating salt from badMsgErr", zap.Int64("msg_id", req.MsgID))
return c.rpc.Do(ctx, req) return c.rpc.Do(ctx, req)
} }
return err return err
-2
View File
@@ -12,7 +12,6 @@ func (e *Engine) NotifyAcks(ids []int64) {
for _, id := range ids { for _, id := range ids {
ch, ok := e.ack[id] ch, ok := e.ack[id]
if !ok { if !ok {
e.log.Debug("Acknowledge callback not set", zap.Int64("msg_id", id))
continue continue
} }
@@ -31,7 +30,6 @@ func (e *Engine) waitAck(id int64) chan struct{} {
return c return c
} }
log.Debug("Waiting for acknowledge")
c := make(chan struct{}) c := make(chan struct{})
e.ack[id] = c e.ack[id] = c
return c return c
-4
View File
@@ -88,7 +88,6 @@ func (e *Engine) Do(ctx context.Context, req Request) error {
defer retryClose() defer retryClose()
log := e.log.With(zap.Int64("msg_id", req.MsgID)) log := e.log.With(zap.Int64("msg_id", req.MsgID))
log.Debug("Do called")
done := make(chan struct{}) done := make(chan struct{})
@@ -100,8 +99,6 @@ func (e *Engine) Do(ctx context.Context, req Request) error {
) )
handler := func(rpcBuff *bin.Buffer, rpcErr error) error { handler := func(rpcBuff *bin.Buffer, rpcErr error) error {
log.Debug("Handler called")
if ok := atomic.CompareAndSwapUint32(&handlerCalled, 0, 1); !ok { if ok := atomic.CompareAndSwapUint32(&handlerCalled, 0, 1); !ok {
log.Warn("Handler already called") log.Warn("Handler already called")
@@ -207,7 +204,6 @@ func (e *Engine) retryUntilAck(ctx context.Context, req Request) (sent bool, err
case <-e.reqCtx.Done(): case <-e.reqCtx.Done():
return errors.Wrap(e.reqCtx.Err(), "engine forcibly closed") return errors.Wrap(e.reqCtx.Err(), "engine forcibly closed")
case <-ackChan: case <-ackChan:
log.Debug("Acknowledged")
return nil return nil
case <-timer.C(): case <-timer.C():
timer.Reset(e.retryInterval) timer.Reset(e.retryInterval)
+14 -5
View File
@@ -96,7 +96,7 @@ func (c *Conn) OnSession(session mtproto.Session) error {
return c.handler.OnSession(cfg, session) return c.handler.OnSession(cfg, session)
} }
func (c *Conn) trackInvoke() func() { func (c *Conn) trackInvoke() func(bin.Encoder, bin.Decoder, *error) {
start := c.clock.Now() start := c.clock.Now()
c.mux.Lock() c.mux.Lock()
@@ -105,7 +105,7 @@ func (c *Conn) trackInvoke() func() {
c.ongoing++ c.ongoing++
c.latest = start c.latest = start
return func() { return func(input bin.Encoder, output bin.Decoder, retErr *error) {
c.mux.Lock() c.mux.Lock()
defer c.mux.Unlock() defer c.mux.Unlock()
@@ -113,9 +113,18 @@ func (c *Conn) trackInvoke() func() {
end := c.clock.Now() end := c.clock.Now()
c.latest = end c.latest = end
c.log.Debug("Invoke", var respField zap.Field
if retErr != nil {
respField = zap.Error(*retErr)
} else {
respField = zap.Any("response_payload", output)
}
c.log.Debug("Request completed",
zap.Duration("duration", end.Sub(start)), zap.Duration("duration", end.Sub(start)),
zap.Int("ongoing", c.ongoing), zap.Int("ongoing", c.ongoing),
zap.Any("request_payload", input),
respField,
) )
} }
} }
@@ -160,9 +169,9 @@ func (c *Conn) Ready() <-chan struct{} {
} }
// Invoke implements Invoker. // Invoke implements Invoker.
func (c *Conn) Invoke(ctx context.Context, input bin.Encoder, output bin.Decoder) error { func (c *Conn) Invoke(ctx context.Context, input bin.Encoder, output bin.Decoder) (retErr error) {
// Tracking ongoing invokes. // Tracking ongoing invokes.
defer c.trackInvoke()() defer c.trackInvoke()(input, output, &retErr)
if err := c.waitSession(ctx); err != nil { if err := c.waitSession(ctx); err != nil {
return errors.Wrap(err, "waitSession") return errors.Wrap(err, "waitSession")
} }