Commit Graph

350 Commits

Author SHA1 Message Date
Jean-Philippe Bempel efe8ee375b
Merge pull request #1226 from jpbempel/jpbempel/reuseKeys
Enable reuseKeys on WeakConcurrentMap
2020-02-18 19:09:05 +01:00
Nikolay Martynov fd75575796 Disable peer hostname tag for http servers
Getting peer hostname makes DNS request
2020-02-14 11:25:07 -05:00
jean-philippe bempel 58b1cff62e Enable reuseKeys on WeakConcurrentMap
for each call to get method in WeakConcurrentMap, a LatentKey is
created. Considering the frequency of call it's significant.
Also, the classloader of the tracer can be considered as permanent
through the lifecycle of the JVM which is a prerequisite to be able
to reuse keys (otherwise classloader leak).
2020-02-14 14:52:59 +01:00
Nikolay Martynov fd58187994 Support JFR profiling 2020-02-11 14:55:19 -05:00
Laplie Anderson 9023c6e1c7 Fix a couple tests using the wrong arguments 2020-02-11 11:44:46 -05:00
Laplie Anderson 3c0877e38a Create a shared parent classloader 2020-02-11 11:42:39 -05:00
Tyler Benson 032f22f5a6
Reduce tracer thread count by combining scheduled executors int… (#1200)
Reduce tracer thread count by combining scheduled executors into a single executor.
2020-02-11 08:18:59 -08:00
Tyler Benson 51bffa2e8a Move agent api classes to bootstrap package so they're not analyzed by muzzle
Also move jdbc classes to bootstrap to reduce size and complexity of those reference checkers.

These changes reduce the total file size of these instrumentation classes by 635k, which should also result in decent memory savings.
2020-02-10 15:09:15 -08:00
Tyler Benson 486d98135e Code review changes 2020-02-10 11:37:36 -08:00
Tyler Benson e5980d4812 Fix muzzle 2020-02-10 10:45:58 -08:00
Tyler Benson 75c7769192 Reduce tracer thread count by combining scheduled executors into a single executor.
Pulls out utility classes for reuse by other projects.

This also meant the dependency had to be bundled with dd-trace-ot since it isn't published as a separate dependency.
2020-02-10 10:45:58 -08:00
Lev Priima 5265a43c6d Reduce use of Thread::setContextClassLoader 2020-02-06 22:53:04 -05:00
dougqh faeb069424 Adjusting capacity check again 2020-01-30 18:08:49 -05:00
dougqh 235a6470fb googleJavaFormat 2020-01-30 17:45:40 -05:00
dougqh 0f095f0adb Final clean-up
- Removed unused method from earlier version
- Corrected previously overlooked comments that were remnant of prior version
2020-01-30 17:44:24 -05:00
dougqh 176f826a44 Adjusting approximateSize check to be more reliable 2020-01-27 17:44:39 -05:00
dougqh 4c7a0ba7a7 Fixing muzzle?
MuzzlePlugin groovy checks that no threads are spawned because this holds the ClassLoader live.

This was breaking with the caching change because the cache no longer uses the Cleaner service.

This caused a problem because the Thread behind the cleaner is created lazily when the first task is created, but without the cache the creation was delayed.

To solve this, I addressed the original cause of the leak.  The newly created Thread automatically inherits the contextClassLoader of its parent, but that's unnecessary for a cleaner thread.

So I changed the ThreadFactory for cleaner to explicitly null out the contextClassLoader.

We should probably null out contextClassLoader in other thread factories and also reduce our use of contextClassLoaders in general, but that will left to another PR.
2020-01-27 17:14:17 -05:00
dougqh d50f901f39 googleJavaFormat, codeNarcTest, and test reliability 2020-01-27 12:34:39 -05:00
dougqh fb871611b5 Replacing ID generation with WeakReference reuse
First pass at replacing ID generation with WeakReference reuse

In this first version, the Cache<ClassLoader, ID> was replaced with Cache<ClassLoader, WeakReference<ClassLoader>>.

The core cache is still of Cache<TypeCacheKey, TypePool.Resolution> and TypeCacheKey logically remains a composite key of ClassLoader, class name.

The removal of ID assignment means ID exhaustion is no longer na issue, so there's never a need to rebuild the cache.  For that reason, CacheInstance has removed and the core caching logic has been moved into DDCachingPoolStrategy.

While TypeCacheKey remains conceptually the same, the internals have changed somewhat.  The TypeCacheKey now has 3 core fields...
- loaderHash
- loadeRef
- class name

Since loader refs are recycled, the fast path for key equivalence can use reference equivalence of the reference objects.

This change ripples through the CacheProvider-s which also have to store loaderHash and loaderRef.

It may be worth going a step further and switching to a Cache<Loader, TypePool> as well.  That still avoid the creation of many WeakReference-s, since the underlying CacheProvider will hold a canonical WeakReference per ClassLoader.
2020-01-27 12:03:44 -05:00
dougqh cf877f67e5 Working around muzzle quirk
Muzzle doesn't like creation of SecureClassLoader-s, so switching to a URLClassLoader for my placeholder loader in tests
2020-01-27 09:47:36 -05:00
dougqh 984d77e44c googleJavaFormat & codeNarc 2020-01-23 11:15:39 -05:00
dougqh 726236bd64 Type cache overhaul
This change overhauls the core type cache

The new approach aims to achieve several things...
1 - cache is strictly bounded -- no variance for number of classes of ClassLoaders
2 - cache is significantly smaller
3 - cache doesn't compromise start-up time
4 - primary eviction policy isn't driven by time
5 - primary eviction policy isn't driven by GC

There are some slight compromises here.
In practice, start-up does increase slightly in a memory rich environment; however, start-up improves considerably in a memory poor environment.

The basic approcach is to have a single unified Guava cache for all ClassLoaders -- nominally keyed a composite of ClassLoader & class name

The ByteBuddy CacheProvider are simply thin wrappers around the Guava cache associated to a particular ClassLoader

However rather than having a large number of WeakReferences floating around.  The cache assigns an ID to each ClassLoader.

To further avoid, consuming memory the cache only preserves a small map of Loader / ID assignments.  This means a ClassLoader may have more than one active ID.

This introduce the possibility for ID exhaustion.  That unlikely case is handle by retiring the internal CacheInstance and starting anew.
2020-01-23 10:55:16 -05:00
Laplie Anderson 6766e12597
Merge pull request #1173 from DataDog/landerson/weakmap-computeifabsent
Synchronized audit: WeakMap computeIfAbsent
2020-01-15 14:51:29 -05:00
Laplie Anderson 68ed1da9c6 Don't call `map.get()` in the `put(..)` case 2020-01-15 12:41:01 -05:00
Laplie Anderson a0b1cd4a75 WeakMap computeIfAbsent 2020-01-15 12:26:15 -05:00
Tyler Benson e31cbd6c89 Add Builder to DDTracer
Deprecate previous constructors.
2020-01-14 17:44:34 -08:00
Tyler Benson 5fe26f004b Remove more declared method filtering for optimization
Same logic that was applied in #1169
2020-01-13 12:52:41 -08:00
Laplie Anderson 6b6554996a
Merge pull request #1155 from DataDog/landerson/muzzle-scan-classloader-matcher
Add classloader matcher to muzzle scan
2019-12-30 10:12:59 -05:00
Pawel Chojnacki 65c701dd51
Merge pull request #1128 from DataDog/pawel/add_rmi_support
Add RMI support
2019-12-23 14:38:46 +01:00
Laplie Anderson f181fa721f Add classloader matcher to muzzle scan 2019-12-20 16:17:08 -05:00
Pawel Chojnacki 832605a01a [rmi] Add distributed context propagation
The flow for context propagation is as follows.

 * <p>We inject into StreamRemoteCall constructor used for invoking remote tasks and performs a
 * backwards compatible check to ensure if the other side is prepared to receive context propagation
 * messages then if successful sends a context propagation message
 *
 * <p>Context propagation consist of a Serialized HashMap with all data set by usual context
 * injection, which includes things like sampling priority, trace and parent id
 *
 * <p>As well as optional baggage items
 *
 * <p>On the other side of the communication a special Dispatcher is created when a message with
 * DD_CONTEXT_CALL_ID is received.
 *
 * <p>If the server is not instrumented first call will gracefully fail just like any other unknown
 * call. With small caveat that this first call needs to *not* have any parameters, since those will
 * not be read from connection and instead will be interpreted as another remote instruction, but
 * that instruction will essentially be garbage data and will cause the parsing loop to throw exception
 * and shutdown the connection which we do not want
2019-12-19 17:21:07 +01:00
Pawel Chojnacki 0ee80a0b95 [rmi] Instrumentation for RMI 1.2 and later
includes instrumentation of client and server endpoints
currently missing passing of execution context from client to server
2019-12-19 17:20:50 +01:00
kfujita b707a3aab9 move multi-value aware logic to Extractor. 2019-12-19 13:33:08 +09:00
Laplie Anderson d2db6b6fd9
Merge pull request #1098 from DataDog/tyler/jax-rs-annotation-inheritance
Support JAX-RS Annotation Inheritance
2019-12-06 13:49:46 -05:00
Laplie Anderson 42ac5fc024 Remove synchronization and static helper map 2019-12-04 15:43:28 -05:00
Laplie Anderson 7640e68337 The same classwalking is necessary for @Path 2019-11-20 13:07:04 -05:00
Tyler Benson 393a88585a First pass at supporting annotations inheritance for JAX-RS
[skip ci]
2019-11-15 11:53:16 -08:00
Laplie Anderson 251ceeb978 Print all instrumentation names when muzzled 2019-11-13 14:12:26 -05:00
Nikolay Martynov 2789324cd5
Merge pull request #1084 from DataDog/mar-kolya/fix-agent-for-zulu8
fix agent for zulu8
2019-11-07 14:39:03 -05:00
Douglas Q Hawkins 599d1e0fab
Merge pull request #1082 from DataDog/dougqh/sisu-exclusion
Excluded classes generated by Eclipse Sisu
2019-11-06 14:41:36 -05:00
Nikolay Martynov 42cece67c2 Fix namespace clashes
Using `datadog.trace.agent` to hold agent class causes problems due to
shadowing into this package of other classes.
2019-11-06 13:58:20 -05:00
Nikolay Martynov 15c1e67334 Fix agent on latest zulu8
The problem was that on zulu8 loading OkHttp touches JFR which in turn
touches log manager - which would break things like JBOSS.

The fix is to delay installing agent (and writer) until log manager
things have settled down - in way similar to jmxfetch.

Unfortunately for 'main' agent this turns out to be more involved
because of classloader shenanigans.
2019-11-06 10:09:50 -05:00
dougqh 270a440162 Excluded classes generated by Eclipse Sisu
This change excludes classes generated by Eclipse Sisu (part of Equinox DS).

These classes are created by https://github.com/eclipse/sisu.inject/blob/master/org.eclipse.sisu.inject/src/org/eclipse/sisu/space/CloningClassSpace.java
2019-11-05 15:20:52 -05:00
Nikolay Martynov 7f5b270c67 Call class loading callbacks from onComplete
This should make things more clear
2019-11-05 13:08:21 -05:00
Tyler Benson 425156115c Add new integration for Servlet Filters, HttpServlet, and RequestDispatcher
Disabled by default, and only creates a span if existing trace detected.

To enable all of them:
* System Property: `-Ddd.integration.servlet.enabled=true`
* Environment Variable: `DD_INTEGRATION_SERVLET_ENABLED=true`

(They have independent configs as well.  If needed, view the source below.)
2019-10-25 14:47:48 -07:00
Tyler Benson fa80fee15d Refactor JAX-RS Annotation and Spring Controller/Handler Instrumentation
For spring:
* Move more logic to the decorator.
* Use a fixed operation name, but set the resource name.
* Rename the root span instead of the parent span (If there are other spans in between this could make a difference.)  Not sure what impact this would have if multiple controllers are called (ie, forward/include).

For Jax-rs:
* Rename the root span instead of the parent span (same concern as above with spring)
2019-10-25 10:19:25 -07:00
Trask Stalnaker d45b571996 Remove unused code 2019-10-24 20:53:13 -07:00
Trask Stalnaker b0c5b2cd78 Remove deprecated methods 2019-10-19 16:52:43 -07:00
Trask Stalnaker f67e3b98db Migrate base decorators to new agent api 2019-10-19 16:40:52 -07:00
Tyler Benson 126dc67181 Update AgentApi to OT 0.32.0 2019-10-17 14:11:07 -07:00