Skip to content

Commit 2329be9

Browse files
committed
GraalVM Native JMXFetch smoke test
1 parent 03e3c12 commit 2329be9

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

dd-smoke-tests/spring-boot-3.0-native/application/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ if (hasProperty('agentPath')) {
3939
if (withProfiler && property('profiler') == 'true') {
4040
buildArgs.add("-J-Ddd.profiling.enabled=true")
4141
}
42+
buildArgs.add("--enable-monitoring=jmxserver")
4243
}
4344
}
4445
}

dd-smoke-tests/spring-boot-3.0-native/src/test/groovy/SpringBootNativeInstrumentationTest.groovy

+40-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import datadog.smoketest.AbstractServerSmokeTest
2+
import datadog.trace.agent.test.utils.PortUtils
23
import okhttp3.Request
34
import org.openjdk.jmc.common.item.IItemCollection
45
import org.openjdk.jmc.common.item.ItemFilters
@@ -13,6 +14,10 @@ import java.nio.file.Files
1314
import java.nio.file.Path
1415
import java.nio.file.SimpleFileVisitor
1516
import java.nio.file.attribute.BasicFileAttributes
17+
import java.util.concurrent.CompletableFuture
18+
import java.util.concurrent.Executors
19+
import java.util.concurrent.TimeUnit
20+
import java.util.concurrent.TimeoutException
1621
import java.util.concurrent.atomic.AtomicInteger
1722
import java.util.concurrent.locks.LockSupport
1823

@@ -21,6 +26,9 @@ class SpringBootNativeInstrumentationTest extends AbstractServerSmokeTest {
2126
@TempDir
2227
def testJfrDir
2328

29+
@Shared
30+
def statsdPort = PortUtils.randomOpenPort()
31+
2432
@Override
2533
ProcessBuilder createProcessBuilder() {
2634
String springNativeExecutable = System.getProperty('datadog.smoketest.spring.native.executable')
@@ -39,7 +47,10 @@ class SpringBootNativeInstrumentationTest extends AbstractServerSmokeTest {
3947
'-Ddd.profiling.upload.period=1',
4048
'-Ddd.profiling.start-force-first=true',
4149
"-Ddd.profiling.debug.dump_path=${testJfrDir}",
42-
"-Ddd.integration.spring-boot.enabled=true"
50+
"-Ddd.integration.spring-boot.enabled=true",
51+
"-Ddd.trace.debug=true",
52+
"-Ddd.jmxfetch.statsd.port=${statsdPort}",
53+
"-Ddd.jmxfetch.start-delay=0",
4354
])
4455
ProcessBuilder processBuilder = new ProcessBuilder(command)
4556
processBuilder.directory(new File(buildDirectory))
@@ -66,8 +77,18 @@ class SpringBootNativeInstrumentationTest extends AbstractServerSmokeTest {
6677
super.isErrorLog(log) || log.contains("ClassNotFoundException")
6778
}
6879

80+
def setupSpec() {
81+
try {
82+
processTestLogLines { it.contains("JMXFetch config: ") }
83+
} catch (TimeoutException toe) {
84+
throw new AssertionError("'JMXFetch config: ' not found in logs. Make sure it's enabled.", toe)
85+
}
86+
}
87+
6988
def "check native instrumentation"() {
7089
setup:
90+
CompletableFuture<String> udpMessage = receiveUdpMessage(statsdPort, 1000)
91+
7192
String url = "http://localhost:${httpPort}/hello"
7293

7394
when:
@@ -87,6 +108,8 @@ class SpringBootNativeInstrumentationTest extends AbstractServerSmokeTest {
87108
LockSupport.parkNanos(1_000_000)
88109
}
89110
countJfrs() > 0
111+
112+
udpMessage.get(1, TimeUnit.SECONDS) contains "service:smoke-test-java-app,version:99,env:smoketest"
90113
}
91114

92115
int countJfrs() {
@@ -115,4 +138,20 @@ class SpringBootNativeInstrumentationTest extends AbstractServerSmokeTest {
115138
})
116139
return jfrCount.get()
117140
}
141+
142+
CompletableFuture<String> receiveUdpMessage(int port, int bufferSize) {
143+
def future = new CompletableFuture<String>()
144+
Executors.newSingleThreadExecutor().submit {
145+
try (DatagramSocket socket = new DatagramSocket(port)) {
146+
byte[] buffer = new byte[bufferSize]
147+
DatagramPacket packet = new DatagramPacket(buffer, buffer.length)
148+
socket.receive(packet)
149+
def received = new String(packet.data, 0, packet.length)
150+
future.complete(received)
151+
} catch (Exception e) {
152+
future.completeExceptionally(e)
153+
}
154+
}
155+
return future
156+
}
118157
}

0 commit comments

Comments
 (0)