-
Notifications
You must be signed in to change notification settings - Fork 25.6k
[Entitlements] Fix Entitlement initialization to work across multiple versions #121192
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
[Entitlements] Fix Entitlement initialization to work across multiple versions #121192
Conversation
|
Pinging @elastic/es-core-infra (Team:Core/Infra) |
...main/java/org/elasticsearch/entitlement/instrumentation/impl/InstrumentationServiceImpl.java
Outdated
Show resolved
Hide resolved
|
In general, reflection-based code is easier to read and maintain than ASM code. I'd lean toward reflection if there's no compelling reason to use ASM. |
…ltiple-version-checker-initialization-2
…objects instead of strings
I was thinking the same and thought that reflection could be equivalent but Iwas wrong in assuming that: as this test failure #120811 (comment) demonstrates, we have to be very careful when using reflection this early. So I closed #121132 in favor of this one, "porting" all the comments here and addressing them. |
rjernst
left a comment
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.
Looks fine but one question.
|
|
||
| methodsToInstrument.put(methodToInstrument, checkMethod); | ||
| var classFileInfo = InstrumenterImpl.getClassFileInfo(currentClass); | ||
| ClassReader reader = new ClassReader(classFileInfo.bytecodes()); |
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.
Why do we need asm here? Since we have Class objects already, can't we use reflection to find all of the methods?
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 thinking the same, but every time we use reflection (e.g. in #120811 (comment)), we end up regretting it and go back to ASM; for example in the linked issue I tried to use reflection first, only to end up with NoClassDefFoundError errors in tests due to the fact that our interface uses types that may not (are not) always available (at least at this time).
It might be fine in this case if we use it only for finding the base classes, but since we need to use ASM to find all the methods anyway, why risk?
|
Serverless failure is due to a lack of policy - fixed in 3451 |
prdoyle
left a comment
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'd rather see some protection against visiting interfaces multiple times, but we can merge this as-is I think.
Also, reflection would probably be simpler than asm, but that's also not a hill I want to die on.
That I've added, implementing your suggestion. See line 55 of InstrumentationServiceImpl. |
💔 Backport failed
You can use sqren/backport to manually backport by running |
This PR fixes an issue that become apparent with #121017: when we initialize Entitlements, and we get the list of methods to instrument, and instrument them, we need to get them from all the "versioned" interfaces compatible with the current runtime version. We also need to use the most specific (latest) "versioned" interface in the instrumentation code.
Alternative to #121132 which uses ASM and the actual inheritance chain to navigate the classes (interfaces) to extract
check$methods from.