이 콘텐츠는 선택한 언어로 제공되지 않습니다.
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 링크 복사링크가 클립보드에 복사되었습니다!
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'
mvn com.redhat.quarkus.platform:quarkus-maven-plugin:<quarkus.platform.version>:create\ -DprojectGroupId=org.hawtio \ -DprojectArtifactId=quarkus-helloworld \ -Dextensions='openshift,camel-quarkus-quartz'Copy to Clipboard Copied! Toggle word wrap Toggle overflow 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
# Set the Docker build strategy quarkus.openshift.build-strategy=docker # Expose the service to create an OpenShift Container Platform route quarkus.openshift.route.expose=trueCopy to Clipboard Copied! Toggle word wrap Toggle overflow
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.javato the project with the following content:Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 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:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Add 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:Copy to Clipboard Copied! Toggle word wrap Toggle overflow
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.propertiesfile, the following should be added to the<build>section of the filepom.xml:Copy to Clipboard Copied! Toggle word wrap Toggle overflow 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):Copy to Clipboard Copied! Toggle word wrap Toggle overflow Add the following dependencies to the
<dependencies>section of the filepom.xml:Copy to Clipboard Copied! Toggle word wrap Toggle overflow 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}# 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}Copy to Clipboard Copied! Toggle word wrap Toggle overflow
8.4. Exposing the Jolokia Port from the Quarkus Container for Discovery by HawtIO 링크 복사링크가 클립보드에 복사되었습니다!
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# Define the Jolokia port on the container for HawtIO access quarkus.openshift.ports.jolokia.container-port=${jolokia.port} quarkus.openshift.ports.jolokia.protocol=TCPCopy to Clipboard Copied! Toggle word wrap Toggle overflow
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
./mvnw clean package -Dquarkus.kubernetes.deploy=trueCopy to Clipboard Copied! Toggle word wrap Toggle overflow - 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: