From e11f3d852fabc2bcbf73fa92c0555877996510cc Mon Sep 17 00:00:00 2001 From: Gyuho Lee Date: Fri, 4 May 2018 11:48:20 -0700 Subject: [PATCH] rafthttp: add more details to structured logger Signed-off-by: Gyuho Lee --- rafthttp/http.go | 15 +++++++++++---- rafthttp/snapshot_sender.go | 7 +++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/rafthttp/http.go b/rafthttp/http.go index f087864ea..6ff9b67f7 100644 --- a/rafthttp/http.go +++ b/rafthttp/http.go @@ -29,6 +29,7 @@ import ( "github.com/coreos/etcd/raftsnap" "github.com/coreos/etcd/version" + humanize "github.com/dustin/go-humanize" "go.uber.org/zap" ) @@ -229,7 +230,8 @@ func (h *snapshotHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { return } - receivedBytes.WithLabelValues(types.ID(m.From).String()).Add(float64(m.Size())) + msgSize := m.Size() + receivedBytes.WithLabelValues(types.ID(m.From).String()).Add(float64(msgSize)) if m.Type != raftpb.MsgSnap { if h.lg != nil { @@ -251,7 +253,9 @@ func (h *snapshotHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { "receiving database snapshot", zap.String("local-member-id", h.localID.String()), zap.String("remote-snapshot-sender-id", types.ID(m.From).String()), - zap.Uint64("snapshot-index", m.Snapshot.Metadata.Index), + 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))), ) } else { plog.Infof("receiving database snapshot [index:%d, from %s] ...", m.Snapshot.Metadata.Index, types.ID(m.From)) @@ -263,9 +267,10 @@ func (h *snapshotHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { msg := fmt.Sprintf("failed to save KV snapshot (%v)", err) if h.lg != nil { h.lg.Warn( - "failed to save KV snapshot", + "failed to save incoming database snapshot", zap.String("local-member-id", h.localID.String()), zap.String("remote-snapshot-sender-id", types.ID(m.From).String()), + zap.Uint64("incoming-snapshot-index", m.Snapshot.Metadata.Index), zap.Error(err), ) } else { @@ -282,7 +287,9 @@ func (h *snapshotHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { "received and saved database snapshot", zap.String("local-member-id", h.localID.String()), zap.String("remote-snapshot-sender-id", types.ID(m.From).String()), - zap.Uint64("snapshot-index", m.Snapshot.Metadata.Index), + 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))), ) } else { plog.Infof("received and saved database snapshot [index: %d, from: %s] successfully", m.Snapshot.Metadata.Index, types.ID(m.From)) diff --git a/rafthttp/snapshot_sender.go b/rafthttp/snapshot_sender.go index b1bd149a0..1924c24b1 100644 --- a/rafthttp/snapshot_sender.go +++ b/rafthttp/snapshot_sender.go @@ -28,6 +28,7 @@ import ( "github.com/coreos/etcd/raft" "github.com/coreos/etcd/raftsnap" + "github.com/dustin/go-humanize" "go.uber.org/zap" ) @@ -79,6 +80,8 @@ func (s *snapshotSender) send(merged raftsnap.Message) { "sending database snapshot", zap.Uint64("snapshot-index", m.Snapshot.Metadata.Index), zap.String("remote-peer-id", types.ID(m.To).String()), + zap.Int64("bytes", merged.TotalSize), + zap.String("size", humanize.Bytes(uint64(merged.TotalSize))), ) } else { plog.Infof("start to send database snapshot [index: %d, to %s]...", m.Snapshot.Metadata.Index, types.ID(m.To)) @@ -92,6 +95,8 @@ func (s *snapshotSender) send(merged raftsnap.Message) { "failed to send database snapshot", zap.Uint64("snapshot-index", m.Snapshot.Metadata.Index), zap.String("remote-peer-id", types.ID(m.To).String()), + zap.Int64("bytes", merged.TotalSize), + zap.String("size", humanize.Bytes(uint64(merged.TotalSize))), zap.Error(err), ) } else { @@ -122,6 +127,8 @@ func (s *snapshotSender) send(merged raftsnap.Message) { "sent database snapshot", zap.Uint64("snapshot-index", m.Snapshot.Metadata.Index), zap.String("remote-peer-id", types.ID(m.To).String()), + zap.Int64("bytes", merged.TotalSize), + zap.String("size", humanize.Bytes(uint64(merged.TotalSize))), ) } else { plog.Infof("database snapshot [index: %d, to: %s] sent out successfully", m.Snapshot.Metadata.Index, types.ID(m.To))