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

Java: Add Logger #1422

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open

Conversation

jonathanl-bq
Copy link
Collaborator

Issue #, if available:
N/A

The Logger implementation here is based on the Python client's implementation, with some relatively small Java/JNI specific changes.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@jonathanl-bq jonathanl-bq requested a review from a team as a code owner May 17, 2024 16:44
@Yury-Fridlyand Yury-Fridlyand added the java issues and fixes related to the java client label May 17, 2024
Copy link
Contributor

@barshaul barshaul left a comment

Choose a reason for hiding this comment

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

IMPORTANT

I see that you use panic and unwrap throughout the lib.rs file, which might crash the user's application, which is definitely something that our client shouldn't do. Have you tested how these unwrap/panics points behave?
In node and python we use Results to return errors, both on the logger and in the value_from_pointer function.
Please check what is the correct way in JNI to handle exceptions, or if it has some JResult object, and test to see how an application would behave when an exception is thrown in the rust code.
See jni-rs/jni-rs#485, might be helpful

java/client/src/main/java/glide/api/logging/Logger.java Outdated Show resolved Hide resolved
java/client/src/main/java/glide/api/logging/Logger.java Outdated Show resolved Hide resolved
java/client/src/main/java/glide/api/logging/Logger.java Outdated Show resolved Hide resolved
java/client/src/main/java/glide/api/logging/Logger.java Outdated Show resolved Hide resolved
@Getter private static Level loggerLevel;

private static void initLogger(@NonNull Level level, String fileName) {
if (level == Level.DISABLED) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we dont have DISABLED option in node and python - can you please open another PR that adds this option to the other wrappers too?

java/client/src/main/java/glide/api/logging/Logger.java Outdated Show resolved Hide resolved
java/client/src/main/java/glide/api/logging/Logger.java Outdated Show resolved Hide resolved
@@ -37,6 +38,7 @@ public class ConnectionWithGlideMockTests extends RustCoreLibMockTestBase {
@BeforeEach
@SneakyThrows
public void createTestClient() {
Logger.setLoggerConfig(Logger.Level.DISABLED);
Copy link
Contributor

Choose a reason for hiding this comment

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

why disabled?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We needed to disable logging to get these tests to work. They're only unit tests and shouldn't be using a real logger anyway.

@@ -134,7 +134,6 @@ tasks.withType(Test) {
events "started", "skipped", "passed", "failed"
showStandardStreams true
}
jvmArgs "-Djava.library.path=${project.rootDir}/target/release"
Copy link
Contributor

Choose a reason for hiding this comment

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

why?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is no longer needed now that we use the NativeLibLoader. It would've been better to put this in the PR that had the changes to publish to local Maven repository, but that's already been merged.

@jonathanl-bq
Copy link
Collaborator Author

IMPORTANT

I see that you use panic and unwrap throughout the lib.rs file, which might crash the user's application, which is definitely something that our client shouldn't do. Have you tested how these unwrap/panics points behave? In node and python we use Results to return errors, both on the logger and in the value_from_pointer function. Please check what is the correct way in JNI to handle exceptions, or if it has some JResult object, and test to see how an application would behave when an exception is thrown in the rust code. See jni-rs/jni-rs#485, might be helpful

I haven't witnessed those SIGABRT messages on the panics so far. It just prints the backtrace to stdout. I can certainly add the catch_unwind and throw Java Exceptions though, just to be safe. The example code in the jni-rs repo does the unwraps, which is what I was following, but maybe the example code isn't very well written.

@barshaul
Copy link
Contributor

barshaul commented May 23, 2024

Yes please add test to check that we handle properly panics in rust

@jonathanl-bq
Copy link
Collaborator Author

Panic handling is coming in a separate PR that overhauls how we handle errors in the FFI layer in general.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
java issues and fixes related to the java client
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants