Skip to content

Commit

Permalink
perf(logging): Optimize the performance of log collection (#5931)
Browse files Browse the repository at this point in the history
- Adjust the serialization timing of the request body and response body to avoid unnecessary string operations.
- Perform string conversion only after confirming the need to record logs to reduce resource consumption.

Co-authored-by: 宗杰 <[email protected]>
  • Loading branch information
zongmingzhi and 宗杰 authored Feb 13, 2025
1 parent e1a48a1 commit 5bd78ff
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ public Flux<DataBuffer> getBody() {
}
}).doFinally(signal -> {
int size = writer.size();
String body = writer.output();
boolean requestBodyTooLarge = LogCollectConfigUtils.isRequestBodyTooLarge(size);
if (size == 0 || requestBodyTooLarge) {
return;
}
String body = writer.output();
logInfo.setRequestBody(body);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ private void logResponse(final ShenyuContext shenyuContext, final BodyWriter wri
}
if (Objects.nonNull(writer)) {
int size = writer.size();
String body = writer.output();
if (size > 0 && !LogCollectConfigUtils.isResponseBodyTooLarge(size)) {
String body = writer.output();
logInfo.setResponseBody(body);
}
} else {
Expand Down Expand Up @@ -261,8 +261,8 @@ public void logError(final Throwable throwable) {
}

int size = bytes.length;
String body = new String(bytes, StandardCharsets.UTF_8);
if (size > 0 && !LogCollectConfigUtils.isResponseBodyTooLarge(size)) {
String body = new String(bytes, StandardCharsets.UTF_8);
logInfo.setResponseBody(body);
}
// collect log
Expand Down

0 comments on commit 5bd78ff

Please sign in to comment.