-
Notifications
You must be signed in to change notification settings - Fork 513
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 error stack in biz history record message #1028
Conversation
WalkthroughThe changes involve modifications to the Changes
Sequence Diagram(s)sequenceDiagram
participant BizModel
participant Throwable
participant StringWriter
participant PrintWriter
BizModel->>Throwable: Exception occurs during startup
BizModel->>StringWriter: Create new StringWriter instance
BizModel->>PrintWriter: Create new PrintWriter with StringWriter
BizModel->>Throwable: Call getStackTraceAsString(Throwable)
PrintWriter->>StringWriter: Write stack trace to StringWriter
BizModel->>BizModel: Set biz state with stack trace string
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1028 +/- ##
============================================
+ Coverage 78.20% 78.30% +0.09%
Complexity 874 874
============================================
Files 171 171
Lines 7056 7060 +4
Branches 1037 1037
============================================
+ Hits 5518 5528 +10
+ Misses 1006 999 -7
- Partials 532 533 +1 ☔ View full report in Codecov by Sentry. |
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.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (1)
sofa-ark-parent/core/api/src/main/java/com/alipay/sofa/ark/api/ArkClient.java (1)
190-193
: LGTM! Consider enhancing the log message clarity.The addition of logging for repeat biz installations improves observability. However, the message could be more explicit about whether the biz was already installed or just registered.
Consider this minor enhancement to the message format:
- response.setCode(ResponseCode.REPEAT_BIZ).setMessage( - String.format("Biz: %s has been installed or registered.", biz.getIdentity())); + response.setCode(ResponseCode.REPEAT_BIZ).setMessage( + String.format("Biz: %s installation skipped - already %s.", + biz.getIdentity(), + bizManagerService.getBizByIdentity(biz.getIdentity()) != null ? "installed" : "registered"));
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.
Actionable comments posted: 1
🧹 Outside diff range and nitpick comments (1)
sofa-ark-parent/core-impl/container/src/main/java/com/alipay/sofa/ark/container/model/BizModel.java (1)
348-348
: Consider memory implications of storing full stack tracesWhile storing the full stack trace provides better debugging information, it could lead to increased memory usage if there are frequent failures or many biz modules. Consider:
- Implementing a maximum length limit for stored stack traces
- Adding a configuration option to control stack trace storage
Example implementation:
- setBizState(BizState.BROKEN, StateChangeReason.INSTALL_FAILED, getStackTraceAsString(e)); + setBizState(BizState.BROKEN, StateChangeReason.INSTALL_FAILED, truncateStackTrace(getStackTraceAsString(e))); + private String truncateStackTrace(String stackTrace) { + int maxLength = Integer.parseInt(System.getProperty("sofa.ark.biz.stack.trace.max.length", "4096")); + return stackTrace.length() > maxLength ? stackTrace.substring(0, maxLength) + "..." : stackTrace; + }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
sofa-ark-parent/core-impl/container/src/main/java/com/alipay/sofa/ark/container/model/BizModel.java
(3 hunks)
🔇 Additional comments (2)
sofa-ark-parent/core-impl/container/src/main/java/com/alipay/sofa/ark/container/model/BizModel.java (2)
47-48
: LGTM: Import statements are appropriate
The added imports for PrintWriter
and StringWriter
are necessary for the new stack trace handling functionality.
348-348
: Verify consistent error handling across the codebase
Let's verify if this error handling improvement should be applied consistently across other error scenarios in the codebase.
Also applies to: 648-653
✅ Verification successful
Let me gather more information about error handling patterns in the codebase.
Error handling is consistent with existing patterns
The change to use getStackTraceAsString(e)
in the error state transition is consistent with the existing error handling patterns in the codebase. The verification shows:
- The
getStackTraceAsString
method is only used in this specific error case for installation failures - Other error transitions to
BizState.BROKEN
exist but handle different scenarios:UN_INSTALL_FAILED
doesn't include stack trace as it's a different type of failure- Test cases properly verify the
BROKEN
state transitions
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Search for other error handling patterns in setBizState calls
echo "Searching for other setBizState calls with error messages..."
rg "setBizState\(.*,.*,.*\)" -A 2
# Search for other places where exception messages are used
echo "Searching for other exception message usage patterns..."
ast-grep --pattern 'getMessage()'
Length of output: 2200
Script:
#!/bin/bash
# Search for getStackTraceAsString usage
echo "Searching for getStackTraceAsString usage..."
rg "getStackTraceAsString" -A 2
# Search for other error state transitions
echo "Searching for BROKEN state transitions..."
rg "BizState\.BROKEN" -A 2
# Search for other INSTALL_FAILED usage
echo "Searching for INSTALL_FAILED usage..."
rg "INSTALL_FAILED" -A 2
Length of output: 5404
private static String getStackTraceAsString(Throwable throwable) { | ||
StringWriter sw = new StringWriter(); | ||
PrintWriter pw = new PrintWriter(sw); | ||
throwable.printStackTrace(pw); | ||
return sw.toString(); | ||
} |
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.
🛠️ Refactor suggestion
Enhance utility method with null check and resource management
The stack trace conversion method should include null check and proper resource management using try-with-resources.
Suggested implementation:
private static String getStackTraceAsString(Throwable throwable) {
+ if (throwable == null) {
+ return "";
+ }
- StringWriter sw = new StringWriter();
- PrintWriter pw = new PrintWriter(sw);
- throwable.printStackTrace(pw);
- return sw.toString();
+ try (StringWriter sw = new StringWriter();
+ PrintWriter pw = new PrintWriter(sw)) {
+ throwable.printStackTrace(pw);
+ return sw.toString();
+ } catch (IOException e) {
+ return throwable.getMessage();
+ }
}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
private static String getStackTraceAsString(Throwable throwable) { | |
StringWriter sw = new StringWriter(); | |
PrintWriter pw = new PrintWriter(sw); | |
throwable.printStackTrace(pw); | |
return sw.toString(); | |
} | |
private static String getStackTraceAsString(Throwable throwable) { | |
if (throwable == null) { | |
return ""; | |
} | |
try (StringWriter sw = new StringWriter(); | |
PrintWriter pw = new PrintWriter(sw)) { | |
throwable.printStackTrace(pw); | |
return sw.toString(); | |
} catch (IOException e) { | |
return throwable.getMessage(); | |
} | |
} |
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.
LGTM
(cherry picked from commit 96f5fc2)
Summary by CodeRabbit
New Features
Bug Fixes