Chapter 8. Setting up Quarkus applications for HawtIO Online with Jolokia This section describes the enabling of monitoring of a Quarkus application by HawtIO. It starts from first principles in setting up a simple example application. However, should a Quarkus application already have been implemented then skip to " Enabling Jolokia Java-Agent on the Example Quarkus Application ". For convenience, an example project based on this documentation has already been implemented and published here . Simply clone its parent repository and jump to " Deployment of the HawtIO-Enabled Quarkus Application to OpenShift ". Explanation of Hawtio Online Component Any interactions either from users or Hawtio are communicated with the HTTP protocol to an Nginx web server The Nginx web server is the outward-facing interface and the only sub-component visible to external consumers When a request is made, the Nginx web server hands off to the internal Gateway component, which serves 2 distinct purposes: Master-Guard Agent Any request directed towards the target Master Cluster API Server (OpenShift) must pass through this component where checks are made to ensure the requested endpoint URL is approved. URLs that are not approved, eg. requests to secrets or configmaps (potentially security sensitive), are rejected; Jolokia Agent Since pods reside on the Master Cluster, ultimately requests for Jolokia information from pods must also be protected and handled in a secure manner. This agent is responsible for converting a request from a client into the correct form for transmission to the target pod internally and passing the response back to the client. 8.1. Setting up an example Quarkus Application For a new Quarkus application, the maven quarkus quick-start is available, eg. mvn io.quarkus.platform:quarkus-maven-plugin:3.14.2:create \ -DprojectGroupId=org.hawtio \ -DprojectArtifactId=quarkus-helloworld \ -Dextensions='openshift,camel-quarkus-quartz' Use the quarkus-maven-plugin to generate the project scaffolding Set the project maven groupId to org.hawtio and customize as appropriate Set the project maven artifactId to quarkus-helloworld and customize as appropriate Use the following Quarkus extensions: openshift : Enables maven to deploy to local OpenShift cluster; camel-quarkus-quartz : Enables the Camel extension quartz for use in the example Quarkus application Execute the quick-start to create the scaffolding for the Quarkus project and then allow further customization for individual applications. To build and deploy the application to OpenShift, the following properties should be specified in the file src/main/resources/application.properties (see related documentation ). # Set the Docker build strategy quarkus.openshift.build-strategy=docker # Expose the service to create an OpenShift Container Platform route quarkus.openshift.route.expose=true 8.2. Implementing an Example Camel Quarkus Application For this example, a simple Camel 'hello-world' Quarkus application is to be implemented. Add the file src/main/java/org/hawtio/SampleCamelRoute.java to the project with the following content: package org.hawtio; import jakarta.enterprise.context.ApplicationScoped; import org.apache.camel.builder.endpoint.EndpointRouteBuilder; @ApplicationScoped public class SampleCamelRoute extends EndpointRouteBuilder { @Override public void configure() { from(quartz("cron").cron("{{quartz.cron}}")).routeId("cron") .setBody().constant("Hello Camel! - cron") .to(stream("out")) .to(mock("result")); from("quartz:simple?trigger.repeatInterval={{quartz.repeatInterval}}").routeId("simple") .setBody().constant("Hello Camel! - simple") .to(stream("out")) .to(mock("result")); } } This example logs "Hello Camel ... " entries in the container log via a Camel route. Modify the src/main/resources/application.properties file with the following properties: # Camel camel.context.name = SampleCamel # Uncomment the following to enable the Camel plugin Trace tab #camel.main.tracing = true #camel.main.backlogTracing = true #camel.main.useBreadcrumb = true # Uncomment to enable debugging of the application and in turn # enables the Camel plugin Debug tab even in non-development # environment #quarkus.camel.debug.enabled = true # Define properties for the Camel quartz component used in the # example quartz.cron = 0/10 * * * * ? quartz.repeatInterval = 10000 Add the following dependencies to the <dependencies> section of file pom.xml . These are required due to the route defined in src/main/java/org/hawtio/SampleCamelRoute.java ; these will need to be modified if the Camel route added to the application is changed: <dependency> <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-stream</artifactId> </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-mock</artifactId> </dependency> 8.3. Enabling Jolokia Java-Agent on the Example Quarkus Application In order to ensure that maven properties can be passed through to the src/main/resources/application.properties file, the following should be added to the <build> section of the file pom.xml : <resources> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> </resource> </resources> Add the following Jolokia properties to the <properties> section of the file pom.xml . These will be used to configure the running jolokia java-agent in the Quarkus container (for an explanation of the properties, please refer to the Jolokia JVM Agent documentation): <properties> ... <!-- The current HawtIO Jolokia Version --> <jolokia-version>2.1.0</jolokia-version> <!-- =============================================================== === Jolokia agent configuration for the connection with HawtIO =============================================================== It should use HTTPS and SSL client authentication at minimum. The client principal should match those the HawtIO instance provides (the default is `hawtio-online.hawtio.svc`). --> <jolokia.protocol>https</jolokia.protocol> <jolokia.host>*</jolokia.host> <jolokia.port>8778</jolokia.port> <jolokia.useSslClientAuthentication>true</jolokia.useSslClientAuthentication> <jolokia.caCert>/var/run/secrets/kubernetes.io/serviceaccount/service-ca.crt</jolokia.caCert> <jolokia.clientPrincipal.1>cn=hawtio-online.hawtio.svc</jolokia.clientPrincipal.1> <jolokia.extendedClientCheck>true</jolokia.extendedClientCheck> <jolokia.discoveryEnabled>false</jolokia.discoveryEnabled> ... </properties> Add the following dependencies to the <dependencies> section of the file pom.xml : <!-- This dependency is required for enabling Camel management via JMX / HawtIO. --> <dependency> <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-management</artifactId> </dependency> <!-- This dependency is optional for monitoring with HawtIO but is required for HawtIO view the Camel routes source XML. --> <dependency> <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-jaxb</artifactId> </dependency> <!-- Add this optional dependency, to enable Camel plugin debugging feature. --> <dependency> <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-debug</artifactId> </dependency> <!-- This dependency is required to include the Jolokia agent jvm for access to JMX beans. --> <dependency> <groupId>org.jolokia</groupId> <artifactId>jolokia-agent-jvm</artifactId> <version>USD{jolokia-version}</version> <classifier>javaagent</classifier> </dependency> With maven property filtering implemented, the USD{jolokia... } environment variables should be passed-through from the pom.xml during the building of the application. The purpose of this property is to append a JVM option to the executing process of the container that runs the jolokia java-agent. Modify the src/main/resources/application.properties file with the following property: # Enable the jolokia java-agent on the quarkus application quarkus.openshift.env.vars.JAVA_OPTS_APPEND=-javaagent:lib/main/org.jolokia.jolokia-agent-jvm-USD{jolokia-version}-javaagent.jar=protocol=USD{jolokia.protocol}\,host=USD{jolokia.host}\,port=USD{jolokia.port}\,useSslClientAuthentication=USD{jolokia.useSslClientAuthentication}\,caCert=USD{jolokia.caCert}\,clientPrincipal.1=USD{jolokia.clientPrincipal.1}\,extendedClientCheck=USD{jolokia.extendedClientCheck}\,discoveryEnabled=USD{jolokia.discoveryEnabled} 8.4. Exposing the Jolokia Port from the Quarkus Container for Discovery by HawtIO For HawtIO to discover the deployed application, a port named jolokia must be present on the executing container. Therefore, it is necessary to add the following properties in the src/main/resources/application.properties file: # Define the Jolokia port on the container for HawtIO access quarkus.openshift.ports.jolokia.container-port=USD{jolokia.port} quarkus.openshift.ports.jolokia.protocol=TCP 8.5. Deployment of the HawtIO-Enabled Quarkus Application to OpenShift Pre-requsites : Command-line (CLI) is already logged-in to the OpenShift cluster and the project is selected. When all files have been configured, the following maven command can be executed: ./mvnw clean package -Dquarkus.kubernetes.deploy=true Verify that the Quarkus application is running correctly using the Verification steps detailed here . Assuming the application is running correctly, the new Quarkus application should be discovered by an HawtIO instance (depending on its mode - 'Namespace' mode requires it to be in the same project). The new container should be displayed like in the following screenshot: By clicking Connect, the Quarkus application can be examined by HawtIO. See also : Deploying Quarkus application to OpenShift A Quarkus application: Getting started Using the Quarkus Openshift Extension

Commands:
mvn io.quarkus.platform:quarkus-maven-plugin:3.14.2:create -DprojectGroupId=org.hawtio -DprojectArtifactId=quarkus-helloworld -Dextensions='openshift,camel-quarkus-quartz'
Set the Docker build strategy quarkus.openshift.build-strategy=docker # Expose the service to create an OpenShift Container Platform route quarkus.openshift.route.expose=true
package org.hawtio; import jakarta.enterprise.context.ApplicationScoped; import org.apache.camel.builder.endpoint.EndpointRouteBuilder; @ApplicationScoped public class SampleCamelRoute extends EndpointRouteBuilder { @Override public void configure() { from(quartz("cron").cron("{{quartz.cron}}")).routeId("cron") .setBody().constant("Hello Camel! - cron") .to(stream("out")) .to(mock("result")); from("quartz:simple?trigger.repeatInterval={{quartz.repeatInterval}}").routeId("simple") .setBody().constant("Hello Camel! - simple") .to(stream("out")) .to(mock("result")); } }
Camel camel.context.name = SampleCamel # Uncomment the following to enable the Camel plugin Trace tab #camel.main.tracing = true #camel.main.backlogTracing = true #camel.main.useBreadcrumb = true # Uncomment to enable debugging of the application and in turn # enables the Camel plugin Debug tab even in non-development # environment #quarkus.camel.debug.enabled = true # Define properties for the Camel quartz component used in the # example quartz.cron = 0/10 * * * * ? quartz.repeatInterval = 10000
<dependency> <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-stream</artifactId> </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-mock</artifactId> </dependency>
<resources> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> </resource> </resources>
<properties> <!-- The current HawtIO Jolokia Version --> <jolokia-version>2.1.0</jolokia-version> <!-- =============================================================== === Jolokia agent configuration for the connection with HawtIO =============================================================== It should use HTTPS and SSL client authentication at minimum. The client principal should match those the HawtIO instance provides (the default is `hawtio-online.hawtio.svc`). --> <jolokia.protocol>https</jolokia.protocol> <jolokia.host>*</jolokia.host> <jolokia.port>8778</jolokia.port> <jolokia.useSslClientAuthentication>true</jolokia.useSslClientAuthentication> <jolokia.caCert>/var/run/secrets/kubernetes.io/serviceaccount/service-ca.crt</jolokia.caCert> <jolokia.clientPrincipal.1>cn=hawtio-online.hawtio.svc</jolokia.clientPrincipal.1> <jolokia.extendedClientCheck>true</jolokia.extendedClientCheck> <jolokia.discoveryEnabled>false</jolokia.discoveryEnabled> </properties>
<!-- This dependency is required for enabling Camel management via JMX / HawtIO. --> <dependency> <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-management</artifactId> </dependency> <!-- This dependency is optional for monitoring with HawtIO but is required for HawtIO view the Camel routes source XML. --> <dependency> <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-jaxb</artifactId> </dependency> <!-- Add this optional dependency, to enable Camel plugin debugging feature. --> <dependency> <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-debug</artifactId> </dependency> <!-- This dependency is required to include the Jolokia agent jvm for access to JMX beans. --> <dependency> <groupId>org.jolokia</groupId> <artifactId>jolokia-agent-jvm</artifactId> <version>USD{jolokia-version}</version> <classifier>javaagent</classifier> </dependency>
Enable the jolokia java-agent on the quarkus application quarkus.openshift.env.vars.JAVA_OPTS_APPEND=-javaagent:lib/main/org.jolokia.jolokia-agent-jvm-USD{jolokia-version}-javaagent.jar=protocol=USD{jolokia.protocol}\,host=USD{jolokia.host}\,port=USD{jolokia.port}\,useSslClientAuthentication=USD{jolokia.useSslClientAuthentication}\,caCert=USD{jolokia.caCert}\,clientPrincipal.1=USD{jolokia.clientPrincipal.1}\,extendedClientCheck=USD{jolokia.extendedClientCheck}\,discoveryEnabled=USD{jolokia.discoveryEnabled}
Define the Jolokia port on the container for HawtIO access quarkus.openshift.ports.jolokia.container-port=USD{jolokia.port} quarkus.openshift.ports.jolokia.protocol=TCP
./mvnw clean package -Dquarkus.kubernetes.deploy=true