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

Less logging during tests #14003

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

Conversation

rfscholte
Copy link
Contributor

Logging is a relative expensive operation. Logging during tests is only useful if it is being read (so most likely it is ignored during a succesful run), so it should be reduced to a minimum (and where the logged data is important, it should be converted to an assertion).
After this you'll have a much better overview of what the build is doing and you suddenly might see overseen warnings.

After this I still noticed a couple of things:

  • A couple of Test classes have 0 executed tests. This could be because it is not a test. Be aware that the maven-surefire-plugin has a set of includes, i.e classnames starting with Test or ending with Test, Tests or TestCase but excluding subclasses. For these cases consider an explicit exclude or rename the class so you don't have to wonder again why the number of executed tests is zero.
  • The use of jul-to-slf4j should be avoided as it can have a huge impact on the performance. Most likely this can be replaced with slf4j-jdk-platform-logging.
  • Based on the output of the tests, there are still a few places where is directly written to System.out either in the test or main class). These should be rewritten.

With this PR you'll already see a huge difference. The remarks above are things that can be optimized later.

Best practices and other information can be found at https://github.com/rfscholte/lessLogging

Add profiler profile for information of duration of plugin goals and tests
@codecov-commenter
Copy link

codecov-commenter commented Sep 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 57.88%. Comparing base (59551e4) to head (d561cb3).
Report is 1038 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master   #14003      +/-   ##
============================================
- Coverage     61.75%   57.88%   -3.87%     
- Complexity      207      219      +12     
============================================
  Files          2436     2617     +181     
  Lines        133233   143433   +10200     
  Branches      20636    22021    +1385     
============================================
+ Hits          82274    83026     +752     
- Misses        44911    53917    +9006     
- Partials       6048     6490     +442     
Flag Coverage Δ
custom-integration1 <0.01% <ø> (-0.01%) ⬇️
integration <0.01% <ø> (-0.01%) ⬇️
integration1 <0.01% <ø> (-0.01%) ⬇️
integration2 0.00% <ø> (ø)
java-11 57.86% <ø> (-3.84%) ⬇️
java-21 57.77% <ø> (-3.86%) ⬇️
skip-bytebuffers-false 57.88% <ø> (-3.87%) ⬇️
skip-bytebuffers-true 30.66% <ø> (+2.94%) ⬆️
temurin 57.88% <ø> (-3.87%) ⬇️
unittests 57.88% <ø> (-3.87%) ⬇️
unittests1 40.74% <ø> (-6.15%) ⬇️
unittests2 27.96% <ø> (+0.23%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@@ -26,11 +26,12 @@
</Console>
</Appenders>
<Loggers>
<Logger name="org.apache.pinot" level="warn" additivity="false">
<Root level="OFF"/>
Copy link
Contributor

Choose a reason for hiding this comment

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

We usually need these logs to fix issues detected when a test fail. Although we can always turn it on at the time we are fixing the issue, do you know if there is any alternative way to do that? Maybe reading some property devs can set in their ~/.m2/settings.xml?

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 assume this is only an issue for integration tests, where you need to have a pinot component is a specific state before running the tests. In such case the exception of the test is not enough; in such case the pinot component logging could help.
It is possible to use system properties in log4j.xml files: https://logging.apache.org/log4j/2.x/manual/lookups.html
For me the main question is: should the logging be available when the tests fails, or is it good enough to rerun the test with adjusted settings/arguments?

Comment on lines +103 to +106
<systemPropertyVariables>
<!-- org.glassfish.grizzly uses JUL, -->
<java.util.logging.config.file>src/test/resources/logging-test.properties</java.util.logging.config.file>
</systemPropertyVariables>
Copy link
Contributor

Choose a reason for hiding this comment

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

Couldn't we just set this in the root pom.xml?

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 don't know what the Java Util Logging framework will do if this file is not available. This is the fast and simple solution. It might be worth checking if this AND jul-to-slf4j can be replaced everywhere with slf4j-jdk-platform-logging. jul-to-slf4 is a hack with possible huge performance penalty, whereas slf4j-jdk-platform-logging is the proper way to log to slf4j via a logging provider

pom.xml Show resolved Hide resolved
Comment on lines +297 to +317
<profile>
<id>profiler</id>
<activation>
<property> <!-- with this the profiler extension is activated too -->
<name>profiler</name>
<value>true</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire.version}</version>
<configuration>
<reportFormat>plain</reportFormat>
</configuration>
</plugin>
</plugins>
</build>
</profile>
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it may be useful to run this on the CI by default. WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this will report the durations of individual tests, but also for every maven plugin and maven project. Surefire will write to console, which makes the output unreadable again, but AFAIK this info is already logged to file as well.
If nobody cares I would keep if off, and activate it once you need to analyse build times again.

@gortiz
Copy link
Contributor

gortiz commented Sep 18, 2024

Logging is a relative expensive operation. Logging during tests is only useful if it is being read (so most likely it is ignored during a succesful run), so it should be reduced to a minimum (and where the logged data is important, it should be converted to an assertion).

I can see it may be useful to log less but... numbers don't show that it is an expensive operation. Specifically, tests on this PR took as long as tests in other PRs. I can see advantages when logs are being read (GH takes quite long to load 20k log lines from the other PRs while it is pretty fast with the 2k in this PR) and I'm glad to merge this because it can help to detect maven issues in the future, but we need to include some text indicating how to enable logs in case we want to fix a broken test.

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.

3 participants