Coder Social home page Coder Social logo

ammbra / micrometering-with-quarkus Goto Github PK

View Code? Open in Web Editor NEW
5.0 1.0 2.0 251 KB

This repository contains code referenced on https://dzone.com/articles/extra-micrometer-practices-with-quarkus

License: MIT License

Java 78.47% HTML 21.53%
quarkus micrometer practices metrics

micrometering-with-quarkus's Introduction

micrometering-with-quarkus project

Full details about this project can be found here: https://dzone.com/articles/extra-micrometer-practices-with-quarkus

This project uses Quarkus, the Supersonic Subatomic Java Framework.

If you want to learn more about Quarkus, please visit its website: https://quarkus.io/ .

Running the application in dev mode

You can run your application in dev mode that enables live coding using:

./mvnw compile quarkus:dev

Packaging and running the application

The application can be packaged using:

./mvnw package

It produces the micrometering-with-quarkus-1.0.0-SNAPSHOT-runner.jar file in the /target directory. Be aware that it’s not an über-jar as the dependencies are copied into the target/lib directory.

If you want to build an über-jar, execute the following command:

./mvnw package -Dquarkus.package.type=uber-jar

The application is now runnable using java -jar target/micrometering-with-quarkus-1.0.0-SNAPSHOT-runner.jar.

Setup Prometheus on Red Hat OpenShift Developer Sandbox

Once you have your Red Hat account, you can obtain free of charge a Sandbox by going to: https://developers.redhat.com/developer-sandbox/get-started. For development purposes only, you can setup Prometheus by following the steps below:

  • Make sure you are in Developer view.
  • Click on +Add and select the Container Images card.
  • Fill in the image name with openshift/prometheus and leave the other default values. img.png
  • Click on Create button.
  • Next, open the web terminal by pressing the icon >_ located in the upper right corner.
  • Type the following commands there:
curl https://raw.githubusercontent.com/ammbra/micrometering-with-quarkus/feature/techflow-code/kubefiles/prometheus.yaml -o prometheus.yaml

oc create cm prometheus-config --from-file=prometheus.yaml

oc set volume deployment/prometheus --add --name=prometheus-config --type=configmap --configmap-name=prometheus-config --mount-path=/etc/prometheus/

kubectl patch deployment prometheus \
--type=json \
-p='[{"op": "add", "path": "/spec/template/spec/containers/0/args/-", "value": "--config.file=/etc/prometheus/prometheus.yaml"}]'

oc expose svc prometheus

Setup Grafana on Red Hat OpenShift Developer Sandbox

For development purposes only, you can setup Grafana by following the steps below:

  • Make sure you are in Developer view.
  • Click on +Add and select the Container Images card.
  • Fill in the image name with grafana/grafana:6.0.1 and leave the other default values.
  • Click on Create button.
  • Next, open the web terminal by pressing the icon >_ located in the upper right corner.
  • Type the following commands in the web terminal to get an external url where you can access Grafana:
oc expose svc grafana
  • Once you have the external URL to Grafana, open it in a browser tab and use the admin/admin default Grafana credentials.
  • You can change the password used by admin after your first login.
  • Next, add Prometheus as datasource in your Grafana by following the UI steps. You can use the URL of the route to Prometheus for an easier connection.

img.png

  • Next, you can import the experimental dashboard used in the demos by loading [Micrometer Sample.json](Micrometer Sample.json) via Upload .json file.

img.png

micrometering-with-quarkus's People

Contributors

ammbra avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

micrometering-with-quarkus's Issues

./mvnw package -Dquarkus.package.type=uber-jar does not work!

....
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running org.acme.endpoint.ExampleEndpointTest
2022-03-23 17:00:04,895 INFO  [org.jbo.threads] (main) JBoss Threads version 3.4.2.Final
17:00:05 WARN  traceId=, spanId=, sampled= [io.qu.mi.de.bi.mp.MicroprofileMetricsProcessor] (build-14) This application uses the MP Metrics API. The micrometer extension currently provides a compatibility layer that supports the MP Metrics API, but metric names and recorded values will be different. Note that the MP Metrics compatibility layer will move to a different extension in the future.
17:00:07 INFO  traceId=, spanId=, sampled= [io.ag.pool] (main) Datasource '<default>': Initial size smaller than min. Connections will be created when necessary
Hibernate: 
    
    drop table if exists Message CASCADE 
Hibernate: 
    
    drop sequence if exists message_id_seq
Hibernate: create sequence message_id_seq start with 1 increment by 1
Hibernate: 
    
    create table Message (
       id bigint not null,
        content varchar(255),
        locale varchar(255) not null,
        primary key (id)
    )
Hibernate: 
    INSERT INTO message (id, content, locale) VALUES (1000, 'bonjour','fr')
[ERROR] Tests run: 5, Failures: 0, Errors: 1, Skipped: 4, Time elapsed: 6.924 s <<< FAILURE! - in org.acme.endpoint.ExampleEndpointTest
[ERROR] org.acme.endpoint.ExampleEndpointTest.findNonExistingLanguage  Time elapsed: 0.006 s  <<< ERROR!
java.lang.RuntimeException: java.lang.RuntimeException: Failed to start quarkus
Caused by: java.lang.RuntimeException: Failed to start quarkus
Caused by: java.lang.RuntimeException: Unable to start HTTP server
Caused by: java.util.concurrent.ExecutionException: io.quarkus.runtime.QuarkusBindException
Caused by: io.quarkus.runtime.QuarkusBindException

[INFO] Running org.acme.metric.counter.DynamicMultiTaggedCounterTest
[INFO] Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.145 s - in org.acme.metric.counter.DynamicMultiTaggedCounterTest
[INFO] Running org.acme.metric.counter.DynamicTaggedCounterTest
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.001 s - in org.acme.metric.counter.DynamicTaggedCounterTest
[INFO] Running org.acme.metric.timer.DynamicMultiTaggedTimerTest
[INFO] Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.037 s - in org.acme.metric.timer.DynamicMultiTaggedTimerTest
[INFO] Running org.acme.metric.timer.DynamicTaggedTimerTest
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.005 s - in org.acme.metric.timer.DynamicTaggedTimerTest
[INFO] 
[INFO] Results:
[INFO] 
[ERROR] Errors: 
[ERROR]   ExampleEndpointTest.findNonExistingLanguage » Runtime java.lang.RuntimeExcepti...
[INFO] 
[ERROR] Tests run: 11, Failures: 0, Errors: 1, Skipped: 4

I am on Linux (Ubuntu 20.04) with Java openjdk version "11.0.14" 2022-01-18.

Cannot build native package!

openjdk version "11.0.14" 2022-01-18
OpenJDK Runtime Environment GraalVM CE 22.0.0.2 (build 11.0.14+9-jvmci-22.0-b05)
OpenJDK 64-Bit Server VM GraalVM CE 22.0.0.2 (build 11.0.14+9-jvmci-22.0-b05, mixed mode, sharing)
ComponentId              Version             Component name                Stability                     Origin 
---------------------------------------------------------------------------------------------------------------------------------
graalvm                  22.0.0.2            GraalVM Core                  Supported                     
js                       22.0.0.2            Graal.js                      Supported                     
native-image             22.0.0.2            Native Image                  Early adopter                 github.com
  1. ./mvnw package -Pnative =>
[ERROR] Errors: 
[ERROR]   ExampleEndpointTest.findNonExistingLanguage » Runtime java.lang.RuntimeExcepti...

and in target/surefire-reports/org.acme.endpoint.ExampleEndpointTest.txt I have

Tests run: 5, Failures: 0, Errors: 1, Skipped: 4, Time elapsed: 4.519 s <<< FAILURE! - in org.acme.endpoint.ExampleEndpointTest
org.acme.endpoint.ExampleEndpointTest.findNonExistingLanguage  Time elapsed: 0.011 s  <<< ERROR!
java.lang.RuntimeException: java.lang.RuntimeException: Failed to start quarkus
Caused by: java.lang.RuntimeException: Failed to start quarkus
Caused by: java.lang.RuntimeException: Unable to start HTTP server
Caused by: java.util.concurrent.ExecutionException: io.quarkus.runtime.QuarkusBindException
Caused by: io.quarkus.runtime.QuarkusBindException

So it seems to be a port error - should the command be run as root (or as other user)? is it possible to change the port? (BTW is it defined somewhere? running the application as ./mvnw compile quarkus:dev shows that the standard 8080 Spring port is used).
Should some environment variables be defined in order to make the native application building run correctly?

build error if not executing tests: Could not parse certificate: java.io.IOException: Empty input

With GraalVM :

java --version
openjdk 11.0.11 2021-04-20
OpenJDK Runtime Environment GraalVM CE 21.1.0 (build 11.0.11+8-jvmci-21.1-b05)
OpenJDK 64-Bit Server VM GraalVM CE 21.1.0 (build 11.0.11+8-jvmci-21.1-b05, mixed mode, sharing)

Then

mvn package -Pnative -Dmaven.test.skip

[ERROR] Failed to execute goal io.quarkus:quarkus-maven-plugin:2.7.1.Final:build (default) on project micrometering-with-quarkus: Failed to build quarkus application: io.quarkus.builder.BuildException: Build failure: Build failed due to errors
[ERROR] 	[error]: Build step io.quarkus.kubernetes.client.deployment.KubernetesClientBuildStep#process threw an exception: io.fabric8.kubernetes.client.KubernetesClientException: An error has occurred.
[ERROR] 	at io.fabric8.kubernetes.client.KubernetesClientException.launderThrowable(KubernetesClientException.java:103)
[ERROR] 	at io.fabric8.kubernetes.client.KubernetesClientException.launderThrowable(KubernetesClientException.java:97)
[ERROR] 	at io.fabric8.kubernetes.client.utils.HttpClientUtils.applyCommonConfiguration(HttpClientUtils.java:214)
[ERROR] 	at io.fabric8.kubernetes.client.okhttp.OkHttpClientFactory.createHttpClient(OkHttpClientFactory.java:89)
[ERROR] 	at io.fabric8.kubernetes.client.utils.HttpClientUtils.createHttpClient(HttpClientUtils.java:164)
[ERROR] 	at io.fabric8.kubernetes.client.BaseClient.<init>(BaseClient.java:48)
[ERROR] 	at io.fabric8.kubernetes.client.BaseKubernetesClient.<init>(BaseKubernetesClient.java:159)
[ERROR] 	at io.fabric8.kubernetes.client.DefaultKubernetesClient.<init>(DefaultKubernetesClient.java:42)
[ERROR] 	at io.quarkus.kubernetes.client.runtime.KubernetesClientUtils.createClient(KubernetesClientUtils.java:50)
[ERROR] 	at io.quarkus.kubernetes.client.deployment.KubernetesClientBuildStep.process(KubernetesClientBuildStep.java:16)
[ERROR] 	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[ERROR] 	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[ERROR] 	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[ERROR] 	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
[ERROR] 	at io.quarkus.deployment.ExtensionLoader$2.execute(ExtensionLoader.java:882)
[ERROR] 	at io.quarkus.builder.BuildContext.run(BuildContext.java:277)
[ERROR] 	at org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)
[ERROR] 	at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2449)
[ERROR] 	at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1478)
[ERROR] 	at java.base/java.lang.Thread.run(Thread.java:829)
[ERROR] 	at org.jboss.threads.JBossThread.run(JBossThread.java:501)
[ERROR] Caused by: java.security.cert.CertificateException: Could not parse certificate: java.io.IOException: Empty input
[ERROR] 	at java.base/sun.security.provider.X509Factory.engineGenerateCertificate(X509Factory.java:115)
[ERROR] 	at java.base/java.security.cert.CertificateFactory.generateCertificate(CertificateFactory.java:355)
[ERROR] 	at io.fabric8.kubernetes.client.internal.CertUtils.createTrustStore(CertUtils.java:98)
[ERROR] 	at io.fabric8.kubernetes.client.internal.CertUtils.createTrustStore(CertUtils.java:74)
[ERROR] 	at io.fabric8.kubernetes.client.internal.SSLUtils.trustManagers(SSLUtils.java:140)
[ERROR] 	at io.fabric8.kubernetes.client.internal.SSLUtils.trustManagers(SSLUtils.java:90)
[ERROR] 	at io.fabric8.kubernetes.client.utils.HttpClientUtils.applyCommonConfiguration(HttpClientUtils.java:203)
[ERROR] 	... 18 more
[ERROR] Caused by: java.io.IOException: Empty input
[ERROR] 	at java.base/sun.security.provider.X509Factory.engineGenerateCertificate(X509Factory.java:111)
[ERROR] 	... 24 more
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.

embedded mvwn does not work!

On Linux (Ubuntu 20.04) I have the following problem:

./mvnw compile quarkus:dev
...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  3.224 s
[INFO] Finished at: 2022-03-23T17:04:51+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal io.quarkus:quarkus-maven-plugin:2.7.1.Final:dev (default-cli) on project micrometering-with-quarkus: Detected Maven Version (3.6.3)  is not supported, it must be in [3.8.1,). -> [Help 1]

And indeed ./mvnw --version =>

Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /home/.../.m2/wrapper/dists/apache-maven-3.6.3-bin/1iopthnavndlasol9gbrbg6bf2/apache-maven-3.6.3
Java version: 11.0.14, vendor: Ubuntu, runtime: /usr/lib/jvm/java-11-openjdk-amd64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.13.0-37-generic", arch: "amd64", family: "unix"

With a 3.8.4 Maven version everything goes well and I can open the application in the browser etc...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.