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

Set envoy log level per pod #1849

Merged
merged 1 commit into from
Feb 13, 2023
Merged

Set envoy log level per pod #1849

merged 1 commit into from
Feb 13, 2023

Conversation

jm96441n
Copy link
Member

@jm96441n jm96441n commented Jan 23, 2023

Changes proposed in this PR:

  • Allow users to set the log level on the envoy proxy in a specified pod, they can either set the level for all loggers by calling consul-k8s proxy log POD_NAME -l warning, or on specific loggers by consul-k8s proxy log POD_NAME -l grpc:warning or consul-k8s proxy log POD_NAME -l grpc:warning,http:info
  • Small refactor to pull out an envoy package to encapsulate interactions with envoy

How I've tested this PR:

  • Unit tests
  • ran consul on k8's locally using kind https://gist.github.com/jm96441n/a56cd2ebd53f4484c3b40e725e305372
    • create a cluster using kind: kind create cluster
    • install consul on that cluster using the consul-values.yml file in the above gist: consul-k8s install -config-file=consul-values.yaml -set global.image=hashicorp/consul:1.14.3
    • once that is up apply the server.yaml to your cluster kubectl apply server.yaml
    • once that is setup get one of the server pod names using kubectl get pods
    • in another terminal window set up port forwarding for that pod kubectl port-forward <POD_NAME> 19000:19000 (where 19000 is the default admin port for the envoy proxy)
    • in the original terminal run consul-k8s proxy log <POD_NAME> -l warning and compare the output to the envoy admin interface which would be at localhost:19000/logging while port forwarding is enabled (rinse and repeat for other combinations of changing levels)

How I expect reviewers to test this PR:
code review
potentially running above steps (but probably not necessary)

NOTE: Didn't add a CHANGELOG yet, planning on adding the CHANGELOG entry once the work on the consul-k8s proxy log command is complete, though can add one for the current work if that's preferred (the next PR should be the last one to add reset functionality to put logs back to the default level for envoy)

Checklist:

  • Tests added
  • CHANGELOG entry added

    HashiCorp engineers only, community PRs should not add a changelog entry.
    Entries should use present tense (e.g. Add support for...)

@t-eckert t-eckert marked this pull request as draft January 23, 2023 21:32
// EnvoyConfig represents the configuration retrieved from a config dump at the
// admin endpoint. It wraps the Envoy ConfigDump struct to give us convenient
// access to the different sections of the config.
type EnvoyConfig struct {
rawCfg []byte
RawCfg []byte
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so this change and changing the tests to utilize the testdata directory rather than embedding are the only substantial changes here other than the move

@@ -222,7 +227,7 @@ func (l *LogLevelCommand) fetchAdminPorts() (map[string]int, error) {
return adminPorts, nil
}

func (l *LogLevelCommand) fetchLogLevels(adminPorts map[string]int) (map[string]LoggerConfig, error) {
func (l *LogLevelCommand) fetchOrSetLogLevels(adminPorts map[string]int) error {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so I also consolidated the calls to envoy into this function, because they were both the exact same code, I'd prefer to keep them separate so it reads better, but having the envoy API is kinda forcing my hand to keep this code from being completely duplicated

Base automatically changed from get-envoy-log-level-per-pod to main January 27, 2023 19:11
cli/common/envoy/http.go Outdated Show resolved Hide resolved
@jm96441n jm96441n changed the title DRAFT: Set envoy log level per pod Set envoy log level per pod Jan 31, 2023
@jm96441n jm96441n marked this pull request as ready for review January 31, 2023 17:21
Copy link
Contributor

@andrewstucki andrewstucki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, cursory pass and the code looks generally fine to me, but I guess I have a question/observation about the usability and/or flag naming conventions. It seems a bit confusing to me that what appears to be the "listing" log-level command also acts as double-duty for setting said log-levels.

If we're fine going with that approach, what do you think about making the flag name a bit more specific? Saying -level or -l means we don't really have any user-indication that they're actually doing some sort of "set" command. What about something like -update-level or -u?

cli/common/envoy/http.go Show resolved Hide resolved
@jm96441n
Copy link
Member Author

I like the idea of using -u/-update-level as opposed to just level, let me make that change

Copy link
Contributor

@andrewstucki andrewstucki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Move format parsing into envoy package

Move enovy to common package, move param parsing to calling package

use a LoggerParams struct for handling a format for log changes to envoy

refactor to use logger params and methods to set and validate logger and
log levels before calling envoy

linting changes

clean up from rebase

Improve comment on envoy logging endpoint function, switched to using
'-update-level' for updating envoy log level flag for better usability
@jm96441n jm96441n merged commit 9990aa7 into main Feb 13, 2023
@jm96441n jm96441n deleted the set-envoy-log-level-per-pod branch February 13, 2023 20:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants