update troubleshoot CLI (#16129)

This commit is contained in:
malizz 2023-02-01 15:11:05 -08:00 committed by GitHub
parent 284cf5f062
commit 1477cf5a82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 75 additions and 16 deletions

View File

@ -116,8 +116,9 @@ import (
tlscacreate "github.com/hashicorp/consul/command/tls/ca/create" tlscacreate "github.com/hashicorp/consul/command/tls/ca/create"
tlscert "github.com/hashicorp/consul/command/tls/cert" tlscert "github.com/hashicorp/consul/command/tls/cert"
tlscertcreate "github.com/hashicorp/consul/command/tls/cert/create" tlscertcreate "github.com/hashicorp/consul/command/tls/cert/create"
troubleshoot "github.com/hashicorp/consul/command/troubleshoot/connect" troubleshoot "github.com/hashicorp/consul/command/troubleshoot"
upstreams "github.com/hashicorp/consul/command/troubleshoot/upstreams" troubleshootproxy "github.com/hashicorp/consul/command/troubleshoot/proxy"
troubleshootupstreams "github.com/hashicorp/consul/command/troubleshoot/upstreams"
"github.com/hashicorp/consul/command/validate" "github.com/hashicorp/consul/command/validate"
"github.com/hashicorp/consul/command/version" "github.com/hashicorp/consul/command/version"
"github.com/hashicorp/consul/command/watch" "github.com/hashicorp/consul/command/watch"
@ -242,8 +243,9 @@ func RegisteredCommands(ui cli.Ui) map[string]mcli.CommandFactory {
entry{"tls ca create", func(ui cli.Ui) (cli.Command, error) { return tlscacreate.New(ui), nil }}, entry{"tls ca create", func(ui cli.Ui) (cli.Command, error) { return tlscacreate.New(ui), nil }},
entry{"tls cert", func(ui cli.Ui) (cli.Command, error) { return tlscert.New(), nil }}, entry{"tls cert", func(ui cli.Ui) (cli.Command, error) { return tlscert.New(), nil }},
entry{"tls cert create", func(ui cli.Ui) (cli.Command, error) { return tlscertcreate.New(ui), nil }}, entry{"tls cert create", func(ui cli.Ui) (cli.Command, error) { return tlscertcreate.New(ui), nil }},
entry{"troubleshoot connect", func(ui cli.Ui) (cli.Command, error) { return troubleshoot.New(ui), nil }}, entry{"troubleshoot", func(ui cli.Ui) (cli.Command, error) { return troubleshoot.New(), nil }},
entry{"troubleshoot upstreams", func(ui cli.Ui) (cli.Command, error) { return upstreams.New(ui), nil }}, entry{"troubleshoot proxy", func(ui cli.Ui) (cli.Command, error) { return troubleshootproxy.New(ui), nil }},
entry{"troubleshoot upstreams", func(ui cli.Ui) (cli.Command, error) { return troubleshootupstreams.New(ui), nil }},
entry{"validate", func(ui cli.Ui) (cli.Command, error) { return validate.New(ui), nil }}, entry{"validate", func(ui cli.Ui) (cli.Command, error) { return validate.New(ui), nil }},
entry{"version", func(ui cli.Ui) (cli.Command, error) { return version.New(ui), nil }}, entry{"version", func(ui cli.Ui) (cli.Command, error) { return version.New(ui), nil }},
entry{"watch", func(ui cli.Ui) (cli.Command, error) { return watch.New(ui, MakeShutdownCh()), nil }}, entry{"watch", func(ui cli.Ui) (cli.Command, error) { return watch.New(ui, MakeShutdownCh()), nil }},

View File

@ -1,4 +1,4 @@
package troubleshoot package proxy
import ( import (
"flag" "flag"
@ -7,7 +7,7 @@ import (
"os" "os"
"github.com/hashicorp/consul/command/flags" "github.com/hashicorp/consul/command/flags"
troubleshoot "github.com/hashicorp/consul/troubleshoot/connect" troubleshoot "github.com/hashicorp/consul/troubleshoot"
"github.com/mitchellh/cli" "github.com/mitchellh/cli"
) )
@ -31,7 +31,7 @@ type cmd struct {
func (c *cmd) init() { func (c *cmd) init() {
c.flags = flag.NewFlagSet("", flag.ContinueOnError) c.flags = flag.NewFlagSet("", flag.ContinueOnError)
c.flags.StringVar(&c.upstream, "upstream", os.Getenv("TROUBLESHOOT_CONNECT_UPSTREAM"), "The upstream service that receives the communication. ") c.flags.StringVar(&c.upstream, "upstream", os.Getenv("TROUBLESHOOT_UPSTREAM"), "The upstream service that receives the communication. ")
defaultAdminBind := "localhost:19000" defaultAdminBind := "localhost:19000"
if adminBind := os.Getenv("ADMIN_BIND"); adminBind != "" { if adminBind := os.Getenv("ADMIN_BIND"); adminBind != "" {
@ -53,7 +53,7 @@ func (c *cmd) Run(args []string) int {
} }
if c.upstream == "" { if c.upstream == "" {
c.UI.Error("-upstream service SNI is required") c.UI.Error("-upstream envoy identifier is required")
return 1 return 1
} }
@ -94,11 +94,11 @@ func (c *cmd) Help() string {
} }
const ( const (
synopsis = "Troubleshoots service mesh issues" synopsis = "Troubleshoots service mesh issues from the current envoy instance"
help = ` help = `
Usage: consul troubleshoot proxy [options] Usage: consul troubleshoot proxy [options]
Connects to local envoy proxy and troubleshoots service mesh communication issues. Connects to local envoy proxy and troubleshoots service mesh communication issues.
Requires an upstream service SNI. Requires an upstream service envoy identifier.
Examples: Examples:
$ consul troubleshoot proxy -upstream foo $ consul troubleshoot proxy -upstream foo

View File

@ -1,4 +1,4 @@
package troubleshoot package proxy
import ( import (
"strings" "strings"
@ -7,7 +7,7 @@ import (
"github.com/mitchellh/cli" "github.com/mitchellh/cli"
) )
func TestTroubleshootConnectCommand_noTabs(t *testing.T) { func TestTroubleshootProxyCommand_noTabs(t *testing.T) {
t.Parallel() t.Parallel()
if strings.ContainsRune(New(cli.NewMockUi()).Help(), '\t') { if strings.ContainsRune(New(cli.NewMockUi()).Help(), '\t') {

View File

@ -0,0 +1,44 @@
package troubleshoot
import (
"github.com/hashicorp/consul/command/flags"
"github.com/mitchellh/cli"
)
func New() *cmd {
return &cmd{}
}
type cmd struct{}
func (c *cmd) Run(args []string) int {
return cli.RunResultHelp
}
func (c *cmd) Synopsis() string {
return synopsis
}
func (c *cmd) Help() string {
return flags.Usage(help, nil)
}
const synopsis = `CLI tools for troubleshooting Consul service mesh`
const help = `
Usage: consul troubleshoot <subcommand> [options]
This command has subcommands for troubleshooting the service mesh.
Here are some simple examples, and more detailed examples are available
in the subcommands or the documentation.
Troubleshoot Get Upstreams
$ consul troubleshoot upstreams
Troubleshoot Proxy
$ consul troubleshoot proxy -upstream [options]
For more examples, ask for subcommand help or view the documentation.
`

View File

@ -0,0 +1,13 @@
package troubleshoot
import (
"strings"
"testing"
)
func TestTroubleshootCommand_noTabs(t *testing.T) {
t.Parallel()
if strings.ContainsRune(New().Help(), '\t') {
t.Fatal("help has tabs")
}
}

View File

@ -7,7 +7,7 @@ import (
"os" "os"
"github.com/hashicorp/consul/command/flags" "github.com/hashicorp/consul/command/flags"
troubleshoot "github.com/hashicorp/consul/troubleshoot/connect" troubleshoot "github.com/hashicorp/consul/troubleshoot"
"github.com/mitchellh/cli" "github.com/mitchellh/cli"
) )
@ -89,13 +89,13 @@ func (c *cmd) Help() string {
} }
const ( const (
synopsis = "Troubleshoots service mesh issues" synopsis = "Get upstream envoy identifiers for the current envoy instance"
help = ` help = `
Usage: consul troubleshoot upstreams [options] Usage: consul troubleshoot upstreams [options]
Connects to local Envoy and lists upstream service envoy IDs. Connects to local Envoy and lists upstream service envoy identifiers.
This command is used in combination with This command is used in combination with
'consul troubleshoot connect' to diagnose issues in Consul service mesh. 'consul troubleshoot proxy' to diagnose issues in Consul service mesh.
Examples: Examples:
$ consul troubleshoot upstreams $ consul troubleshoot upstreams
` `