Skip to content

Conversation

@rjernst
Copy link
Member

@rjernst rjernst commented Dec 11, 2024

This commit simplifies the entitlements instrumentation service and instrumenter a bit. It especially removes some repetition in the instrumenter tests.

This commit simplifies the entitlements instrumentation service and
instrumenter a bit. It especially removes some repetition in the
instrumenter tests.
@rjernst rjernst added :Core/Infra/Core Core issues without another label >refactoring auto-backport Automatically create backport pull requests when merged v9.0.0 v8.18.0 labels Dec 11, 2024
@rjernst rjernst requested a review from ldematte December 11, 2024 18:59
@elasticsearchmachine elasticsearchmachine added the Team:Core/Infra Meta label for core/infra team label Dec 11, 2024
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra (Team:Core/Infra)

var classesToTransform = checkMethods.keySet().stream().map(MethodKey::className).collect(Collectors.toSet());

inst.addTransformer(new Transformer(INSTRUMENTER_FACTORY.newInstrumenter(checkMethods), classesToTransform), true);
Instrumenter instrumenter = INSTRUMENTER_FACTORY.newInstrumenter(EntitlementChecker.class, checkMethods);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there no need to reference Java23EntitlementChecker anymore?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oof, looks like we already lost this. I'll fix in a followup, but I think we can still use the Class object here, we will want to do Class.forName anyways

Copy link
Member Author

Choose a reason for hiding this comment

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

Note that we were already doing Class.forName inside the instrumenter. We are just making it more explicit here.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK, but still, I do not see a way to load Java23EntitlementChecker in the new code. And I wonder if referencing a class directly (instead by name) could be an issue here (for JDK 22, for example).
I agree, using the Class object is nicer, but does it work?

Copy link
Member Author

Choose a reason for hiding this comment

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

In a followup I will change this back to using a helper method. In the case of Java 23, it will use Class.forName to get the Class object, from a string. In the default case it will use the .class as it does here. In either case, we will pass in the Class object. That's what InstrumentationService was doing internally anyways.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds like a good plan, thank you for clarifying.

Copy link
Contributor

@ldematte ldematte left a comment

Choose a reason for hiding this comment

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

Changes looks good, thanks for the cleanup!

@rjernst rjernst enabled auto-merge (squash) December 13, 2024 21:51
@rjernst rjernst merged commit b456e16 into elastic:main Dec 13, 2024
16 checks passed
@elasticsearchmachine
Copy link
Collaborator

💚 Backport successful

Status Branch Result
8.x

rjernst added a commit to rjernst/elasticsearch that referenced this pull request Dec 13, 2024
This commit simplifies the entitlements instrumentation service and
instrumenter a bit. It especially removes some repetition in the
instrumenter tests.
rjernst added a commit that referenced this pull request Dec 19, 2024
This commit simplifies the entitlements instrumentation service and
instrumenter a bit. It especially removes some repetition in the
instrumenter tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto-backport Automatically create backport pull requests when merged :Core/Infra/Core Core issues without another label >refactoring Team:Core/Infra Meta label for core/infra team v8.18.0 v9.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants