-
Notifications
You must be signed in to change notification settings - Fork 10
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
Log stream responses with progress. #49
Conversation
/release-note-none |
/assign @PrasadG193 |
Selective test output illustrating the logging:
and
|
f71c948
to
92990e8
Compare
b.WriteString("[") | ||
for _, bmd := range clientResp.BlockMetadata { | ||
b.WriteString(fmt.Sprintf("{%d,%d}", bmd.ByteOffset, bmd.SizeBytes)) | ||
} | ||
b.WriteString("]") |
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 not use json encoding?
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 had first used a JSON dump of the entire data structure but then reconsidered. JSON encoding is very verbose and would repeat the byte_offset
and size_bytes
labels for each entry. This is more compact and expresses the same data and we don't have to trim the output.
For example, if I replace
b.WriteString("[")
for _, bmd := range clientResp.BlockMetadata {
b.WriteString(fmt.Sprintf("{%d,%d}", bmd.ByteOffset, bmd.SizeBytes))
}
b.WriteString("]")
...
logger.WithValues(
...
"blockMetadata", b.String(),
...
).Info("stream response")
with
enc := json.NewEncoder(&b)
_ = enc.Encode(clientResp.BlockMetadata)
...
logger.WithValues(
...
"blockMetadata", strings.TrimSuffix(b.String(), "\n"),
...
).Info("stream response")
then the output changes from
blockMetadata="[{1,1024}{2,1024}]"
to
blockMetadata="[{\"byte_offset\":1,\"size_bytes\":1024},{\"byte_offset\":2,\"size_bytes\":1024}]"
Also, the autogenerated field names for JSON do not use camel case but instead use underscores, which looks a bit ugly to me.
92990e8
to
595a5da
Compare
@@ -38,7 +38,8 @@ import ( | |||
) | |||
|
|||
const ( | |||
HandlerTraceLogLevel = 4 | |||
HandlerTraceLogLevel = 4 | |||
HandlerDetailedTraceLogLevel = 5 |
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 added a detailed trace level for the contents of the stream response loop.
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.
@carlbraganza I think the logs level is not specific to handler methods, right? I mean the level can be set in log in any package. Should we give generic names like - debug, info, verbose, etc?
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.
Klog uses a concept of a process wide verbosity level (the V
function), and each -v flag increments the level used. There are no clear definitions for info, debug, etc. - these are "severity" values in the log which could be logged at any verbosity level.
I defined these constants for the handler package, with the only constraint being that
1 <= HandlerTraceLogLevel < HandlerDetailedTraceLogLevel
We could define common process wide constants to assign values to these constants later if we see the need, but for now I think most of the business logic is concentrated in the grpc/server
package.
/lgtm |
/approve |
595a5da
to
e3f9d0f
Compare
e3f9d0f
to
35d3aaa
Compare
I applied the permission change to |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: carlbraganza, PrasadG193 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 |
Fixes: #41