|
| 1 | +import com.zaxxer.hikari.pool.ProxyLeakTask |
| 2 | +import datadog.trace.agent.test.AgentTestRunner |
| 3 | +import datadog.trace.bootstrap.instrumentation.jfr.InstrumentationBasedProfiling |
| 4 | +import jdk.jfr.Recording |
| 5 | +import org.openjdk.jmc.common.item.Attribute |
| 6 | +import org.openjdk.jmc.common.item.IAttribute |
| 7 | +import org.openjdk.jmc.common.item.ItemFilters |
| 8 | +import org.openjdk.jmc.common.unit.UnitLookup |
| 9 | +import org.openjdk.jmc.flightrecorder.JfrLoaderToolkit |
| 10 | +import spock.lang.Shared |
| 11 | + |
| 12 | +import java.nio.file.Files |
| 13 | + |
| 14 | +class KnownExcludesForkedTest extends AgentTestRunner { |
| 15 | + private static final IAttribute<String> TYPE = |
| 16 | + Attribute.attr("type", "type", "Exception type", UnitLookup.PLAIN_TEXT) |
| 17 | + |
| 18 | + @Shared |
| 19 | + Recording recording |
| 20 | + |
| 21 | + @Override |
| 22 | + protected void configurePreAgent() { |
| 23 | + super.configurePreAgent() |
| 24 | + injectSysConfig("profiling.enabled", "true") |
| 25 | + injectSysConfig("profiling.start-force-first", "true") |
| 26 | + } |
| 27 | + |
| 28 | + def setupSpec() { |
| 29 | + recording = new Recording() |
| 30 | + recording.enable("datadog.ExceptionCount") |
| 31 | + recording.start() |
| 32 | + InstrumentationBasedProfiling.enableInstrumentationBasedProfiling() |
| 33 | + } |
| 34 | + |
| 35 | + def "obey excluded"() { |
| 36 | + when: |
| 37 | + println("Generating exceptions ...") |
| 38 | + for (int i = 0; i < 50; i++) { |
| 39 | + new ProxyLeakTask() |
| 40 | + new NullPointerException() |
| 41 | + } |
| 42 | + println("Exceptions generated") |
| 43 | + |
| 44 | + def tempPath = Files.createTempDirectory("test-recording") |
| 45 | + def recFile = tempPath.resolve(KnownExcludesForkedTest.name.replace('.', '_') + ".jfr") |
| 46 | + recFile.toFile().deleteOnExit() |
| 47 | + recording.dump(recFile) |
| 48 | + recording.stop() |
| 49 | + |
| 50 | + def events = JfrLoaderToolkit.loadEvents(recFile.toFile()).apply(ItemFilters.type("datadog.ExceptionCount")) |
| 51 | + |
| 52 | + then: |
| 53 | + events.apply(ItemFilters.equals(TYPE, NullPointerException.canonicalName)).hasItems() |
| 54 | + !events.apply(ItemFilters.equals(TYPE, ProxyLeakTask.canonicalName)).hasItems() |
| 55 | + } |
| 56 | +} |
0 commit comments