-
Notifications
You must be signed in to change notification settings - Fork 56
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 endpoint-specific fields to API request log #3528
Conversation
internal/server/grants.go
Outdated
rCtx.AddLogFields = append(rCtx.AddLogFields, func(event *zerolog.Event) { | ||
event.Int64("lastUpdateIndex", r.LastUpdateIndex) | ||
}) |
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 add this separately from numGrants
so that if the request errors and exits early we still get this context added to the log entry.
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.
What log level do these get output at?
Looks like INFO level: https://github.com/infrahq/infra/blob/b243a3a/internal/server/logging.go#L57 |
d7a039f
to
2a48700
Compare
I made a small change to the implementation. Instead of storing the slice directly on |
|
||
// Response is a mutable field. It can be modified by API handlers to add | ||
// new response metadata. | ||
Response *ResponseMetadata |
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.
consider making this a non-pointer
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 believe this will need to be a pointer so that we can mutate it without needing to call c.Set()
to update the value stored in the gin.Context.
A pointer receiver may work, but I was hoping that making this a pointer make it more obvious that this was a mutable value.
I'll think about it some more .
To fix lint error on main
2a48700
to
8be8f16
Compare
I pushed a commit to fix the lint failure on main. I don't think we've found an alternative without adding methods to I'm going to merge it this way. It should be super easy to change at any time. I don't see us adding all that many fields to our logs anytime soon. |
Summary
This PR introduces a hook for adding fields to the API request log. It also uses the new hook in list grants to add a
lastUpdatedIndex
andnumGrants
fields. I think we may also want to use this with SCIM endpoints, so that we can track which provider is using which fields. I'm sure we'll find other use cases for adding fields to the request log as we add new endpoints.I think maybe we can find a better way to include these fields, but this seemed to work for now. If anyone has a suggestion for a better interface, I'd be happy to incorporate it.