Add a flag for enabling debug logs to the `connect envoy` command (#15988)
* Add a flag for enabling debug logs to the `connect envoy` command * Update website/content/commands/connect/envoy.mdx Co-authored-by: Jeff Boruszak <104028618+boruszak@users.noreply.github.com> * Add changelog note * Add debug log note to envoy proxy doc page * Update website/content/docs/connect/proxies/envoy.mdx Co-authored-by: Kendall Strautman <36613477+kendallstrautman@users.noreply.github.com> * Wording tweak in envoy bootstrap section --------- Co-authored-by: Jeff Boruszak <104028618+boruszak@users.noreply.github.com> Co-authored-by: Kendall Strautman <36613477+kendallstrautman@users.noreply.github.com>
This commit is contained in:
parent
5572f1584d
commit
3febfa2e5d
|
@ -0,0 +1,3 @@
|
||||||
|
```release-note:improvements
|
||||||
|
cli: Added a flag, `-enable-config-gen-logging`, to the `connect envoy` command to display log messages when generating the bootstrap config.
|
||||||
|
```
|
|
@ -11,6 +11,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/hashicorp/go-hclog"
|
||||||
"github.com/hashicorp/go-version"
|
"github.com/hashicorp/go-version"
|
||||||
"github.com/mitchellh/cli"
|
"github.com/mitchellh/cli"
|
||||||
"github.com/mitchellh/mapstructure"
|
"github.com/mitchellh/mapstructure"
|
||||||
|
@ -42,6 +43,7 @@ type cmd struct {
|
||||||
http *flags.HTTPFlags
|
http *flags.HTTPFlags
|
||||||
help string
|
help string
|
||||||
client *api.Client
|
client *api.Client
|
||||||
|
logger hclog.Logger
|
||||||
|
|
||||||
// flags
|
// flags
|
||||||
meshGateway bool
|
meshGateway bool
|
||||||
|
@ -65,6 +67,7 @@ type cmd struct {
|
||||||
prometheusCertFile string
|
prometheusCertFile string
|
||||||
prometheusKeyFile string
|
prometheusKeyFile string
|
||||||
ignoreEnvoyCompatibility bool
|
ignoreEnvoyCompatibility bool
|
||||||
|
enableLogging bool
|
||||||
|
|
||||||
// mesh gateway registration information
|
// mesh gateway registration information
|
||||||
register bool
|
register bool
|
||||||
|
@ -221,6 +224,9 @@ func (c *cmd) init() {
|
||||||
"flag to `false` to ensure compatibility with Envoy and prevent potential issues. "+
|
"flag to `false` to ensure compatibility with Envoy and prevent potential issues. "+
|
||||||
"Default is `false`.")
|
"Default is `false`.")
|
||||||
|
|
||||||
|
c.flags.BoolVar(&c.enableLogging, "enable-config-gen-logging", false,
|
||||||
|
"Output debug log messages during config generation")
|
||||||
|
|
||||||
c.http = &flags.HTTPFlags{}
|
c.http = &flags.HTTPFlags{}
|
||||||
flags.Merge(c.flags, c.http.ClientFlags())
|
flags.Merge(c.flags, c.http.ClientFlags())
|
||||||
flags.Merge(c.flags, c.http.MultiTenancyFlags())
|
flags.Merge(c.flags, c.http.MultiTenancyFlags())
|
||||||
|
@ -229,6 +235,12 @@ func (c *cmd) init() {
|
||||||
c.dialFunc = func(network string, address string) (net.Conn, error) {
|
c.dialFunc = func(network string, address string) (net.Conn, error) {
|
||||||
return net.DialTimeout(network, address, 3*time.Second)
|
return net.DialTimeout(network, address, 3*time.Second)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
opts := hclog.LoggerOptions{Level: hclog.Off}
|
||||||
|
if c.enableLogging {
|
||||||
|
opts.Level = hclog.Debug
|
||||||
|
}
|
||||||
|
c.logger = hclog.New(&opts)
|
||||||
}
|
}
|
||||||
|
|
||||||
// canBindInternal is here mainly so we can unit test this with a constant net.Addr list
|
// canBindInternal is here mainly so we can unit test this with a constant net.Addr list
|
||||||
|
@ -281,6 +293,8 @@ func (c *cmd) Run(args []string) int {
|
||||||
c.UI.Error(fmt.Sprintf("Error connecting to Consul agent: %s", err))
|
c.UI.Error(fmt.Sprintf("Error connecting to Consul agent: %s", err))
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
c.logger.Debug("Initialized API client")
|
||||||
|
|
||||||
// TODO: refactor
|
// TODO: refactor
|
||||||
return c.run(c.flags.Args())
|
return c.run(c.flags.Args())
|
||||||
}
|
}
|
||||||
|
@ -350,6 +364,7 @@ func (c *cmd) run(args []string) int {
|
||||||
c.proxyID = c.gatewaySvcName
|
c.proxyID = c.gatewaySvcName
|
||||||
|
|
||||||
}
|
}
|
||||||
|
c.logger.Debug("Set Proxy ID", "proxy-id", c.proxyID)
|
||||||
}
|
}
|
||||||
if c.proxyID == "" {
|
if c.proxyID == "" {
|
||||||
c.UI.Error("No proxy ID specified. One of -proxy-id, -sidecar-for, or -gateway is " +
|
c.UI.Error("No proxy ID specified. One of -proxy-id, -sidecar-for, or -gateway is " +
|
||||||
|
@ -443,6 +458,7 @@ func (c *cmd) run(args []string) int {
|
||||||
c.UI.Error(fmt.Sprintf("Error registering service %q: %s", svc.Name, err))
|
c.UI.Error(fmt.Sprintf("Error registering service %q: %s", svc.Name, err))
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
c.logger.Debug("Proxy registration complete")
|
||||||
|
|
||||||
if !c.bootstrap {
|
if !c.bootstrap {
|
||||||
// We need stdout to be reserved exclusively for the JSON blob, so
|
// We need stdout to be reserved exclusively for the JSON blob, so
|
||||||
|
@ -457,6 +473,7 @@ func (c *cmd) run(args []string) int {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate config
|
// Generate config
|
||||||
|
c.logger.Debug("Generating bootstrap config")
|
||||||
bootstrapJson, err := c.generateConfig()
|
bootstrapJson, err := c.generateConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.UI.Error(err.Error())
|
c.UI.Error(err.Error())
|
||||||
|
@ -465,11 +482,13 @@ func (c *cmd) run(args []string) int {
|
||||||
|
|
||||||
if c.bootstrap {
|
if c.bootstrap {
|
||||||
// Just output it and we are done
|
// Just output it and we are done
|
||||||
|
c.logger.Debug("Outputting bootstrap config")
|
||||||
c.UI.Output(string(bootstrapJson))
|
c.UI.Output(string(bootstrapJson))
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find Envoy binary
|
// Find Envoy binary
|
||||||
|
c.logger.Debug("Finding envoy binary")
|
||||||
binary, err := c.findBinary()
|
binary, err := c.findBinary()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.UI.Error("Couldn't find envoy binary: " + err.Error())
|
c.UI.Error("Couldn't find envoy binary: " + err.Error())
|
||||||
|
@ -497,6 +516,7 @@ func (c *cmd) run(args []string) int {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c.logger.Debug("Executing envoy binary")
|
||||||
err = execEnvoy(binary, nil, args, bootstrapJson)
|
err = execEnvoy(binary, nil, args, bootstrapJson)
|
||||||
if err == errUnsupportedOS {
|
if err == errUnsupportedOS {
|
||||||
c.UI.Error("Directly running Envoy is only supported on linux and macOS " +
|
c.UI.Error("Directly running Envoy is only supported on linux and macOS " +
|
||||||
|
@ -618,6 +638,7 @@ func (c *cmd) generateConfig() ([]byte, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
c.logger.Debug("Generated template args")
|
||||||
|
|
||||||
var bsCfg BootstrapConfig
|
var bsCfg BootstrapConfig
|
||||||
|
|
||||||
|
@ -665,6 +686,7 @@ func (c *cmd) generateConfig() ([]byte, error) {
|
||||||
datacenter = svcList.Node.Datacenter
|
datacenter = svcList.Node.Datacenter
|
||||||
c.gatewayKind = svcList.Services[0].Kind
|
c.gatewayKind = svcList.Services[0].Kind
|
||||||
}
|
}
|
||||||
|
c.logger.Debug("Fetched registration info")
|
||||||
if svcProxyConfig == nil {
|
if svcProxyConfig == nil {
|
||||||
return nil, errors.New("service is not a Connect proxy or gateway")
|
return nil, errors.New("service is not a Connect proxy or gateway")
|
||||||
}
|
}
|
||||||
|
@ -700,6 +722,7 @@ func (c *cmd) generateConfig() ([]byte, error) {
|
||||||
if err := generateAccessLogs(c, args); err != nil {
|
if err := generateAccessLogs(c, args); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
c.logger.Debug("Generated access logs")
|
||||||
|
|
||||||
// Setup ready listener for ingress gateway to pass healthcheck
|
// Setup ready listener for ingress gateway to pass healthcheck
|
||||||
if c.gatewayKind == api.ServiceKindIngressGateway {
|
if c.gatewayKind == api.ServiceKindIngressGateway {
|
||||||
|
|
|
@ -126,6 +126,8 @@ compatibility with Envoy and prevent potential issues. Default is `false`.
|
||||||
always specifies `--config-file` and `--v2-config-only` and by default passes
|
always specifies `--config-file` and `--v2-config-only` and by default passes
|
||||||
`--disable-hot-restart` see [hot restart](#envoy-hot-restart).
|
`--disable-hot-restart` see [hot restart](#envoy-hot-restart).
|
||||||
|
|
||||||
|
- `-enable-config-gen-logging` - This flag enables debug message logging when generating the Envoy bootstrap configuration to help troubleshoot issues. Logs output to `stderr`. For more information about generating the Envoy bootstrap configuration, refer to [Envoy proxy configuration](/consul/docs/connect/proxies/envoy#bootstrap-configuration).
|
||||||
|
|
||||||
#### Envoy Sidecar Proxy Options
|
#### Envoy Sidecar Proxy Options
|
||||||
|
|
||||||
- `-sidecar-for` - The _ID_ (not name if they differ) of the service instance
|
- `-sidecar-for` - The _ID_ (not name if they differ) of the service instance
|
||||||
|
|
|
@ -124,6 +124,12 @@ Envoy requires an initial bootstrap configuration file. You can either create th
|
||||||
|
|
||||||
Connect to a local Consul client agent and run the [`consul connect envoy` command](/consul/commands/connect/envoy) to create the Envoy bootstrap configuration. The command either outputs the bootstrap configuration directly to stdout or generates the configuration and issues an `exec` command to the Envoy binary as a convenience wrapper. For more information about using `exec` to bootstrap Envoy, refer to [Exec Security Details](/consul/commands/connect/envoy#exec-security-details).
|
Connect to a local Consul client agent and run the [`consul connect envoy` command](/consul/commands/connect/envoy) to create the Envoy bootstrap configuration. The command either outputs the bootstrap configuration directly to stdout or generates the configuration and issues an `exec` command to the Envoy binary as a convenience wrapper. For more information about using `exec` to bootstrap Envoy, refer to [Exec Security Details](/consul/commands/connect/envoy#exec-security-details).
|
||||||
|
|
||||||
|
If you experience issues when bootstrapping Envoy proxies from the CLI, use the
|
||||||
|
`-enable-config-gen-logging` flag to enable debug message logging. These logs can
|
||||||
|
help you troubleshoot issues that occur during the bootstrapping process.
|
||||||
|
For more information about available flags and parameters, refer to the
|
||||||
|
[`consul connect envoy CLI` reference](/consul/commands/connect/envoy).
|
||||||
|
|
||||||
### Generate the bootstrap file from Consul Dataplane
|
### Generate the bootstrap file from Consul Dataplane
|
||||||
|
|
||||||
Consul Dataplane automatically configures and manages an Envoy process. Consul Dataplane generates the Envoy bootstrap configuration file prior to starting Envoy. To configure how Consul Dataplane starts Envoy, refer to the [Consul Dataplane CLI reference](/consul/docs/connect/dataplane/consul-dataplane).
|
Consul Dataplane automatically configures and manages an Envoy process. Consul Dataplane generates the Envoy bootstrap configuration file prior to starting Envoy. To configure how Consul Dataplane starts Envoy, refer to the [Consul Dataplane CLI reference](/consul/docs/connect/dataplane/consul-dataplane).
|
||||||
|
@ -1098,4 +1104,4 @@ warning.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
</CodeTabs>
|
</CodeTabs>
|
||||||
|
|
Loading…
Reference in New Issue