rafthttp: improve snapshot send logging

Signed-off-by: Gyuho Lee <leegyuho@amazon.com>
This commit is contained in:
Gyuho Lee 2020-05-18 02:20:04 -07:00
parent 9bad82fee5
commit a668adba78
2 changed files with 15 additions and 11 deletions

View File

@ -239,8 +239,9 @@ func (h *snapshotHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
msgSize := m.Size()
receivedBytes.WithLabelValues(from).Add(float64(msgSize))
msgSizeVal := m.Size()
msgSize := humanize.Bytes(uint64(msgSizeVal))
receivedBytes.WithLabelValues(from).Add(float64(msgSizeVal))
if m.Type != raftpb.MsgSnap {
if h.lg != nil {
@ -269,11 +270,11 @@ func (h *snapshotHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
zap.String("local-member-id", h.localID.String()),
zap.String("remote-snapshot-sender-id", from),
zap.Uint64("incoming-snapshot-index", m.Snapshot.Metadata.Index),
zap.Int("incoming-snapshot-message-size-bytes", msgSize),
zap.String("incoming-snapshot-message-size", humanize.Bytes(uint64(msgSize))),
zap.Int("incoming-snapshot-message-size-bytes", msgSizeVal),
zap.String("incoming-snapshot-message-size", msgSize),
)
} else {
plog.Infof("receiving database snapshot [index:%d, from %s] ...", m.Snapshot.Metadata.Index, types.ID(m.From))
plog.Infof("receiving database snapshot [index: %d, from: %s, raft message size: %s]", m.Snapshot.Metadata.Index, types.ID(m.From), msgSize)
}
// save incoming database snapshot.
@ -296,6 +297,7 @@ func (h *snapshotHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
dbSize := humanize.Bytes(uint64(n))
receivedBytes.WithLabelValues(from).Add(float64(n))
if h.lg != nil {
@ -305,10 +307,10 @@ func (h *snapshotHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
zap.String("remote-snapshot-sender-id", from),
zap.Uint64("incoming-snapshot-index", m.Snapshot.Metadata.Index),
zap.Int64("incoming-snapshot-size-bytes", n),
zap.String("incoming-snapshot-size", humanize.Bytes(uint64(n))),
zap.String("incoming-snapshot-size", dbSize),
)
} else {
plog.Infof("received and saved database snapshot [index: %d, from: %s] successfully", m.Snapshot.Metadata.Index, types.ID(m.From))
plog.Infof("successfully received and saved database snapshot [index: %d, from: %s, raft message size: %s, db size: %s]", m.Snapshot.Metadata.Index, types.ID(m.From), msgSize, dbSize)
}
if err := h.r.Process(context.TODO(), m); err != nil {

View File

@ -78,16 +78,18 @@ func (s *snapshotSender) send(merged snap.Message) {
u := s.picker.pick()
req := createPostRequest(u, RaftSnapshotPrefix, body, "application/octet-stream", s.tr.URLs, s.from, s.cid)
snapshotTotalSizeVal := uint64(merged.TotalSize)
snapshotTotalSize := humanize.Bytes(snapshotTotalSizeVal)
if s.tr.Logger != nil {
s.tr.Logger.Info(
"sending database snapshot",
zap.Uint64("snapshot-index", m.Snapshot.Metadata.Index),
zap.String("remote-peer-id", to),
zap.Int64("bytes", merged.TotalSize),
zap.String("size", humanize.Bytes(uint64(merged.TotalSize))),
zap.String("size", snapshotTotalSize),
)
} else {
plog.Infof("start to send database snapshot [index: %d, to %s]...", m.Snapshot.Metadata.Index, types.ID(m.To))
plog.Infof("start to send database snapshot [index: %d, to %s, size %s]...", m.Snapshot.Metadata.Index, types.ID(m.To), snapshotTotalSize)
}
snapshotSendInflights.WithLabelValues(to).Inc()
@ -104,7 +106,7 @@ func (s *snapshotSender) send(merged snap.Message) {
zap.Uint64("snapshot-index", m.Snapshot.Metadata.Index),
zap.String("remote-peer-id", to),
zap.Int64("bytes", merged.TotalSize),
zap.String("size", humanize.Bytes(uint64(merged.TotalSize))),
zap.String("size", snapshotTotalSize),
zap.Error(err),
)
} else {
@ -137,7 +139,7 @@ func (s *snapshotSender) send(merged snap.Message) {
zap.Uint64("snapshot-index", m.Snapshot.Metadata.Index),
zap.String("remote-peer-id", to),
zap.Int64("bytes", merged.TotalSize),
zap.String("size", humanize.Bytes(uint64(merged.TotalSize))),
zap.String("size", snapshotTotalSize),
)
} else {
plog.Infof("database snapshot [index: %d, to: %s] sent out successfully", m.Snapshot.Metadata.Index, types.ID(m.To))