Questo contenuto non è disponibile nella lingua selezionata.
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 Next 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 Copia collegamentoCollegamento copiato negli appunti!
For a new Quarkus application, the
maven quarkus quick-startis available, eg.mvn com.redhat.quarkus.platform:quarkus-maven-plugin:<quarkus.platform.version>:create\ -DprojectGroupId=org.hawtio \ -DprojectArtifactId=quarkus-helloworld \ -Dextensions='openshift,camel-quarkus-quartz'NoteUse latest
quarkus.platform.versionfrom the Camel Quarkus official documentation.-
Use the
quarkus-maven-pluginto generate the project scaffolding -
Set the project
maven groupIdtoorg.hawtioand customize as appropriate -
Set the project
maven artifactIdtoquarkus-helloworldand customize as appropriate Use the following Quarkus extensions:
- openshift: Enables maven to deploy to local OpenShift cluster;
-
camel-quarkus-quartz: Enables the Camel extension
quartzfor 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.
-
Use the
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 Copia collegamentoCollegamento copiato negli appunti!
For this example, a simple Camel ‘hello-world’ Quarkus application is to be implemented. Add the file
src/main/java/org/hawtio/SampleCamelRoute.javato 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.propertiesfile 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 = 10000Add the following dependencies to the
<dependencies>section of filepom.xml. These are required due to the route defined insrc/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 Copia collegamentoCollegamento copiato negli appunti!
In order to ensure that maven properties can be passed through to the
src/main/resources/application.propertiesfile, the following should be added to the<build>section of the filepom.xml:<resources> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> </resource> </resources>Add the following Jolokia properties to the
<properties>section of the filepom.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.2.9.redhat-00001</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 filepom.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>${jolokia-version}</version> <classifier>javaagent</classifier> </dependency>With maven property filtering implemented, the
${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 thesrc/main/resources/application.propertiesfile 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-${jolokia-version}-javaagent.jar=protocol=${jolokia.protocol}\,host=${jolokia.host}\,port=${jolokia.port}\,useSslClientAuthentication=${jolokia.useSslClientAuthentication}\,caCert=${jolokia.caCert}\,clientPrincipal.1=${jolokia.clientPrincipal.1}\,extendedClientCheck=${jolokia.extendedClientCheck}\,discoveryEnabled=${jolokia.discoveryEnabled}
8.4. Exposing the Jolokia Port from the Quarkus Container for Discovery by HawtIO Copia collegamentoCollegamento copiato negli appunti!
For HawtIO to discover the deployed application, a port named
jolokiamust be present on the executing container. Therefore, it is necessary to add the following properties in thesrc/main/resources/application.propertiesfile:# Define the Jolokia port on the container for HawtIO access quarkus.openshift.ports.jolokia.container-port=${jolokia.port} quarkus.openshift.ports.jolokia.protocol=TCP
8.5. Deployment of the HawtIO-Enabled Quarkus Application to OpenShift Copia collegamentoCollegamento copiato negli appunti!
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: