From 3dc73a6c9898683f4150fb0417b0e217035463a2 Mon Sep 17 00:00:00 2001 From: jm96441n Date: Mon, 23 Jan 2023 15:24:33 -0500 Subject: [PATCH] Add reset command for envoy proxy log command Move format parsing into envoy package Move enovy to common package, move param parsing to calling package Added changelog for proxy log command Cleaning up usage message and error message from pr review clean up issue with exported constant used in test, fmt'd/linted export loggers undo autoformatting last fix to changelog to clean up from auto format set level on reset for envoy log level to info Fix spelling mistake in changelog --- CHANGELOG.md | 3 +++ cli/cmd/proxy/loglevel/command.go | 17 +++++++++++++++++ cli/common/envoy/http_test.go | 4 ++-- cli/common/envoy/logger_params.go | 4 ++-- 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4aecdf96d0..31014df601 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,9 @@ IMPROVEMENTS: * Add support for the annotation `consul.hashicorp.com/use-proxy-health-check`. When this annotation is used by a service, it configures a readiness endpoint on Consul Dataplane and queries it instead of the proxy's inbound port which forwards requests to the application. [[GH-1824](https://github.com/hashicorp/consul-k8s/pull/1824)], [[GH-1841](https://github.com/hashicorp/consul-k8s/pull/1841)] * Add health check for synced services based on the status of the Kubernetes readiness probe on synced pod. [[GH-1821](https://github.com/hashicorp/consul-k8s/pull/1821)] * Remove extraneous `gnupg` dependency from `consul-k8s-control-plane` since it is no longer needed for validating binary artifacts prior to release. [[GH-1882](https://github.com/hashicorp/consul-k8s/pull/1882)] +* CLI: + * Add `consul-k8s proxy log podname` command for displaying and modifying Envoy log levels for a given Pod. [GH-1844](https://github.com/hashicorp/consul-k8s/pull/1844), [GH-1849](https://github.com/hashicorp/consul-k8s/pull/1849), [GH-1864](https://github.com/hashicorp/consul-k8s/pull/1864) + BUG FIXES: * Control Plane diff --git a/cli/cmd/proxy/loglevel/command.go b/cli/cmd/proxy/loglevel/command.go index 85dc91bfa2..4355997ed3 100644 --- a/cli/cmd/proxy/loglevel/command.go +++ b/cli/cmd/proxy/loglevel/command.go @@ -24,6 +24,7 @@ const ( defaultAdminPort = 19000 flagNameNamespace = "namespace" flagNameUpdateLevel = "update-level" + flagNameReset = "reset" flagNameKubeConfig = "kubeconfig" flagNameKubeContext = "context" ) @@ -52,6 +53,7 @@ type LogLevelCommand struct { podName string namespace string level string + reset bool kubeConfig string kubeContext string @@ -79,6 +81,13 @@ func (l *LogLevelCommand) init() { Aliases: []string{"u"}, }) + f.BoolVar(&flag.BoolVar{ + Name: flagNameReset, + Target: &l.reset, + Usage: "Reset the log level for all loggers in a pod to the Envoy default (info).", + Aliases: []string{"r"}, + }) + f = l.set.NewSet("Global Options") f.StringVar(&flag.StringVar{ Name: flagNameKubeConfig, @@ -108,6 +117,11 @@ func (l *LogLevelCommand) Run(args []string) int { return l.logOutputAndDie(err) } + // if we're resetting the default log level for envoy is info: https://www.envoyproxy.io/docs/envoy/latest/start/quick-start/run-envoy#debugging-envoy + if l.reset { + l.level = "info" + } + if l.envoyLoggingCaller == nil { l.envoyLoggingCaller = envoy.CallLoggingEndpoint } @@ -160,6 +174,9 @@ func (l *LogLevelCommand) parseFlags(args []string) error { } func (l *LogLevelCommand) validateFlags() error { + if l.level != "" && l.reset { + return fmt.Errorf("cannot set log level to %q and reset to 'info' at the same time", l.level) + } if l.namespace == "" { return nil } diff --git a/cli/common/envoy/http_test.go b/cli/common/envoy/http_test.go index 2f10e10a2f..291eb2c22b 100644 --- a/cli/common/envoy/http_test.go +++ b/cli/common/envoy/http_test.go @@ -527,8 +527,8 @@ func (m *mockPortForwarder) Open(ctx context.Context) (string, error) { return m func (m *mockPortForwarder) Close() {} func testLogConfig() map[string]string { - cfg := make(map[string]string, len(envoyLoggers)) - for k := range envoyLoggers { + cfg := make(map[string]string, len(EnvoyLoggers)) + for k := range EnvoyLoggers { cfg[k] = "debug" } return cfg diff --git a/cli/common/envoy/logger_params.go b/cli/common/envoy/logger_params.go index 346ac19478..b2eff623c0 100644 --- a/cli/common/envoy/logger_params.go +++ b/cli/common/envoy/logger_params.go @@ -56,7 +56,7 @@ func validateLogLevel(level string) error { } func validateLoggerName(name string) error { - if _, ok := envoyLoggers[name]; !ok { + if _, ok := EnvoyLoggers[name]; !ok { loggers := []string{} for loggerName := range envoyLevels { loggers = append(loggers, loggerName) @@ -105,7 +105,7 @@ var envoyLevels = map[string]struct{}{ "off": {}, } -var envoyLoggers = map[string]struct{}{ +var EnvoyLoggers = map[string]struct{}{ "admin": {}, "alternate_protocols_cache": {}, "aws": {},