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:
parent
9eb2d97d6d
commit
291b87f82d
|
@ -2,6 +2,8 @@ package protocol
|
|||
|
||||
import (
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"math"
|
||||
"sort"
|
||||
|
@ -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
|
||||
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue