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
client-go: export NewDebuggingRoundTripper function and DebugLevel #98324
client-go: export NewDebuggingRoundTripper function and DebugLevel #98324
Conversation
`debuggingRoundTripper` is a useful throbleshooting tool to debug of Kubernetes API requests and their timing. Unfortunately, as of today, it can only be used via the `DebugWrappers` function, which automatically adjust the amount of debug information exposed by the roundTripper based on the configured `klog` verbosity. While `DebugWrappers` definitely fits the purpose for clients using `klog`, this is currently hard to be used for controllers using `controller-runtime`, which uses `github.com/go-logr/logr` for logging. In this PR we change the visibility of `newDebuggingRoundTripper` and `debugLevel` in order to be directly accessible from users of the `k8s.io/client-go/transport` package. In particular, the changes proposed in this PR allow users of `controller-runtime` to use the `debuggingRoundTripper` to intercept Kubernetes API requests as follows ```go import ( ctrl "sigs.k8s.io/controller-runtime" ) func init() { ctrl.SetLogger(zap.New()) } func main() { // wrap the http transport used by the Kubernetes client restConfig, err := ctrl.GetConfig() checkError(setupLog, err, "unable to get kubernetes client config") restConfig.Wrap(func(rt http.RoundTripper) http.RoundTripper { return transport.NewDebuggingRoundTripper(rt, transport.DebugJustURL) }) ... } ```
Hi @atosatto. Thanks for your PR. I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
cc @lavalamp |
@lavalamp adding here some more information on my PR. Currently, the one way we can build a // DebugWrappers wraps a round tripper and logs based on the current log level.
func DebugWrappers(rt http.RoundTripper) http.RoundTripper {
switch {
case bool(klog.V(9).Enabled()):
rt = newDebuggingRoundTripper(rt, debugCurlCommand, debugURLTiming, debugResponseHeaders)
case bool(klog.V(8).Enabled()):
rt = newDebuggingRoundTripper(rt, debugJustURL, debugRequestHeaders, debugResponseStatus, debugResponseHeaders)
case bool(klog.V(7).Enabled()):
rt = newDebuggingRoundTripper(rt, debugJustURL, debugRequestHeaders, debugResponseStatus)
case bool(klog.V(6).Enabled()):
rt = newDebuggingRoundTripper(rt, debugURLTiming)
}
return rt
} Unfortunately this is relying on In this PR I am proposing to change the visibility of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'm pretty OK with this since it is just making something public. But did we consider letting the user also pass a log alternative in? So it doesn't have to use the global one? I guess that could be a separate change if we wanted to do that.
I did but I am afraid this would be a bigger change (perhaps with more contention) as it would require us to switch to the I am happy to give it a try in a separated PR as this would definitely help in the scenario where the API is used in |
OK. Let's just take this and wait for the structured logging folks to work their way through the system. /lgtm |
/ok-to-test |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: atosatto, lavalamp The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/test pull-kubernetes-e2e-kind-ipv6 |
@lavalamp it looks like the PR is now passing all the tests. Would you mind checking again whether it is good to be merged? Thanks! |
/triage accepted |
/lgtm |
What type of PR is this?
/kind feature
What this PR does / why we need it:
debuggingRoundTripper
is a useful tool to debug Kubernetes API requests and their timing.Unfortunately it can only be used via the
DebugWrappers
function, which adjusts the level of debugging information logged by the roundTripper based on the configuredklog
verbosity.While
DebugWrappers
definitely works for clients usingklog
(likekubectl
), this is currently hard to be used from controllers usingcontroller-runtime
, as by default the library usesgithub.com/go-logr/logr
for logging.In this PR we change the visibility of
newDebuggingRoundTripper
anddebugLevel
in order to be able to use directly thedebugRoundTripper
without theDebugWrappers
function.In particular, the changes proposed in this PR allow to use the
debuggingRoundTripper
to intercept Kubernetes API requests performed bycontroller-runtime
using the following sample codeDoes this PR introduce a user-facing change?: