query for leader in `operator debug` command (#13472)

The `operator debug` command doesn't output the leader anywhere in the
output, which adds extra burden to offline debugging (away from an
ongoing incident where you can simply check manually). Query the
`/v1/status/leader` API but degrade gracefully.
This commit is contained in:
Tim Gross 2022-07-06 10:57:44 -04:00 committed by GitHub
parent 07418877c6
commit 1fc8995590
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 0 deletions

3
.changelog/13472.txt Normal file
View File

@ -0,0 +1,3 @@
```release-note:improvement
cli: `operator debug` now outputs current leader to debug bundle
```

View File

@ -588,6 +588,18 @@ func (c *OperatorDebugCommand) Run(args []string) int {
// Write complete list of server members to file // Write complete list of server members to file
c.writeJSON(clusterDir, "members.json", c.members, err) c.writeJSON(clusterDir, "members.json", c.members, err)
// Get leader and write to file; there's no option for AllowStale
// on this API and a stale result wouldn't even be meaningful, so
// only warn if we fail so that we don't stop the rest of the
// debugging
leader, err := client.Status().Leader()
if err != nil {
c.Ui.Warn(fmt.Sprintf("Failed to retrieve leader; err: %v", err))
}
if len(leader) > 0 {
c.writeJSON(clusterDir, "leader.json", leader, err)
}
// Filter for servers matching criteria // Filter for servers matching criteria
c.serverIDs, err = filterServerMembers(c.members, serverIDs, c.region) c.serverIDs, err = filterServerMembers(c.members, serverIDs, c.region)
if err != nil { if err != nil {