Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli: unhide advanced operator raft debugging commands #11682

Merged
merged 1 commit into from
Dec 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/11682.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
cli: Made the `operator raft info`, `operator raft logs`, `operator raft state`, and `operator snapshot state` commands visible to command line help.
```
8 changes: 4 additions & 4 deletions command/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -535,17 +535,17 @@ func Commands(metaPtr *Meta, agentUi cli.Ui) map[string]cli.CommandFactory {
Meta: meta,
}, nil
},
"operator raft _info": func() (cli.Command, error) {
"operator raft info": func() (cli.Command, error) {
return &OperatorRaftInfoCommand{
Meta: meta,
}, nil
},
"operator raft _logs": func() (cli.Command, error) {
"operator raft logs": func() (cli.Command, error) {
return &OperatorRaftLogsCommand{
Meta: meta,
}, nil
},
"operator raft _state": func() (cli.Command, error) {
"operator raft state": func() (cli.Command, error) {
return &OperatorRaftStateCommand{
Meta: meta,
}, nil
Expand All @@ -566,7 +566,7 @@ func Commands(metaPtr *Meta, agentUi cli.Ui) map[string]cli.CommandFactory {
Meta: meta,
}, nil
},
"operator snapshot _state": func() (cli.Command, error) {
"operator snapshot state": func() (cli.Command, error) {
return &OperatorSnapshotStateCommand{
Meta: meta,
}, nil
Expand Down
15 changes: 15 additions & 0 deletions command/operator_raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,22 @@ Usage: nomad operator raft <subcommand> [options]

$ nomad operator raft remove-peer -peer-address "IP:Port"

Display info about the raft logs in the data directory:

$ nomad operator raft info /var/nomad/data

Display the log entries persisted in data dir in JSON format.

$ nomad operator raft logs /var/nomad/data

Display the server state obtained by replaying raft log entries
persisted in data dir in JSON format.

$ nomad operator raft state /var/nomad/data

Please see the individual subcommand help for detailed usage information.


`
return strings.TrimSpace(helpText)
}
Expand Down
12 changes: 7 additions & 5 deletions command/operator_raft_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ type OperatorRaftInfoCommand struct {

func (c *OperatorRaftInfoCommand) Help() string {
helpText := `
Usage: nomad operator raft _info <path to nomad data dir>
Usage: nomad operator raft info <path to nomad data dir>

Displays info about the raft logs in the data directory.
Displays summary information about the raft logs in the data directory.

This command requires file system permissions to access the data directory on
disk. The Nomad server locks access to the data directory, so this command
cannot be run on a data directory that is being used by a running Nomad server.

This is a low-level debugging tool and not subject to Nomad's usual backward
compatibility guarantees.

If ACLs are enabled, this command requires a management token.
`
return strings.TrimSpace(helpText)
}
Expand All @@ -38,7 +40,7 @@ func (c *OperatorRaftInfoCommand) Synopsis() string {
return "Display info of the raft log"
}

func (c *OperatorRaftInfoCommand) Name() string { return "operator raft _info" }
func (c *OperatorRaftInfoCommand) Name() string { return "operator raft info" }

func (c *OperatorRaftInfoCommand) Run(args []string) int {
if len(args) != 1 {
Expand Down
12 changes: 8 additions & 4 deletions command/operator_raft_logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,18 @@ type OperatorRaftLogsCommand struct {

func (c *OperatorRaftLogsCommand) Help() string {
helpText := `
Usage: nomad operator raft _logs <path to nomad data dir>
Usage: nomad operator raft logs <path to nomad data dir>

Display the log entries persisted in data dir in json form.
Display the log entries persisted in the Nomad data directory in JSON
format.

This command requires file system permissions to access the data directory on
disk. The Nomad server locks access to the data directory, so this command
cannot be run on a data directory that is being used by a running Nomad server.

This is a low-level debugging tool and not subject to Nomad's usual backward
compatibility guarantees.

If ACLs are enabled, this command requires a management token.
`
return strings.TrimSpace(helpText)
}
Expand All @@ -40,7 +44,7 @@ func (c *OperatorRaftLogsCommand) Synopsis() string {
return "Display raft log content"
}

func (c *OperatorRaftLogsCommand) Name() string { return "operator raft _info" }
func (c *OperatorRaftLogsCommand) Name() string { return "operator raft logs" }

func (c *OperatorRaftLogsCommand) Run(args []string) int {
if len(args) != 1 {
Expand Down
13 changes: 8 additions & 5 deletions command/operator_raft_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,18 @@ type OperatorRaftStateCommand struct {

func (c *OperatorRaftStateCommand) Help() string {
helpText := `
Usage: nomad operator raft _state <path to nomad data dir>
Usage: nomad operator raft state <path to nomad data dir>

Display the server state obtained by replaying raft log entries persisted in data dir in json form.
Display the server state obtained by replaying raft log entries persisted in
the Nomad data directory in JSON format.

This command requires file system permissions to access the data directory on
disk. The Nomad server locks access to the data directory, so this command
cannot be run on a data directory that is being used by a running Nomad server.

This is a low-level debugging tool and not subject to Nomad's usual backward
compatibility guarantees.

If ACLs are enabled, this command requires a management token.

Options:

-last-index=<last_index>
Expand All @@ -47,7 +50,7 @@ func (c *OperatorRaftStateCommand) Synopsis() string {
return "Display raft server state"
}

func (c *OperatorRaftStateCommand) Name() string { return "operator raft _state" }
func (c *OperatorRaftStateCommand) Name() string { return "operator raft state" }

func (c *OperatorRaftStateCommand) Run(args []string) int {
var fLastIdx int64
Expand Down
6 changes: 3 additions & 3 deletions command/operator_snapshot_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ type OperatorSnapshotStateCommand struct {

func (c *OperatorSnapshotStateCommand) Help() string {
helpText := `
Usage: nomad operator snapshot _state <file>
Usage: nomad operator snapshot state <file>

Displays a JSON representation of state in the snapshot.

To inspect the file "backup.snap":

$ nomad operator snapshot _state backup.snap
$ nomad operator snapshot state backup.snap
`
return strings.TrimSpace(helpText)
}
Expand All @@ -39,7 +39,7 @@ func (c *OperatorSnapshotStateCommand) Synopsis() string {
return "Displays information about a Nomad snapshot file"
}

func (c *OperatorSnapshotStateCommand) Name() string { return "operator snapshot _state" }
func (c *OperatorSnapshotStateCommand) Name() string { return "operator snapshot state" }

func (c *OperatorSnapshotStateCommand) Run(args []string) int {
// Check that we either got no filename or exactly one.
Expand Down
39 changes: 39 additions & 0 deletions website/content/docs/commands/operator/raft-info.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
layout: docs
page_title: 'Commands: operator raft info'
description: |
Display Raft server state.
---

# Command: operator raft info

The `raft info` command is used to display summary information about the
raft logs persisted in the Nomad [data directory].

This command requires file system permissions to access the data
directory on disk. The Nomad server locks access to the data
directory, so this command cannot be run on a data directory that is
being used by a running Nomad server.

~> **Warning:** This is a low-level debugging tool and not subject to
Nomad's usual backward compatibility guarantees.

## Usage

```plaintext
nomad operator raft info <path to data dir>
```

## Examples

An example output is as follows:

```shell-session
$ sudo nomad operator raft info /var/nomad/data
path: /var/nomad/data/server/raft/raft.db
length: 10
first index: 1
last index: 10
```

[data directory]: /docs/configuration#data_dir
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ description: |

# Command: operator raft list-peers

The Raft list-peers command is used to display the current Raft peer
The `raft list-peers` command is used to display the current Raft peer
configuration.

See the [Outage Recovery] guide for some examples of how this command is used.
Expand Down
38 changes: 38 additions & 0 deletions website/content/docs/commands/operator/raft-logs.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
layout: docs
page_title: 'Commands: operator raft logs'
description: |
Display Raft server state.
---

# Command: operator raft logs

The `raft logs` command is used to display the log entries persisted in
the Nomad [data directory] in JSON format.

This command requires file system permissions to access the data
directory on disk. The Nomad server locks access to the data
directory, so this command cannot be run on a data directory that is
being used by a running Nomad server.

~> **Warning:** This is a low-level debugging tool and not subject to
Nomad's usual backward compatibility guarantees.

## Usage

```plaintext
nomad operator raft logs [options] <path to data dir>
```

## Examples

The output of this command can be very large, so it's recommended that
you redirect the output to a file for later examination with other
tools.

```shell-session
$ sudo nomad operator raft logs /var/nomad/data > ~/raft-logs.json
$ jq . < ~/raft-logs.json
```

[data directory]: /docs/configuration#data_dir
46 changes: 46 additions & 0 deletions website/content/docs/commands/operator/raft-state.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
layout: docs
page_title: 'Commands: operator raft state'
description: |
Display Raft server state.
---

# Command: operator raft state

The `raft state` command is used to display the server state obtained by
replaying raft log entries persisted in the Nomad [data directory] in
JSON format.

This command requires file system permissions to access the data
directory on disk. The Nomad server locks access to the data
directory, so this command cannot be run on a data directory that is
being used by a running Nomad server.

~> **Warning:** This is a low-level debugging tool and not subject to
Nomad's usual backward compatibility guarantees.

## Usage

```plaintext
nomad operator raft state [options] <path to data dir>
```

## Raft State Options

- `-last-index=<last_index>`: Set the last log index to be applied, to
drop spurious log entries not properly committed. If the
`last_index` option is zero or negative, it's treated as an offset
from the last index seen in raft.

## Examples

The output of this command can be very large, so it's recommended that
you redirect the output to a file for later examination with other
tools.

```shell-session
$ sudo nomad operator raft state /var/nomad/data > ~/raft-state.json
$ jq . < ~/raft-state.json
```

[data directory]: /docs/configuration#data_dir
30 changes: 30 additions & 0 deletions website/content/docs/commands/operator/snapshot-state.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
layout: docs
page_title: 'Commands: operator snapshot state'
description: |
Displays a JSON representation of a Raft snapshot.
---

# Command: operator snapshot state

Displays a JSON representation of state in a raft snapshot on disk.

~> **Warning:** This is a low-level debugging tool and not subject to
Nomad's usual backward compatibility guarantees.

## Usage

```plaintext
nomad operator snapshot state <file>
```

## Examples

The output of this command can be very large, so it's recommended that
you redirect the output to a file for later examination with other
tools.

```shell-session
$ nomad operator snapshot state backup.snap > ~/raft-state.json
$ jq . < ~/raft-state.json
```
16 changes: 16 additions & 0 deletions website/data/docs-nav-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -535,14 +535,26 @@
"title": "metrics",
"path": "commands/operator/metrics"
},
{
"title": "raft info",
"path": "commands/operator/raft-info"
},
{
"title": "raft list-peers",
"path": "commands/operator/raft-list-peers"
},
{
"title": "raft logs",
"path": "commands/operator/raft-logs"
},
{
"title": "raft remove-peer",
"path": "commands/operator/raft-remove-peer"
},
{
"title": "raft state",
"path": "commands/operator/raft-state"
},
{
"title": "snapshot agent",
"path": "commands/operator/snapshot-agent"
Expand All @@ -558,6 +570,10 @@
{
"title": "snapshot save",
"path": "commands/operator/snapshot-save"
},
{
"title": "snapshot state",
"path": "commands/operator/snapshot-state"
}
]
},
Expand Down