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

fix instrumentation module not loading silently when duplicate helper… #13005

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

Conversation

FlorianBruckner
Copy link

… classnames are detected.

issue #9752 introduced a check that prevents an instrumentation module from being loaded when duplicate helper classes are detected. Such a case may arise when a class is detected by muzzle as a helper class and at the same time it is registered in additionalHelperClasses. Before #9752, the module would properly load.

The proposed change will allow the instrumentation to load and log a warning. While it may be true that this is actually an issue in the instrumentation module, such cases are not obvious to find, there are modules in the field that have stopped working because this change and the fix should not lead to unintended behavior as we can expect the bytecode of the duplicates to be identical.

… classnames are detected.

issue open-telemetry#9752 introduced a check that prevents an instrumentation module from being loaded when duplicate helper classes are detected. Such a case may arise when a class is detected by muzzle as a helper class and at the same time it is registered in additionalHelperClasses. Before open-telemetry#9752, the module would properly load.

The proposed change will allow the instrumentation to load and log a warning. While it may be true that this is actually an issue in the instrumentation module, such cases are not obvious to find, there are modules in the field that have stopped working because this change and the fix should not lead to unintended behavior as we can expect the bytecode of the duplicates to be identical.
@FlorianBruckner FlorianBruckner requested a review from a team as a code owner January 7, 2025 02:07
Copy link

linux-foundation-easycla bot commented Jan 7, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@trask
Copy link
Member

trask commented Jan 8, 2025

@SylvainJuge @JonasKunz any thoughts on this? thanks

Copy link
Contributor

@JonasKunz JonasKunz left a comment

Choose a reason for hiding this comment

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

LGTM, I don't think that in #9752 I made this check more strict intentionally.
Even if the helper classes happen to have a different bytecode, this very likely only causes the instrumentation to fail and the application itself should run fine, so a warning should be good enough.

With invokedynamic, injecting will become an edge case anyway, so we can expect this warning to pop up rarely.

@@ -183,8 +184,11 @@ public DynamicType.Builder<?> transform(
HelperClassDefinition::getClassName,
helper -> () -> helper.getBytecode().getBytecode(),
(a, b) -> {
throw new IllegalStateException(
"Duplicate classnames for helper class detected!");
logger.log(
Copy link
Contributor

Choose a reason for hiding this comment

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

Firstly I think there should also be a test for this. I have created a PR for your PR 3kraft#1 that you can use to add the test. Secondly I'm not sure that printing a warning here is useful. There isn't anything in the javadoc of

that would suggest that declaring the helper multiple times would be an issue. In its current for the warning isn't too informative as it doesn't even mention the name of the duplicate class. I'd probably leave the throw new IllegalStateException here as it was and ensure the uniqueness at an earlier point. Perhaps add .distinct() to

Copy link
Author

Choose a reason for hiding this comment

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

Hi @laurit

thanks for reviewing and providing the test cases. I agree that the warning message would have been better if it included the offending class name, nevertheless at that point only the bytecode is available and thus I decided to warn with the offending module only.

When the class names are distincted, it is impossible for this case to happen and the merge function could be removed. It will throw an IllegalStateException anyways (https://docs.oracle.com/javase/8/docs/api/java/util/stream/Collectors.html#toMap-java.util.function.Function-java.util.function.Function-).

Copy link
Contributor

Choose a reason for hiding this comment

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

When the class names are distincted, it is impossible for this case to happen and the merge function could be removed. It will throw an IllegalStateException anyways (https://docs.oracle.com/javase/8/docs/api/java/util/stream/Collectors.html#toMap-java.util.function.Function-java.util.function.Function-).

HelperInjector has another constructor that could be provided with input that contains duplicates, though that would most likely be a bug, so I think it is fine to leave the merge function as it is.

Add test for duplicate helper class
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.

5 participants