-
Notifications
You must be signed in to change notification settings - Fork 263
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
Add --log-http option #326
Conversation
@sixolet is that similar to how kubectl implements -v=8 option? |
Looks like yes-ish, but they use the |
Doesn't, actually, experientially, since the logger is outside the layer that adds them. I can add that to the test.
… On Aug 2, 2019, at 11:57 AM, Dmitriy Kalinin ***@***.***> wrote:
@cppforlife commented on this pull request.
In pkg/util/logging_http_transport.go:
> +func NewLoggingTransport(transport http.RoundTripper) http.RoundTripper {
+ return &LoggingHttpTransport{transport, nil}
+}
+
+func NewLoggingTransportWithStream(transport http.RoundTripper, s io.Writer) http.RoundTripper {
+ return &LoggingHttpTransport{transport, s}
+}
+
+func (t *LoggingHttpTransport) RoundTrip(r *http.Request) (*http.Response, error) {
+ stream := t.stream
+ if stream == nil {
+ stream = os.Stderr
+ }
+ reqBytes, _ := httputil.DumpRequestOut(r, true)
+ fmt.Fprintln(stream, "===== REQUEST =====")
+ fmt.Fprintln(stream, string(reqBytes))
a little concerning that this will include auth headers etc.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
... actually never mind, I was looking at the response. I'll fix. |
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.
Thanks a lot, I think this is a very useful feature.
My only concern is about the UX integration via --log-http
. We have already PRs open which introduce --verbose
and/or --debug
. We should consolidate on that to offer a minimal UI surface for managing log and debug output (especially as it's a global option)
My suggestion would be that we could settle on a convention like:
- Adding
--debug
for very low level information. Only useful for developer ofkn
itself - Adding a
--verbose
option for increasing the detail level of the information presented. Examples arekn service describe --verbose
to add more details to a service (like the image digests, or all env vars/annotations/labels)kn plugin list --verbose
to also print the plugin directories where plugins are looked upkn service create --debug
to print also the HTTP headers
In order to tune debug and verbose output, I'd suggest to introduce categories:
--debug
--> all debug info--debug=all
--> all debug info--debug=http
--> only http related debugging--verbose
--> all verbose output--verbose=config
--> config related information, too--verbose=config,details
--> config information and details (made up here to show how to combine categories)
This suggestion would introduce exactly two option, --debug
and --verbose
(with the possible values shown in the help page). The alternative would be to have an extra option for every category like in this PR, but this would blow up the help pages and UX surface considerably over time.
Happy to use --log
instead of --verbose
it's not so much about naming but about being concise.
The following is the coverage report on pkg/.
|
Let's merge this into |
Let's do it after this PR is merged. I opened #333 for this. /approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: rhuss, sixolet 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 |
It prints all the HTTP requests and responses to stderr.
Quick and dirty, I just found it useful when debugging what requests
kn
was sending, maybe other people will too.Prints the http requests before they get their tokens added, so it's not that much of a security risk.