etcd-dump-logs: Print full confState as json for debugging purposes.

This commit is contained in:
Piotr Tabor 2021-04-02 17:58:13 +02:00
parent 768da490ed
commit aa6597384b

View File

@ -18,6 +18,7 @@ import (
"bufio" "bufio"
"bytes" "bytes"
"encoding/hex" "encoding/hex"
"encoding/json"
"flag" "flag"
"fmt" "fmt"
"io" "io"
@ -88,8 +89,12 @@ and output a hex encoded line of binary for each input line`)
case nil: case nil:
walsnap.Index, walsnap.Term = snapshot.Metadata.Index, snapshot.Metadata.Term walsnap.Index, walsnap.Term = snapshot.Metadata.Index, snapshot.Metadata.Term
nodes := genIDSlice(snapshot.Metadata.ConfState.Voters) nodes := genIDSlice(snapshot.Metadata.ConfState.Voters)
fmt.Printf("Snapshot:\nterm=%d index=%d nodes=%s\n", confstateJson, err := json.Marshal(snapshot.Metadata.ConfState)
walsnap.Term, walsnap.Index, nodes) if err != nil {
confstateJson = []byte(fmt.Sprintf("confstate err: %v", err))
}
fmt.Printf("Snapshot:\nterm=%d index=%d nodes=%s confstate=%s\n",
walsnap.Term, walsnap.Index, nodes, confstateJson)
case snap.ErrNoSnapshot: case snap.ErrNoSnapshot:
fmt.Printf("Snapshot:\nempty\n") fmt.Printf("Snapshot:\nempty\n")
default: default: