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

Improve recently added log messages by adding context to indicate which build is relevant #640

Merged
merged 2 commits into from
Aug 22, 2024

Conversation

dwnusbaum
Copy link
Member

@dwnusbaum dwnusbaum commented Aug 22, 2024

Amends #625. @olamy recently saw a bunch of these log messages, which were added in that PR I guess to help detect slow loading, but they are not really useful without indicating which build is relevant:

2024-08-22 08:03:49.329+0000 [id=465]	WARNING	h.tasks.junit.TestResultAction#getResult: TestResultAction.load took 1060 ms.

This PR does 3 main things:

  • For the new log messages added in Test history refactoring and improvements #625, it adds either Run.toString() or File.toString() to the message to provide context
  • It removes the hard-coded Class.method parts of the messages, which are added automatically by the default Jenkins logger
  • It changes the visibility of the new static parse methods in Test history refactoring and improvements #625 that as far as I understand were only intended for internal use from public to package-private. This plugin is a dependency of various other plugns, so I think it is desirable to avoid accidentally increasing the API surface

Testing done

I mangled some test files locally and enabled FINEST logging to check that log messages worked and indicated which build was relevant.

Submitter checklist

  • Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or Jira
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Ensure you have provided tests - that demonstrates feature works or fixes the issue

…ch build is relevant

Also remove redundant class and method names from log messages and make some internal
methods package-private instead of public.
@dwnusbaum dwnusbaum requested a review from a team as a code owner August 22, 2024 16:49
@@ -269,7 +268,7 @@ public static float clampDuration(float d) {
return Math.min(365.0f * 24 * 60 * 60, Math.max(0.0f, d));
}

public static CaseResult parse(SuiteResult parent, final XMLStreamReader reader, String ver)
Copy link
Member Author

Choose a reason for hiding this comment

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

As far as I know nothing should be using these new methods from #625, so I made them all package-private, but if that is not true, let me know and I will revert that part of the change.

if (LOGGER.isLoggable(Level.FINEST)) {
LOGGER.finest("CaseResult.parse encountered an unknown field: " + elementName);
}
LOGGER.finest(() -> "Unknown field in " + context + ": " + elementName);
Copy link
Member Author

@dwnusbaum dwnusbaum Aug 22, 2024

Choose a reason for hiding this comment

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

I also checked whether XMLReader.getLocation included a file name to avoid having to pass context everywhere, but getPublicID and getSystemID just return null (and IDK what they would even return if they weren't null). We could add line and column numbers to give even more context, but I don't really think it would be helpful in practice.

@@ -179,8 +179,8 @@ public synchronized TestResult getResult() {
skipCount = r.getSkipCount();
}
long d = System.nanoTime() - started;
if (d > 500000000L && LOGGER.isLoggable(Level.WARNING)) {
Copy link
Member Author

Choose a reason for hiding this comment

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

500000000 is 5e8, or 0.5 seconds. I adjusted the code to use TimeUnit to make it clearer, but I could switch it to 500 * 1000 * 1000 or whatever you think is clearest.

Copy link
Member Author

Choose a reason for hiding this comment

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

(I also wonder if this threshold is too low for WARNING and it should be increased to 1-2 seconds, maybe logging at FINE for stuff between 0.5-1 seconds)

Copy link
Contributor

Choose a reason for hiding this comment

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

I like the idea of setting the threshold higher for logging at less than 2 seconds, but approve this pull request with or without that change.

@@ -69,7 +70,6 @@
@SuppressFBWarnings(value = "UG_SYNC_SET_UNSYNC_GET", justification = "False positive")
public class TestResultAction extends AbstractTestResultAction<TestResultAction>
implements StaplerProxy, SimpleBuildStep.LastBuildAction {
private static final Logger LOGGER = Logger.getLogger(TestResultAction.class.getName());
Copy link
Member Author

Choose a reason for hiding this comment

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

This was added in #625, but we already had a logger at the bottom of the file, it was just named lowercase logger.

@dwnusbaum dwnusbaum requested a review from timja August 22, 2024 17:10
@@ -179,8 +179,8 @@ public synchronized TestResult getResult() {
skipCount = r.getSkipCount();
}
long d = System.nanoTime() - started;
if (d > 500000000L && LOGGER.isLoggable(Level.WARNING)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I like the idea of setting the threshold higher for logging at less than 2 seconds, but approve this pull request with or without that change.

@timja timja merged commit bf538bc into jenkinsci:master Aug 22, 2024
16 checks passed
@olamy
Copy link
Member

olamy commented Aug 22, 2024

@dwnusbaum Thanks!

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

Successfully merging this pull request may close these issues.

4 participants