How to use Java 11 Java Flight Recorder JFR library with Wildfly 16

1.2k Views Asked by At

Background

I'm working on jboss/wildfly 16 servlet mypackagex.war. It's a maven project. My server uses openjdk11-jdk. I managed to run the produce a java flight recording using jcmd. And managed to open that jfr dump with JDK Mission Control. All nice and dandy.

JPID=616
jcmd $JPID JFR.configure repositorypath=/tmp/jcmdrecording/
jcmd $JPID JFR.start settings=default.jfc name=recording1 filename=JFRfile.jfr disk=true dumponexit=true  maxage=2d maxsize=2000m  path-to-gc-roots=true
jcmd $JPID JFR.check
jcmd $JPID JFR.dump /tmp/recording1.jfr

The Issue

When I tried to do a custom event recording programmatically like the example below. I get an error. It's as if wildfly don't know jdk.jfr.Event exists. What did I miss?

Declaring a custom event recorder example

package com.mypackagex.dao;

import jdk.jfr.Category;
import jdk.jfr.Event;
import jdk.jfr.Label;
import jdk.jfr.Period;

@Label("Database stats")
@Period("1 s")
@Category("Database")
public class DatabaseStatsEvent extends Event {
}

Code location to take the flight recording event

public class UrlObjectActionMapperDAO {
    private static String jndiDataSourceName = "jdbc/cedar_mypackagex_security";
    private static DataSource dataSource = getDataSourceFromJNDI();
    
    static Logger logger = LoggerFactory.getLogger(UrlObjectActionMapperDAO.class);

    private static DataSource getDataSourceFromJNDI() {

        return DatasourceProvider.getProvider().getDsSecurity();
    }
    
    public UrlObjectActionMapperDTO getURLMappedProps(String URI){
        
        DatabaseStatsEvent ev =  new DatabaseStatsEvent();         // --------- line 49 the issue!
        ev.begin();
        
        return null;
    }
    
}

The error Scroll to the right where you'll see jdk/jfr/Event

local-mypackagex            | Caused by: java.lang.NoClassDefFoundError: Failed to link com/mypackagex/dao/DatabaseStatsEvent (Module "deployment.mypackagex.war" from Service Module Loader): jdk/jfr/Event
local-mypackagex            |   at deployment.mypackagex.war//com.mypackagex.dao.UrlObjectActionMapperDAO.getURLMappedProps(UrlObjectActionMapperDAO.java:49)
local-mypackagex            |   at deployment.mypackagex.war//com.mypackagex.services.RBACService.getURLMappedProps(RBACService.java:70)
local-mypackagex            |   at deployment.mypackagex.war//com.mypackagex.servlet.RBACFilter.validateRequest(RBACFilter.java:465)
local-mypackagex            |   at deployment.mypackagex.war//com.mypackagex.servlet.RBACFilter.validateRequest(RBACFilter.java:450)
local-mypackagex            |   at deployment.mypackagex.war//com.mypackagex.servlet.RBACFilter.doFilter(RBACFilter.java:235)
local-mypackagex            |   at [email protected]//io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
local-mypackagex            |   at [email protected]//io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
local-mypackagex            |   at deployment.mypackagex.war//com.mypackagex.servlet.ProxyResponseBuilderFilter.doFilter(ProxyResponseBuilderFilter.java:456)
local-mypackagex            |   at [email protected]//io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
local-mypackagex            |   at [email protected]//io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
local-mypackagex            |   at deployment.mypackagex.war//org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)
local-mypackagex            |   at deployment.mypackagex.war//org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)
local-mypackagex            |   at deployment.mypackagex.war//org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
local-mypackagex            |   at deployment.mypackagex.war//org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
local-mypackagex            |   at deployment.mypackagex.war//org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:387)
local-mypackagex            |   at deployment.mypackagex.war//org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)
2

There are 2 best solutions below

1
On

I had the identical hassle and will resolve it in Wildfly 15 (the use of Java 11) But beware, I were given this by and large through trial-and-mistakess and don`t absolutely apprehend the outcomes and why jdk.jfr isn't covered via way of means of default. I additionally do not know how this works out on different wildly versions.

0
On

I had the same problem and could solve it in Wildfly 15 (using Java 11):

Make sure your jboss-deployment-structure.xml contains:

<jboss-deployment-structure>
    <deployment>
        <dependencies>
            <module name="jdk.jfr"/>
        </dependencies>
    </deployment>
</jboss-deployment-structure>

But beware, I got this mostly via trial-and-error and don't wholly understand the consequences and why jdk.jfr is not included by default.

I also don't know how this works out on other wildfly versions.