|
| 1 | +package datadog.smoketest |
| 2 | + |
| 3 | +import okhttp3.Request |
| 4 | +import org.openjdk.jmc.common.item.ItemFilters |
| 5 | +import org.openjdk.jmc.flightrecorder.JfrLoaderToolkit |
| 6 | +import org.openjdk.jmc.flightrecorder.internal.InvalidJfrFileException |
| 7 | +import spock.lang.Shared |
| 8 | +import spock.lang.TempDir |
| 9 | +import spock.util.concurrent.PollingConditions |
| 10 | + |
| 11 | +import java.nio.file.FileVisitResult |
| 12 | +import java.nio.file.Files |
| 13 | +import java.nio.file.Path |
| 14 | +import java.nio.file.SimpleFileVisitor |
| 15 | +import java.nio.file.attribute.BasicFileAttributes |
| 16 | +import java.util.concurrent.atomic.AtomicInteger |
| 17 | + |
| 18 | +/** |
| 19 | + * Smoke test for profiling in Quarkus native images. |
| 20 | + * |
| 21 | + * This test validates the fix for issue #10446 where Quarkus native image builds |
| 22 | + * failed with ClassNotFoundException for profiler classes (BufferWriter9, etc.). |
| 23 | + * The fix requires proper GraalVM native-image configuration to defer profiler |
| 24 | + * class initialization to runtime. |
| 25 | + * |
| 26 | + * Test validates: |
| 27 | + * 1. Native image builds successfully with profiling enabled (no ClassNotFoundException) |
| 28 | + * 2. Application starts without agent initialization errors |
| 29 | + * 3. Profiler produces JFR files at runtime |
| 30 | + */ |
| 31 | +class QuarkusNativeProfilingSmokeTest extends QuarkusSlf4jSmokeTest { |
| 32 | + |
| 33 | + @Shared |
| 34 | + @TempDir |
| 35 | + Path testJfrDir |
| 36 | + |
| 37 | + @Override |
| 38 | + protected List<String> additionalArguments() { |
| 39 | + return [ |
| 40 | + "-Ddd.profiling.upload.period=1", |
| 41 | + "-Ddd.profiling.start-force-first=true", |
| 42 | + "-Ddd.profiling.debug.dump_path=${testJfrDir}".toString(), |
| 43 | + // TODO: Remove this arg after JFR initialization is fixed on GraalVM 25. |
| 44 | + // https://datadoghq.atlassian.net/browse/PROF-12742 |
| 45 | + "-XX:StartFlightRecording=filename=${testJfrDir}/recording.jfr".toString(), |
| 46 | + ] |
| 47 | + } |
| 48 | + |
| 49 | + def "profiling works in native image"() { |
| 50 | + setup: |
| 51 | + String url = "http://localhost:${httpPort}/${endpointName}?id=1" |
| 52 | + def conditions = new PollingConditions(initialDelay: 2, timeout: 10) |
| 53 | + |
| 54 | + when: |
| 55 | + // Make a request to generate some activity for the profiler |
| 56 | + def response = client.newCall(new Request.Builder().url(url).get().build()).execute() |
| 57 | + |
| 58 | + then: |
| 59 | + response.code() == 200 |
| 60 | + response.body().string() == "Hello 1!" |
| 61 | + |
| 62 | + // Wait for JFR files with execution samples to be generated |
| 63 | + conditions.eventually { |
| 64 | + assert countJfrsWithExecutionSamples() > 0 |
| 65 | + } |
| 66 | + } |
| 67 | + |
| 68 | + int countJfrsWithExecutionSamples() { |
| 69 | + AtomicInteger jfrCount = new AtomicInteger(0) |
| 70 | + Files.walkFileTree(testJfrDir, new SimpleFileVisitor<Path>() { |
| 71 | + @Override |
| 72 | + FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { |
| 73 | + if (file.toString().endsWith(".jfr")) { |
| 74 | + try { |
| 75 | + def events = JfrLoaderToolkit.loadEvents(file.toFile()) |
| 76 | + if (events.apply(ItemFilters.type("jdk.ExecutionSample")).hasItems()) { |
| 77 | + jfrCount.incrementAndGet() |
| 78 | + return FileVisitResult.SKIP_SIBLINGS |
| 79 | + } |
| 80 | + } catch (InvalidJfrFileException ignored) { |
| 81 | + // The recording captured at process exit might be incomplete |
| 82 | + } |
| 83 | + } |
| 84 | + return FileVisitResult.CONTINUE |
| 85 | + } |
| 86 | + }) |
| 87 | + return jfrCount.get() |
| 88 | + } |
| 89 | +} |
0 commit comments