Skip to content

Commit

Permalink
chore(mailserver)_: reduce debug logs size in messenger_mailserver
Browse files Browse the repository at this point in the history
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
  • Loading branch information
osmaczko committed Sep 30, 2024
1 parent 9eb2d97 commit 291b87f
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions protocol/messenger_mailserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package protocol

import (
"context"
"crypto/sha256"
"encoding/hex"
"fmt"
"math"
"sort"
Expand Down Expand Up @@ -756,15 +758,15 @@ func processMailserverBatch(
for _, t := range batch.Topics {
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("toString", time.Unix(int64(batch.To), 0).Format(time.RFC3339)),
zap.Any("topic", topicStrings),
zap.Int64("from", int64(batch.From)),
zap.Int64("to", int64(batch.To)))

logger.Info("syncing topic")

wg := sync.WaitGroup{}
workWg := sync.WaitGroup{}
workCh := make(chan work, 1000) // each batch item is split in 10 topics bunch and sent to this channel
Expand Down Expand Up @@ -959,6 +961,12 @@ type MailserverBatch struct {
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) {
chat, ok := m.allChats.Load(chatID)
if !ok {
Expand Down

0 comments on commit 291b87f

Please sign in to comment.