Skip to content

Commit

Permalink
rafthttp: improve snapshot logging
Browse files Browse the repository at this point in the history
Signed-off-by: Gyuho Lee <leegyuho@amazon.com>
  • Loading branch information
gyuho committed May 18, 2020
1 parent 924b812 commit 6723145
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
11 changes: 8 additions & 3 deletions rafthttp/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/coreos/etcd/raft/raftpb"
"github.com/coreos/etcd/snap"
"github.com/coreos/etcd/version"
"github.com/dustin/go-humanize"
)

const (
Expand Down Expand Up @@ -194,7 +195,9 @@ func (h *snapshotHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}

receivedBytes.WithLabelValues(from).Add(float64(m.Size()))
msgSizeVal := m.Size()
msgSize := humanize.Bytes(uint64(msgSizeVal))
receivedBytes.WithLabelValues(from).Add(float64(msgSizeVal))

if m.Type != raftpb.MsgSnap {
plog.Errorf("unexpected raft message type %s on snapshot path", m.Type)
Expand All @@ -207,7 +210,7 @@ func (h *snapshotHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
defer func() {
snapshotReceiveInflights.WithLabelValues(from).Dec()
}()
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.
n, err := h.snapshotter.SaveDBFrom(r.Body, m.Snapshot.Metadata.Index)
if err != nil {
Expand All @@ -217,8 +220,10 @@ func (h *snapshotHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
snapshotReceiveFailures.WithLabelValues(from).Inc()
return
}

dbSize := humanize.Bytes(uint64(n))
receivedBytes.WithLabelValues(from).Add(float64(n))
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 {
switch v := err.(type) {
Expand Down
5 changes: 4 additions & 1 deletion rafthttp/snapshot_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/coreos/etcd/pkg/types"
"github.com/coreos/etcd/raft"
"github.com/coreos/etcd/snap"
"github.com/dustin/go-humanize"
)

var (
Expand Down Expand Up @@ -75,7 +76,9 @@ 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)

plog.Infof("start to send database snapshot [index: %d, to %s]...", m.Snapshot.Metadata.Index, types.ID(m.To))
snapshotTotalSizeVal := uint64(merged.TotalSize)
snapshotTotalSize := humanize.Bytes(snapshotTotalSizeVal)
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()
defer func() {
snapshotSendInflights.WithLabelValues(to).Dec()
Expand Down

0 comments on commit 6723145

Please sign in to comment.