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

Move plugin-related utilities and API to SDK/tracer #3166

Merged
merged 34 commits into from
Jul 10, 2023

Conversation

raphw
Copy link
Contributor

@raphw raphw commented Jun 6, 2023

This API separates API that is mainly used within plugins from the core module but makes it available via the tracer-api (if functional) or the sdk module (if technical). The scope of the latter can be discussed as this exposes it to user plugins, but I found that there are several legitimate uses of some of the Byte Buddy extensions (several custom annotations and matchers) from within non-built-in-plugins. This is also true for several util classes which are mainly used from plugins where technical utilities are moved to the SDK and functional utilities are moved to the tracer module. Also, the PluginClassLoaderRootPackageCustomizer is moved to the SDK (the question being if it should be exposed, but I think there are use cases). Finally, the TraceAwareInstrumentation class is removed as it creates an unfortunate binding between the SDK and tracer module which does not otherwise exist elsewhere. By removing this class, the two modules can remain separated.

@github-actions github-actions bot added agent-java community Issues and PRs created by the community triage labels Jun 6, 2023
@github-actions
Copy link

github-actions bot commented Jun 6, 2023

👋 @raphw Thanks a lot for your contribution!

It may take some time before we review a PR, so even if you don’t see activity for some time, it does not mean that we have forgotten about it.

Every once in a while we go through a process of prioritization, after which we are focussing on the tasks that were planned for the upcoming milestone. The prioritization status is typically reflected through the PR labels. It could be pending triage, a candidate for a future milestone, or have a target milestone set to it.

@apmmachine
Copy link
Contributor

apmmachine commented Jun 6, 2023

❕ Build Aborted

The PR is not allowed to run in the CI yet

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview

Expand to view the summary

Build stats

  • Start Time: 2023-07-03T11:39:18.942+0000

  • Duration: 4 min 48 sec

Steps errors 2

Expand to view the steps failures

Load a resource file from a library
  • Took 0 min 0 sec . View more details here
  • Description: approval-list/elastic/apm-agent-java.yml
Error signal
  • Took 0 min 0 sec . View more details here
  • Description: githubApiCall: The REST API call https://api.github.com/orgs/elastic/members/raphw return the message : java.lang.Exception: httpRequest: Failure connecting to the service https://api.github.com/orgs/elastic/members/raphw : httpRequest: Failure connecting to the service https://api.github.com/orgs/elastic/members/raphw : Code: 404Error: {"message":"User does not exist or is not a member of the organization","documentation_url":"https://docs.github.com/rest/reference/orgs#check-organization-membership-for-a-user"}

🤖 GitHub comments

Expand to view the GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

  • run benchmark tests : Run the benchmark tests.

  • run jdk compatibility tests : Run the JDK Compatibility tests.

  • run integration tests : Run the Agent Integration tests.

  • run end-to-end tests : Run the APM-ITs.

  • run windows tests : Build & tests on windows.

  • run elasticsearch-ci/docs : Re-trigger the docs validation. (use unformatted text in the comment!)

raphw added 2 commits June 30, 2023 08:41
# Conflicts:
#	apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/AbstractSpan.java
#	apm-agent-plugins/apm-cassandra/apm-cassandra3-plugin/src/main/java/co/elastic/apm/agent/cassandra3/Cassandra3Instrumentation.java
#	apm-agent-plugins/apm-cassandra/apm-cassandra4-plugin/src/main/java/co/elastic/apm/agent/cassandra4/Cassandra4Instrumentation.java
#	apm-agent-plugins/apm-dubbo-plugin/src/main/java/co/elastic/apm/agent/dubbo/advice/ApacheMonitorFilterAdvice.java
#	apm-agent-plugins/apm-httpclient-core/src/test/java/co/elastic/apm/agent/httpclient/AbstractHttpClientInstrumentationTest.java
@raphw
Copy link
Contributor Author

raphw commented Jun 30, 2023

I resolved the import conflicts. @SylvainJuge - did you have time to review? Almost there!

@SylvainJuge
Copy link
Member

Hi @raphw , thanks for keeping this PR up-to-date.
I've already had a couple of large PR reviews this week, but I'll try to prioritize yours next week.

@SylvainJuge SylvainJuge self-requested a review July 5, 2023 12:38
Copy link
Member

@SylvainJuge SylvainJuge left a comment

Choose a reason for hiding this comment

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

Yet another great refactor, thanks for this @raphw !

I think it's mostly fine to merge, and I only have very minor comments.

The extra indirection with service providers seems a bit overkill, but I don't think we have a better way to implement that without exposing implementation details from the core module to the plugins sdk, so I think it's fine. As it's only a few static methods maybe having a single provider/implementation could maybe simplify it a bit, but that would just group unrelated methods together in a single interface.

@SylvainJuge SylvainJuge self-assigned this Jul 5, 2023
@JonasKunz
Copy link
Contributor

JonasKunz commented Jul 6, 2023

LGTM as well, I just noticed that a lot of stuff has been moved into the sdk-project, which is intended to be used as public api for external plugins.
Should we maybe move those classes to the .internal package, to mark them as not so public?

And regarding the PluginClassLoaderRootPackageCustomizer: Even if it is now visible to external plugins, it won't be used. For external plugins we always copy all of the classes from the external plugin jar into the plugin classloaders.
For that reason, I would move that one into an internal package aswell.

@jackshirazi
Copy link
Contributor

jackshirazi commented Jul 6, 2023

we shouldn't be expanding the public API at all, as it's intended to be deprecated in favour of the OpenTelemetry API

@raphw
Copy link
Contributor Author

raphw commented Jul 6, 2023

The premise was that it should be possible to implement Elastic's plugins with the SDK and tracer APIs. As some of the APIs build on top of the current SDK, this was the only way to go. Another option would be to define a sdk-ext module which houses these extensions and to declare them not safe for public use. If one wanted to make these classes available later, they could still be moved to the non-ext module.

@JonasKunz
Copy link
Contributor

we shouldn't be expanding the public API at all, as it's intended to be deprecated in favour of the OpenTelemetry API

I think we need to distinguish between the API used for creating spans (=opentelemetry or our "public API") vs the API required for defining the bootstraping of the external plugin, e.g. ElasticApmInstrumentation. The latter one is represented by our sdk project and there is no compatible OTel pendant yet to my knowledge.

@JonasKunz
Copy link
Contributor

Another option would be to define a sdk-ext module which houses these extensions and to declare them not safe for public use. If one wanted to make these classes available later, they could still be moved to the non-ext module.

I think that would be a bit overkill and add yet another module, of which we already have plenty 😅 . Therefore my suggestion to mark them as not intended for public uses by moving them to an internal package within the same module. While this does not prevent usage in external plugins, it at least discourages it.

@raphw
Copy link
Contributor Author

raphw commented Jul 6, 2023

In Mockito, we use an Incubating annotation which is more flexible as it can be placed on methods, too. But I am happy to adjust either way.

@JonasKunz
Copy link
Contributor

We decided to go with just the internal package. I'll update your PR and merge it afterwards.

@JonasKunz
Copy link
Contributor

run elasticsearch-ci/docs

@JonasKunz JonasKunz merged commit 48d2a23 into elastic:main Jul 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
8.10-candidate agent-java community Issues and PRs created by the community
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants