chore(mailserver)_: reduce debug logs size in messenger_mailserver

Logs from `messenger_mailserver` occupy 40 out of 100MB of data in
my `geth.log`.

Instead of extending `logger` with many parameters, such as `chatIDs`,
`topic`, etc., the hash of those parameters is calucalted and kept as a
context.

iterates: #5889
This commit is contained in:
Patryk Osmaczko 2024-09-30 13:47:48 +02:00 committed by osmaczko
parent 9eb2d97d6d
commit 291b87f82d
1 changed files with 11 additions and 3 deletions

View File

@ -2,6 +2,8 @@ package protocol
import ( import (
"context" "context"
"crypto/sha256"
"encoding/hex"
"fmt" "fmt"
"math" "math"
"sort" "sort"
@ -756,15 +758,15 @@ func processMailserverBatch(
for _, t := range batch.Topics { for _, t := range batch.Topics {
topicStrings = append(topicStrings, t.String()) topicStrings = append(topicStrings, t.String())
} }
logger = logger.With(zap.Any("chatIDs", batch.ChatIDs), logger = logger.With(zap.String("batch hash", batch.Hash()))
logger.Info("syncing topic",
zap.Any("chatIDs", batch.ChatIDs),
zap.String("fromString", time.Unix(int64(batch.From), 0).Format(time.RFC3339)), zap.String("fromString", time.Unix(int64(batch.From), 0).Format(time.RFC3339)),
zap.String("toString", time.Unix(int64(batch.To), 0).Format(time.RFC3339)), zap.String("toString", time.Unix(int64(batch.To), 0).Format(time.RFC3339)),
zap.Any("topic", topicStrings), zap.Any("topic", topicStrings),
zap.Int64("from", int64(batch.From)), zap.Int64("from", int64(batch.From)),
zap.Int64("to", int64(batch.To))) zap.Int64("to", int64(batch.To)))
logger.Info("syncing topic")
wg := sync.WaitGroup{} wg := sync.WaitGroup{}
workWg := sync.WaitGroup{} workWg := sync.WaitGroup{}
workCh := make(chan work, 1000) // each batch item is split in 10 topics bunch and sent to this channel workCh := make(chan work, 1000) // each batch item is split in 10 topics bunch and sent to this channel
@ -959,6 +961,12 @@ type MailserverBatch struct {
ChatIDs []string ChatIDs []string
} }
func (mb *MailserverBatch) Hash() string {
data := fmt.Sprintf("%d%d%s%s%v%v", mb.From, mb.To, mb.Cursor, mb.PubsubTopic, mb.Topics, mb.ChatIDs)
hash := sha256.Sum256([]byte(data))
return hex.EncodeToString(hash[:4])
}
func (m *Messenger) SyncChatFromSyncedFrom(chatID string) (uint32, error) { func (m *Messenger) SyncChatFromSyncedFrom(chatID string) (uint32, error) {
chat, ok := m.allChats.Load(chatID) chat, ok := m.allChats.Load(chatID)
if !ok { if !ok {