Speed up java agent type matching - #21473
Conversation
Narrow Byte Buddy matchers to known JDK classes to avoid running subtype check on all loaded classes. Match on class name instead of exact class type. Signed-off-by: tim <7452348+timlueg@users.noreply.github.com>
PR Reviewer Guide 🔍(Review updated until commit d6891f1)Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Latest suggestions up to d6891f1 Explore these optional code suggestions:
Previous suggestionsSuggestions up to commit e9c6fe2
Suggestions up to commit e664df3
Suggestions up to commit d262bfb
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #21473 +/- ##
============================================
+ Coverage 73.34% 73.41% +0.07%
- Complexity 74353 74416 +63
============================================
Files 5967 5967
Lines 338227 338233 +6
Branches 48754 48754
============================================
+ Hits 248061 248314 +253
+ Misses 70399 70120 -279
- Partials 19767 19799 +32 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Signed-off-by: tim <7452348+timlueg@users.noreply.github.com>
|
Persistent review updated to latest commit e664df3 |
|
❌ Gradle check result for e664df3: FAILURE Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change? |
|
Persistent review updated to latest commit e9c6fe2 |
|
❌ Gradle check result for e9c6fe2: FAILURE Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change? |
| final Junction<TypeDescription> pathType = ElementMatchers.isSubTypeOf(Files.class); | ||
| final Junction<TypeDescription> fileChannelType = ElementMatchers.isSubTypeOf(FileChannel.class); | ||
| final Junction<TypeDescription> fileSystemProviderType = ElementMatchers.isSubTypeOf(FileSystemProvider.class); | ||
| final Junction<TypeDescription> socketType = ElementMatchers.nameStartsWith(Socket.class.getPackageName() + ".") |
There was a problem hiding this comment.
@timlueg @cwperks I am afraid this slippery road: the JDK evolves, the assumptions invalidate fast. Where the decision which package to take into consideration are coming from?
Please, correct me if I am missing something, but clearly we are excluding sun.security.ssl.SSLSocketImpl (JDK) and any user class that implement SocketChannel or Socket by package filters?
There was a problem hiding this comment.
Agree the PR suggestion is not an ideal solution. I selected the JDK packages where I found the relevant Subclasses.
SSLSocketImpl is excluded. But SSLSocketImpl.connect() delegates to java.net.Socket.connect() which is matched. But it is better to still include the package explicitly.
Right, user classes that extend e.g. Socket would no longer be matched unless they delegate like above.
(My understanding is that these Agent matcher(s) cover the most common cases. Because I can imagine a arbitrary user class could for example open a connection without using a Socket subclass.)
There was a problem hiding this comment.
(My understanding is that these Agent matcher(s) cover the most common cases. Because I can imagine a arbitrary user class could for example open a connection without using a Socket subclass.)
Thanks @timlueg , I think we should be covering any possible scenario (API set is very limited), otherwise the agent is not really serving the purpose
|
❌ Gradle check result for e9c6fe2: FAILURE Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change? |
Signed-off-by: tim <7452348+timlueg@users.noreply.github.com>
|
Persistent review updated to latest commit d6891f1 |
|
❌ Gradle check result for d6891f1: null Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change? |
Description
From what I understand it should be possible to narrow the java agent bytebuddy matchers to JDK own classes. This avoids running the expensive
isSubTypeOfcheck for all classes. Additionally usingnamed()instead of theis()type check.As I understand it any subclass of e.g.
FileSystemProviderwould now not be instrumented at the class level but since this subclass would normally uses JDK classes to access the file system these would still be instrumented.Time to Node "started" best of 5:
./gradlew run./gradlew runwith plugins./gradlew run -PinstalledPlugins=...
./gradlew run -PinstalledPlugins="['opensearch-job-scheduler', 'opensearch-notifications-core', 'notifications', 'opensearch-ml-plugin', 'opensearch-knn', 'alerting', 'opensearch-anomaly-detection', 'asynchronous-search', 'opensearch-cross-cluster-replication', 'opensearch-custom-codecs', 'opensearch-flow-framework', 'geospatial', 'opensearch-index-management', 'opensearch-skills', 'neural-search', 'opensearch-observability', 'opensearch-reports-scheduler', 'opensearch-sql-plugin', 'query-insights', 'opensearch-system-templates', 'opensearch-ubi', 'opensearch-search-relevance', 'workload-management']"Related Issues
Resolves #[Issue number to be closed when this PR is merged]
Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.