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

DRAFT: Reset log levels per pod #1864

Merged
merged 1 commit into from
Feb 14, 2023
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.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions cli/cmd/proxy/loglevel/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const (
defaultAdminPort = 19000
flagNameNamespace = "namespace"
flagNameUpdateLevel = "update-level"
flagNameReset = "reset"
flagNameKubeConfig = "kubeconfig"
flagNameKubeContext = "context"
)
Expand Down Expand Up @@ -52,6 +53,7 @@ type LogLevelCommand struct {
podName string
namespace string
level string
reset bool
kubeConfig string
kubeContext string

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions cli/common/envoy/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions cli/common/envoy/logger_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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": {},
Expand Down