Skip to content

Commit

Permalink
add more details to stats command
Browse files Browse the repository at this point in the history
  • Loading branch information
nvanthao committed Nov 21, 2022
1 parent 51d4729 commit 8e0f4e6
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,32 @@ CoordinateUpdate: 173
Register: 10
ConnectCA: 5
SystemMetadata: 2
Intention: 1
FederationState: 1
Tombstone: 1
Autopilot: 1
Intention: 1
=== LATEST CLUSTER MEMBERS ===
LogConfiguration Index: 1
{[{Voter 4cb93543-77d4-9a2c-8aed-6a900f45218f 172.22.0.4:8300} {Voter da94ef35-9378-9c35-8a3b-9cbfc390682e 172.22.0.5:8300} {Voter 9ff413b5-57c1-f610-8e15-fafe5a87c166 172.22.0.2:8300}]}
=== LATEST AUTOPILOT CONFIG ===
Autopilot Index: 4
{
"CAS": false,
"Config": {
"CleanupDeadServers": true,
"CreateIndex": 0,
"DisableUpgradeMigration": false,
"LastContactThreshold": 200000000,
"MaxTrailingLogs": 250,
"MinQuorum": 0,
"ModifyIndex": 0,
"RedundancyZoneTag": "",
"ServerStabilizationTime": 10000000000,
"UpgradeVersionTag": ""
},
"Datacenter": "",
"Token": ""
}
```

## Run with Docker
Expand Down
46 changes: 46 additions & 0 deletions app/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ func (s *Store) Stats() {
for _, s := range ss {
fmt.Printf("%s: %d \n", s.Key, s.Value)
}

fmt.Println("=== LATEST CLUSTER MEMBERS ===")
s.printLatestLogConfiguration(logs)

fmt.Println("=== LATEST AUTOPILOT CONFIG ===")
s.printAutopilotConfiguration(logs)
}

func NewStore(file string) (*Store, error) {
Expand Down Expand Up @@ -202,3 +208,43 @@ func sortMapByValue(m map[string]int) []kv {

return ss
}

func (s *Store) printLatestLogConfiguration(logs []RaftLog) {
var latestIndex uint64
for _, log := range logs {
if log.Type == "LogConfiguration" {
if log.Index > latestIndex {
latestIndex = log.Index
}
}
}
if latestIndex != 0 {
var log raft.Log
err := s.store.GetLog(latestIndex, &log)
if err != nil {
return
}
fmt.Printf("LogConfiguration Index: %d \n", latestIndex)
fmt.Println(raft.DecodeConfiguration(log.Data))
}
}

func (s *Store) printAutopilotConfiguration(logs []RaftLog) {
var latestIndex uint64
for _, log := range logs {
if log.Type == "LogCommand" && log.MsgType == "Autopilot" {
if log.Index > latestIndex {
latestIndex = log.Index
}
}
}
if latestIndex != 0 {
var log raft.Log
err := s.store.GetLog(latestIndex, &log)
if err != nil {
return
}
fmt.Printf("Autopilot Index: %d \n", latestIndex)
fmt.Println(getLogCommand(log.Data))
}
}

0 comments on commit 8e0f4e6

Please sign in to comment.