Skip to content

Move the adaptive sampler to a shared location.#2418

Merged
jbachorik merged 12 commits into
masterfrom
jb/shared_adaptive_sampler
Mar 5, 2021
Merged

Move the adaptive sampler to a shared location.#2418
jbachorik merged 12 commits into
masterfrom
jb/shared_adaptive_sampler

Conversation

@jbachorik
Copy link
Copy Markdown
Contributor

The rate limiting sampler is not specific to exception profiling only so it should live in a more generic space.

The change is rather harmless - just moving the actual sampler implementation to internal-api project. Since the agent-bootstrap already depends on internal-api no further changes are needed.

The rate limiting sampler is not specific to exception profiling only so it should live in a more generic space.
@jbachorik jbachorik requested a review from a team as a code owner February 18, 2021 15:47
Comment thread internal-api/internal-api.gradle Outdated
@@ -1,3 +1,7 @@
ext {
enableJunitPlatform = true
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✌🏻

Comment thread internal-api/internal-api.gradle Outdated
Comment on lines +47 to +50
compileTestJava {
sourceCompatibility = 8
targetCompatibility = 8
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Does this mean we no longer test internal-api on JDK7?

Copy link
Copy Markdown
Contributor

@richardstartin richardstartin left a comment

Choose a reason for hiding this comment

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

We can't stop compiling and testing internal-api on JDK7. Perhaps extract an interface and move the implementation into a JDK8 module under utils, with a stub implementation and a factory, then load the JDK8 implementation based on a version check.

*/
StreamingSampler(
public AdaptiveSampler(
final Duration windowDuration,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

(Stating the obvious) Java time was introduced in JDK8, so this implementation would need to be moved out of internal-api

@jbachorik
Copy link
Copy Markdown
Contributor Author

Well, my intention was to have just the one source root to be compiled with Java 8 to avoid creating a new module just for this one class. Apparently, it is not that easy even with the gradle black magic :(

BTW, with move to ASM 9 to support JDK 16 bytecode level the support for Java 7 will be gone as ASM itself is compiled to level 52 (Java 8) 🤷

@jbachorik
Copy link
Copy Markdown
Contributor Author

The AdaptiveSampler implementation has been moved to a separate submodule of internal-api.

Since it is used in an already Java 8+ code in the bootstrap I would like to avoid jumping through several facade/reflection hoops in order to use it. The appropriate checks are done at the top level when the whole profiler subsystem is enabled for Java 8+.

@richardstartin richardstartin self-requested a review February 19, 2021 11:24
@richardstartin
Copy link
Copy Markdown
Contributor

richardstartin commented Feb 19, 2021

BTW, with move to ASM 9 to support JDK 16 bytecode level the support for Java 7 will be gone as ASM itself is compiled to level 52 (Java 8) 🤷

Yes, I agree, maintaining support for JDK7 is holding us back, but we have users on JDK7 and can't drop it until the product decision has been made.

@jbachorik
Copy link
Copy Markdown
Contributor Author

we have users on JDK7 and can't drop it until the product decision has been made

My (slightly offtopic) point was that with ASM 9 you don't have the choice any more :(

Anyway, for this PR I pulled out the Java 8 specific code to a separate module to make it more explicit (also, it makes the build much simpler).

@richardstartin
Copy link
Copy Markdown
Contributor

My (slightly offtopic) point was that with ASM 9 you don't have the choice any more :(

I got it, and this will force the issue soon, as it presents a dichotomy between JDK7 and JDK17

compileMain_java11Java.targetCompatibility = JavaVersion.VERSION_1_8
dependencies {
main_java11CompileOnly project(':internal-api')
main_java11Compile project(':internal-api:internal-api-8')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why compileOnly -> compile?

@richardstartin
Copy link
Copy Markdown
Contributor

This looks problematic

java.lang.NoClassDefFoundError: datadog/trace/api/sampling/AdaptiveSampler
	at datadog.trace.bootstrap.instrumentation.exceptions.ExceptionSampler.<init>(ExceptionSampler.java:25)
	at datadog.trace.bootstrap.instrumentation.exceptions.ExceptionSampler.<init>(ExceptionSampler.java:21)
	at datadog.trace.bootstrap.instrumentation.exceptions.ExceptionProfiling.<init>(ExceptionProfiling.java:26)
	at datadog.trace.bootstrap.instrumentation.exceptions.ExceptionProfiling.<clinit>(ExceptionProfiling.java:11)
	at java.lang.Class.forName(Class.java:377)
	at AgentTestRunnerTest.classpath setup(AgentTestRunnerTest.groovy:50)

@jbachorik
Copy link
Copy Markdown
Contributor Author

👋 All tests are finally passing 🎉

}

apply from: "$rootDir/gradle/java.gradle"
apply plugin: "idea"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is probably not needed.

class StreamingSamplerTest {

class AdaptiveSamplerTest {
private static final Logger log = LoggerFactory.getLogger(AdaptiveSamplerTest.class);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Use @Slf4j on class instead.

@jbachorik jbachorik merged commit 0d6a139 into master Mar 5, 2021
@jbachorik jbachorik deleted the jb/shared_adaptive_sampler branch March 5, 2021 14:05
@github-actions github-actions Bot added this to the 0.76.0 milestone Mar 5, 2021
@tylerbenson tylerbenson added the tag: no release notes Changes to exclude from release notes label Mar 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tag: no release notes Changes to exclude from release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants