Skip to content
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

(moved from #13334) feat: fix #13327 #13358

Open
wants to merge 5 commits into
base: 3.2
Choose a base branch
from

Conversation

Linchen-Xu
Copy link
Contributor

@Linchen-Xu Linchen-Xu commented Nov 14, 2023

Moved from #13334 due to branch operation error.

What is the purpose of the change

fix #13327

  • dubbo.jstack-dump.max-line can be used to indicate that all stack trace lines should be printed now by setting it to a negative number, -1 for example.
  • write stack trace info directly into OutputStream instead of building a String.
  • Add tests in JVMUtilTest.

Brief changelog

  • Support custom print stack depth and write error messages directly into OutputStream in org.apache.dubbo.common.utils.JVMUtil.
  • Add tests in org.apache.dubbo.common.utils.JVMUtilTest.
  • Add stack dump test code in AbortPolicyWithReportTest.

Verifying this change

Checklist

  • Make sure there is a GitHub_issue field for the change (usually before you start working on it). Trivial changes like typos do not require a GitHub issue. Your pull request should address just this issue, without pulling in other changes - one PR resolves one issue.
  • Each commit in the pull request should have a meaningful subject line and body.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Check if is necessary to patch to Dubbo 3 if you are work on Dubbo 2.7
  • Write necessary unit-test to verify your logic correction, more mock a little better when cross module dependency exist. If the new feature or significant change is committed, please remember to add sample in dubbo samples project.
  • Add some description to dubbo-website project if you are requesting to add a feature. (will do after it is merged)
  • GitHub Actions works fine on your own branch.
  • If this contribution is large, please follow the Software Donation Guide.

-support custom print stack trace depth
-write error message directly into OutputStream
@Linchen-Xu Linchen-Xu mentioned this pull request Nov 14, 2023
8 tasks
@Linchen-Xu Linchen-Xu changed the title (reopened) feat: fix #13327 (moved from #13334) feat: fix #13327 Nov 14, 2023
System.setProperty(DUBBO_JSTACK_MAXLINE, depth.toString());
try (FileOutputStream jStackStream =
new FileOutputStream(new File("/tmp", "Dubbo_JStack.log" + "." + dateStr))) {
jstack(jStackStream);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check the result which it print

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the comparison between the depth printed by the old logic and the new logic. PTAL.
When it traces back to JVMUtil, the line number will be different, making purely comparing two outputs impractical, unless we ignore some lines in the output.

@codecov-commenter
Copy link

codecov-commenter commented Nov 15, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (c2b273e) 69.56% compared to head (a3b875c) 69.59%.
Report is 5 commits behind head on 3.2.

Additional details and impacted files
@@             Coverage Diff              @@
##                3.2   #13358      +/-   ##
============================================
+ Coverage     69.56%   69.59%   +0.02%     
  Complexity        2        2              
============================================
  Files          1652     1652              
  Lines         71608    71609       +1     
  Branches      10264    10263       -1     
============================================
+ Hits          49814    49835      +21     
+ Misses        17098    17086      -12     
+ Partials       4696     4688       -8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

try {
byte[] encoded = Files.readAllBytes(Paths.get(String.format("/tmp/%s", filename)));
String newOutput = new String(encoded, StandardCharsets.UTF_8);
int newStackDepth = calculateStackDepth(newOutput);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can decode the stack file with some tools to verify if it match the standard output style.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I replaced it with ByteArrayOutputStream to get the result directly, there's no need to decode anymore.

By the way, I tried dumping threads and using the same thread info to generate the stack trace info in both the old way and the new way. Therefore, we can compare the stack trace directly, which turns out to be working correctly.

Optimize logic in JVMUtil to test without writing files while being able to compare the two string outputs directly.
Comment on lines +58 to +67
ThreadInfo[] threadInfos = JVMUtil.dumpAllThreads();
// generate new stack trace info
JVMUtil.jstack(stream, threadInfos);
String newStackTrace = stream.toString();
// generate old stack trace info
String oldStackTrace = OldJVMUtil.jstack(threadInfos);
// calculate stack trace depth
int newStackDepth = calculateStackDepth(newStackTrace);
int oldStackDepth = calculateStackDepth(oldStackTrace);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to verify if JVMUtil work as expected, not work as previous version/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added stack dump test code in AbortPolicyWithReportTest.jStackDumpTest to ensure that the new code is working as expected, but have to check the output file under /tmp.

The output file after running AbortPolicyWithReportTest.jStackDumpTest when setting dubbo.jstack-dump.max-line=-1:
1

Copy link

sonarcloud bot commented Nov 16, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 8 Code Smells

85.7% 85.7% Coverage
0.0% 0.0% Duplication

Copy link
Member

@AlbumenJ AlbumenJ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@AlbumenJ
Copy link
Member

@CrazyHZM PTAL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

JVMUtil performance improvement
3 participants