-
Notifications
You must be signed in to change notification settings - Fork 25
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
implements structured logging for apiserver #113
Conversation
BugRoger
commented
Dec 7, 2017
pkg/util/log/gophercloud.go
Outdated
if response != nil { | ||
logger = kitlog.With(logger, | ||
"status", response.StatusCode, | ||
"size", response.ContentLength, |
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.
why is this always -1? i suppose it needs to be wrapped into a buffer or something.
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.
From the go docs:
ContentLength records the length of the associated content. The
value -1 indicates that the length is unknown. Unless Request.Method
is "HEAD", values >= 0 indicate that the given number of bytes may
be read from Body.
I think the server (openstack service) doesn't set the content-length header as this would require buffering the whole response before sending anything.
@databus23 please review. if ok, would rewrite the rest of the api-server and openstack clients |
c.Logger.Log( | ||
"msg", "authenticated", | ||
"took", time.Since(begin), | ||
"v", 2, |
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'm wondering if we should log authentication errors at a higher level then successful auth attempts. Not sure what else is logged but when openstack auth is failing we should be able to see this without the need to enable verbose
logging.
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.
done for this specific instance
pkg/util/log/gophercloud.go
Outdated
} | ||
|
||
func (lrt *loggingRoundTripper) RoundTrip(request *http.Request) (response *http.Response, err error) { | ||
logger := kitlog.With(lrt.Logger, |
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.
Looking at the implementation of With
it doesn't come for free. There is quite some shuffling around and allocations going on.
I think its pretty inefficient to prepare a single log line like this, especially using With
in a loop. We should try to use the contextual loggers only if they are used for a longer period and for multiple log lines.
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.
Optimized in 1393ff5
pkg/util/log/middleware.go
Outdated
host = request.RemoteAddr | ||
} | ||
|
||
privateLogger := kitlog.With(logger, |
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.
The statement above about using contextual loggers sparingly applies here.
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.
fixed
pkg/util/log/middleware.go
Outdated
privateLogger := kitlog.With(logger, | ||
"method", request.Method, | ||
"host", host, | ||
"path", request.URL.EscapedPath(), |
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.
missing the User-Agent
here
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.
Added
pkg/api/rest/configure_kubernikus.go
Outdated
@@ -25,8 +18,7 @@ func configureFlags(api *operations.KubernikusAPI) { | |||
} | |||
|
|||
func configureAPI(api *operations.KubernikusAPI) http.Handler { | |||
|
|||
return setupGlobalMiddleware(api.Serve(setupMiddlewares)) | |||
return api.Serve(setupMiddlewares) |
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.
Can we change this to return api.Serve
and remove the setupMiddleware
function?
I find these two levels of middleware confusing and never quite understood the intended use case for the inner middleware chain.
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.
Looks good overall. Some minor remarks
29337d1
to
b5aa4e5
Compare
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 few last nits. Otherwise LGTM
cmd/apiserver/main.go
Outdated
"github.com/golang/glog" | ||
kitLog "github.com/go-kit/kit/log" | ||
"github.com/go-stack/stack" | ||
|
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.
ocd alarm.
I'm trying to only have 3 groups in the imports in the following order:
stdlib
[empty line]
external deps
[empty line]
kubernikus internal deps
@@ -25,8 +18,9 @@ func configureFlags(api *operations.KubernikusAPI) { | |||
} | |||
|
|||
func configureAPI(api *operations.KubernikusAPI) http.Handler { | |||
|
|||
return setupGlobalMiddleware(api.Serve(setupMiddlewares)) | |||
return api.Serve(func(handler http.Handler) http.Handler { |
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 we can reduce this to return api.Serve
, no?
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.
Scratch that we can't
pkg/util/log/gophercloud.go
Outdated
|
||
transport := providerClient.HTTPClient.Transport | ||
if transport == nil { | ||
transport = &http.Transport{} |
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.
Shouldn't we do http.DefaultTransport
here?
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.
good catch
b5aa4e5
to
04bb84f
Compare
04bb84f
to
97943e6
Compare