-
Notifications
You must be signed in to change notification settings - Fork 282
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
Send log messages to log4j systems instead of system out / error #3231
Send log messages to log4j systems instead of system out / error #3231
Conversation
Signed-off-by: Darshit Chanpura <[email protected]>
6a8d0cf
to
9ff69ae
Compare
Codecov Report
@@ Coverage Diff @@
## main #3231 +/- ##
============================================
+ Coverage 62.43% 62.47% +0.03%
+ Complexity 3352 3350 -2
============================================
Files 254 254
Lines 19748 19737 -11
Branches 3334 3334
============================================
+ Hits 12330 12331 +1
+ Misses 5789 5777 -12
Partials 1629 1629
|
Taking a look at the test failure |
src/main/java/org/opensearch/security/tools/AuditConfigMigrater.java
Outdated
Show resolved
Hide resolved
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.
Nice - thanks for keeping the console output cleaner. Can you see about adding an rule to prevent system.out/system.err usage to keep the codebase programmatically cleaned?
Note; I think adding exceptions is fine for a couple places we do want console output
Signed-off-by: Darshit Chanpura <[email protected]>
I was contemplating between adding such check and not adding it, but your comment helped decide :D. I have added a github check. |
c8d211b
to
a25a993
Compare
.github/workflows/code-hygiene.yml
Outdated
@@ -83,3 +83,17 @@ jobs: | |||
fi | |||
done | |||
exit $exit_code | |||
|
|||
check-println: |
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.
Instead of a new check, what about leveraging checkstyle's RegexpSingleline, below was how the 'extension' filter was added, maybe we could add entries for system.out.print & system.err.print that would be easier to maintain
<module name="RegexpSingleline">
<property name="format" value="extension"/>
<property name="ignoreCase" value="true"/>
<property name="message" value="Extension should only be used sparingly to keep implementations as generic as possible" />
<property name="severity" value="error"/>
</module>
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.
I tried that but didn't have a working solution, I'll invest some more time to see if I can make it work
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.
I was not able to have it working with:
<module name="RegexpSingleline">
<property name="format" value="System\.out\.println" />
<property name="message" value="Do not use System.out.println" />
<!-- Exception list of files and directories -->
<property name="fileExtensions" value="java" />
<property name="exclude" value="./src/main/java/org/opensearch/security/tools, ./src/main/java/com/amazon/dlic/auth/http/kerberos/HTTPSpnegoAuthenticator.java" />
</module>
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.
Try building off of this, works locally for me
<module name="RegexpSingleline">
<property name="format" value="println"/>
<property name="ignoreCase" value="true"/>
<property name="message" value="SYSTEM.OUT.PRINTLN NONONO!" />
<property name="severity" value="error"/>
</module>
./gradlew checkstyleMain
...
> Task :checkstyleMain
[ant:checkstyle] [ERROR] /local/home/petern/git/security/src/main/java/org/opensearch/security/securityconf/DynamicConfigFactory.java:247: SYSTEM.OUT.PRINTLN NONONO! [RegexpSingleline]
[ant:checkstyle] [ERROR] /local/home/petern/git/security/src/main/java/org/opensearch/security/securityconf/DynamicConfigFactory.java:248: SYSTEM.OUT.PRINTLN NONONO! [RegexpSingleline]
[ant:checkstyle] [ERROR] /local/home/petern/git/security/src/main/java/org/opensearch/security/auditlog/sink/AuditLogSink.java:63: SYSTEM.OUT.PRINTLN NONONO! [RegexpSingleline]
[ant:checkstyle] [ERROR] /local/home/petern/git/security/src/main/java/org/opensearch/security/auditlog/sink/DebugSink.java:30: SYSTEM.OUT.PRINTLN NONONO! [RegexpSingleline]
[ant:checkstyle] [ERROR] /local/home/petern/git/security/src/main/java/org/opensearch/security/ssl/OpenSearchSecuritySSLPlugin.java:161: SYSTEM.OUT.PRINTLN NONONO! [RegexpSingleline]
[ant:checkstyle] [ERROR] /local/home/petern/git/security/src/main/java/org/opensearch/security/ssl/OpenSearchSecuritySSLPlugin.java:162: SYSTEM.OUT.PRINTLN NONONO! [RegexpSingleline]
[ant:checkstyle] [ERROR] /local/home/petern/git/security/src/main/java/org/opensearch/security/ssl/OpenSearchSecuritySSLPlugin.java:228: SYSTEM.OUT.PRINTLN NONONO! [RegexpSingleline]
[ant:checkstyle] [ERROR] /local/home/petern/git/security/src/main/java/org/opensearch/security/ssl/OpenSearchSecuritySSLPlugin.java:229: SYSTEM.OUT.PRINTLN NONONO! [RegexpSingleline]
[ant:checkstyle] [ERROR] /local/home/petern/git/security/src/main/java/org/opensearch/security/tools/AuditConfigMigrater.java:94: SYSTEM.OUT.PRINTLN NONONO! [RegexpSingleline]
[ant:checkstyle] [ERROR] /local/home/petern/git/security/src/main/java/org/opensearch/security/tools/AuditConfigMigrater.java:109: SYSTEM.OUT.PRINTLN NONONO! [RegexpSingleline]
[ant:checkstyle] [ERROR] /local/home/petern/git/security/src/main/java/org/opensearch/security/tools/AuditConfigMigrater.java:112: SYSTEM.OUT.PRINTLN NONONO! [RegexpSingleline]
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.
Yes, but the problem is how to exclude. There is no such Property called exclude
. Do you know of anything of that might work?
Closest thing I found was this: https://github.com/checkstyle/checkstyle/blob/master/src/main/resources/sun_checks.xml#L46-L50
However this applies to whole file, so I might have to end up creating a separate xml for sysout check anyway. (didn't try it yet)
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.
I was able to achieve this by adding a separate file for println checks.
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.
That's too hard lol - exclusions can be done in place, see https://github.com/opensearch-project/security/blob/main/DEVELOPER_GUIDE.md#checkstyle-violations
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.
I know but this would allow us to exclude files in one place instead of marking them individually. I felt like this was cleaner, so I went with this option. What do you think?
Signed-off-by: Darshit Chanpura <[email protected]>
a25a993
to
770fa09
Compare
Signed-off-by: Darshit Chanpura <[email protected]>
Fixed |
Signed-off-by: Darshit Chanpura <[email protected]>
Signed-off-by: Darshit Chanpura <[email protected]>
The backport to
To backport manually, run these commands in your terminal: # Navigate to the root of your repository
cd $(git rev-parse --show-toplevel)
# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add ../.worktrees/security/backport-2.x 2.x
# Navigate to the new working tree
pushd ../.worktrees/security/backport-2.x
# Create a new branch
git switch --create backport/backport-3231-to-2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 683c4f564e89583d9e98bc2fc4eaaf62b630e2f1
# Push it to GitHub
git push --set-upstream origin backport/backport-3231-to-2.x
# Go back to the original working tree
popd
# Delete the working tree
git worktree remove ../.worktrees/security/backport-2.x Then, create a pull request where the |
…pensearch-project#3231) A lot of files (mostly tests) have sysout's which do nothing but degrade the performance. This PR removes all sysouts from tests, replace sysouts with logger in project files. Also removes all e.printStacktrace(); calls. - `tools/` package - no sysouts were removed from here - HTTPSpnegoAuthenticator.java - a portion was not modified since it enabled debugging on console. Signed-off-by: Darshit Chanpura <[email protected]> (cherry picked from commit 683c4f5)
…ere necessary (#3231) (#3240) Backports #3231. Needed manual backport because of http5 imports and server `shutdown` (2.x) vs `awaitTermination` (main) method calls in test. Signed-off-by: Darshit Chanpura <[email protected]>
Description
A lot of files (mostly tests) have sysout's which do nothing but degrade the performance. This PR removes all sysouts from tests, replace sysouts with logger in project files.
Also removes all e.printStacktrace(); calls.
tools/
package - no sysouts were removed from hereCheck List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.