UserGuide and example extended for Micrometer integration (#5427)
Signed-off-by: Maxim Nesen <maxim.nesen@oracle.com>
diff --git a/bundles/apidocs/pom.xml b/bundles/apidocs/pom.xml
index 50fb94d..3fd55ea 100644
--- a/bundles/apidocs/pom.xml
+++ b/bundles/apidocs/pom.xml
@@ -103,6 +103,11 @@
</dependency>
<dependency>
<groupId>org.glassfish.jersey.connectors</groupId>
+ <artifactId>jersey-jetty-http2-connector</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.connectors</groupId>
<artifactId>jersey-netty-connector</artifactId>
<version>${project.version}</version>
</dependency>
@@ -214,6 +219,11 @@
<version>${project.version}</version>
</dependency>
<dependency>
+ <groupId>org.glassfish.jersey.ext.micrometer</groupId>
+ <artifactId>jersey-micrometer</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
<groupId>org.glassfish.jersey.ext.microprofile</groupId>
<artifactId>jersey-mp-config</artifactId>
<version>${project.version}</version>
diff --git a/docs/pom.xml b/docs/pom.xml
index 4f7621a..5886dfe 100644
--- a/docs/pom.xml
+++ b/docs/pom.xml
@@ -77,7 +77,7 @@
<plugin>
<groupId>com.agilejava.docbkx</groupId>
<artifactId>docbkx-maven-plugin</artifactId>
- <version>2.0.15</version>
+ <version>2.0.17</version>
<dependencies>
<dependency>
<groupId>net.sf.docbook</groupId>
diff --git a/docs/src/main/docbook/client.xml b/docs/src/main/docbook/client.xml
index 85e9fd8..6f2be1c 100644
--- a/docs/src/main/docbook/client.xml
+++ b/docs/src/main/docbook/client.xml
@@ -661,6 +661,11 @@
<entry><literal>org.glassfish.jersey.connectors:jersey-jetty-connector</literal></entry>
</row>
<row>
+ <entry>Jetty HTTP/2 client</entry>
+ <entry>&jersey.jetty.JettyHttp2ConnectorProvider;</entry>
+ <entry><literal>org.glassfish.jersey.connectors:jersey-jetty-http2-connector</literal></entry>
+ </row>
+ <row>
<entry>Netty NIO framework</entry>
<entry>&jersey.netty.NettyConnectorProvider;</entry>
<entry><literal>org.glassfish.jersey.connectors:jersey-netty-connector</literal></entry>
diff --git a/docs/src/main/docbook/jersey.ent b/docs/src/main/docbook/jersey.ent
index a6b2d80..7b08086 100644
--- a/docs/src/main/docbook/jersey.ent
+++ b/docs/src/main/docbook/jersey.ent
@@ -109,6 +109,8 @@
<!ENTITY helidon.link "<link xlink:href='https://helidon.io/'>Helidon</link>">
<!ENTITY smallrye.link "<link xlink:href='https://smallrye.io/'>SmallRye</link>">
<!ENTITY yasson.link "<link xlink:href='https://eclipse-ee4j.github.io/yasson/'>Yasson</link>">
+<!ENTITY micrometer.link "<link xlink:href='https://micrometer.io/'>Micrometer project</link>">
+<!ENTITY micrometer.jersey.link "<link xlink:href='https://micrometer.io/docs/ref/jetty'>Micrometer Jersey/Jetty support</link>">
<!-- API Docs links -->
<!ENTITY bv.Configuration "<link xlink:href='&bv11.javadoc.uri;/javax/validation/Configuration.html'>Configuration</link>">
@@ -476,6 +478,7 @@
<!ENTITY jersey.jetty.JettyClientProperties.SYNC_LISTENER_RESPONSE_MAX_SIZE "<link xlink:href='&jersey.javadoc.uri.prefix;/jetty/connector/JettyClientProperties.html#SYNC_LISTENER_RESPONSE_MAX_SIZE'>JettyClientProperties.SYNC_LISTENER_RESPONSE_MAX_SIZE</link>" >
<!ENTITY jersey.jetty.JettyClientProperties.TOTAL_TIMEOUT "<link xlink:href='&jersey.javadoc.uri.prefix;/jetty/connector/JettyClientProperties.html#TOTAL_TIMEOUT'>JettyClientProperties.TOTAL_TIMEOUT</link>" >
<!ENTITY jersey.jetty.JettyConnectorProvider "<link xlink:href='&jersey.javadoc.uri.prefix;/jetty/connector/JettyConnectorProvider.html'>JettyConnectorProvider</link>">
+<!ENTITY jersey.jetty.JettyHttp2ConnectorProvider "<link xlink:href='&jersey.javadoc.uri.prefix;/jetty/http2/connector/JettyConnectorProvider.html'>JettyHttp2ConnectorProvider</link>">
<!ENTITY jersey.jetty.JettyHttpContainer "<link xlink:href='&jersey.javadoc.uri.prefix;/jetty/JettyHttpContainer.html'>JettyHttpContainer</link>">
<!ENTITY jersey.jetty.JettyHttpContainerFactory "<link xlink:href='&jersey.javadoc.uri.prefix;/jetty/JettyHttpContainerFactory.html'>JettyHttpContainerFactory</link>">
<!ENTITY jersey.jetty.JettyHttpContainerProvider "<link xlink:href='&jersey.javadoc.uri.prefix;/jetty/JettyHttpContainerProvider.html'>JettyHttpContainerProvider</link>">
diff --git a/docs/src/main/docbook/micrometer.xml b/docs/src/main/docbook/micrometer.xml
new file mode 100644
index 0000000..f09375e
--- /dev/null
+++ b/docs/src/main/docbook/micrometer.xml
@@ -0,0 +1,85 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2023 Oracle and/or its affiliates. All rights reserved.
+
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v. 2.0, which is available at
+ http://www.eclipse.org/legal/epl-2.0.
+
+ This Source Code may also be made available under the following Secondary
+ Licenses when the conditions for such availability set forth in the
+ Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ version 2 with the GNU Classpath Exception, which is available at
+ https://www.gnu.org/software/classpath/license.html.
+
+ SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+
+-->
+
+<!DOCTYPE chapter [<!ENTITY % ents SYSTEM "jersey.ent" > %ents; ]>
+<chapter xmlns="http://docbook.org/ns/docbook"
+ version="5.0"
+ xml:lang="en"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:xi="http://www.w3.org/2001/XInclude"
+ xmlns:xlink="http://www.w3.org/1999/xlink"
+ xsi:schemaLocation="http://docbook.org/ns/docbook http://docbook.org/xml/5.0/xsd/docbook.xsd
+ http://www.w3.org/1999/xlink http://www.w3.org/1999/xlink.xsd"
+ xml:id="jersey-micrometer">
+ <title>Micrometer - application observability facade</title>
+ <para>
+ The chapter is about Micrometer integration into Jersey which comes since the version 2.41 as an extension module.
+ Before Jersey 2.41, it was possible to integrate Micrometer with Jersey using directly µmeter.jersey.link;.
+ There is also support for Jakarta EE 10 integration. The detailed documentation regarding metrics fine-tuning
+ can be found at the µmeter.link;.
+ </para>
+ <section xml:id="micrometer-integration">
+ <title>Integration into Jersey</title>
+ <para>
+ Since Jersey 2.41 it's possibly to use an extension module in order to use Micrometer instrumentation
+ inside your projects. The module shall be added as a dependency:
+ <programlisting language="xml" linenumbering="unnumbered"><dependency>
+ <groupId>org.glassfish.jersey.ext.micrometer</groupId>
+ <artifactId>jersey-micrometer</artifactId>
+ <version>&version;</scope>
+</dependency></programlisting>
+ After the dependency is added, the Micrometer can be configured as follows:
+ <programlisting language="java" linenumbering="unnumbered">final ResourceConfig resourceConfig = new ResourceConfig();
+resourceConfig.register(new MetricsApplicationEventListener(
+ registry,
+ new DefaultJerseyTagsProvider(), "http.shared.metrics", true));
+final ServletContainer servletContainer = new ServletContainer(resourceConfig);</programlisting>
+ the registry instance is of type <literal>MeterRegistry</literal> which could be
+ <literal>new SimpleMeterRegistry();</literal>. Then all metrics can be accessed like
+ <literal>registry.get("http.shared.metrics")</literal>. The "http.shared.metrics" string
+ is the name of a particular registry which was registered within the
+ <literal>MetricsApplicationEventListener</literal>.
+
+ Micrometer supports a set of <literal>Meter</literal> primitives, including <literal>Timer</literal>,
+ <literal>Counter</literal>, <literal>Gauge</literal>, <literal>DistributionSummary</literal>,
+ <literal>LongTaskTimer</literal>, <literal>FunctionCounter</literal>, <literal>FunctionTimer</literal>,
+ and <literal>TimeGauge</literal>.
+ Different meter types result in a different number of time series metrics. For example, while there is
+ a single metric that represents a <literal>Gauge</literal>, a <literal>Timer</literal> measures both the
+ count of timed events and the total time of all timed events.
+ </para>
+ <para>
+ Implementing resource methods, which should be measured, several annotations can be used. The basic example
+ demonstrates the <literal>@Counted</literal> annotation.
+ <example>
+ <title>Annotated Micrometer resource methods</title>
+ <programlisting language="java" linenumbering="unnumbered">@GET
+@Counted(value = COUNTER_NAME, description = COUNTER_DESCRIPTION)
+@Produces(MediaType.TEXT_PLAIN)
+@Path("counted")
+public String getCounterMessage() {
+ return "Requests to this method are counted. Use /metrics to see more";
+}
+ </programlisting>
+ </example>
+ Metrics however can be introduced using another annotations <literal>@Timed</literal>, or
+ <literal>@TimedSet</literal> which is a set of <literal>@Timed</literal>.
+ </para>
+ </section>
+</chapter>
\ No newline at end of file
diff --git a/docs/src/main/docbook/modules.xml b/docs/src/main/docbook/modules.xml
index 7fa60b4..6f029df 100644
--- a/docs/src/main/docbook/modules.xml
+++ b/docs/src/main/docbook/modules.xml
@@ -116,6 +116,14 @@
</row>
<row>
<entry>
+<link xlink:href="https://eclipse-ee4j.github.io/jersey.github.io/project-info/&version;/jersey/project/jersey-container-jetty-http2/dependencies.html">
+ jersey-container-jetty-http2
+</link>
+</entry>
+<entry>Jetty HTTP/2 Container</entry>
+</row>
+<row>
+<entry>
<link xlink:href="https://eclipse-ee4j.github.io/jersey.github.io/project-info/&version;/jersey/project/jersey-container-jetty-servlet/dependencies.html">
jersey-container-jetty-servlet
</link>
@@ -178,6 +186,14 @@
<tbody>
<row>
<entry>
+<link xlink:href="https://eclipse-ee4j.github.io/jersey.github.io/project-info/&version;/jersey/project/jersey-apache5-connector/dependencies.html">
+ jersey-apache5-connector
+</link>
+</entry>
+<entry>Jersey Client Transport via Apache 5</entry>
+</row>
+<row>
+<entry>
<link xlink:href="https://eclipse-ee4j.github.io/jersey.github.io/project-info/&version;/jersey/project/jersey-apache-connector/dependencies.html">
jersey-apache-connector
</link>
@@ -194,6 +210,14 @@
</row>
<row>
<entry>
+<link xlink:href="https://eclipse-ee4j.github.io/jersey.github.io/project-info/&version;/jersey/project/jersey-helidon-connector/dependencies.html">
+ jersey-helidon-connector
+</link>
+</entry>
+<entry>Jersey Client Transport via Helidon</entry>
+</row>
+<row>
+<entry>
<link xlink:href="https://eclipse-ee4j.github.io/jersey.github.io/project-info/&version;/jersey/project/jersey-jdk-connector/dependencies.html">
jersey-jdk-connector
</link>
@@ -210,6 +234,14 @@
</row>
<row>
<entry>
+<link xlink:href="https://eclipse-ee4j.github.io/jersey.github.io/project-info/&version;/jersey/project/jersey-jetty-http2-connector/dependencies.html">
+ jersey-jetty-http2-connector
+</link>
+</entry>
+<entry>Jersey Client Transport via Jetty with HTTP/2 support</entry>
+</row>
+<row>
+<entry>
<link xlink:href="https://eclipse-ee4j.github.io/jersey.github.io/project-info/&version;/jersey/project/jersey-netty-connector/dependencies.html">
jersey-netty-connector
</link>
@@ -398,6 +430,30 @@
</row>
<row>
<entry>
+<link xlink:href="https://eclipse-ee4j.github.io/jersey.github.io/project-info/&version;/jersey/project/jersey-micrometer/dependencies.html">
+ jersey-micrometer
+</link>
+</entry>
+<entry>Jersey extension module providing support for Micrometer.</entry>
+</row>
+<row>
+<entry>
+<link xlink:href="https://eclipse-ee4j.github.io/jersey.github.io/project-info/&version;/jersey/project/project/jersey-mp-config/dependencies.html">
+ jersey-mp-config
+</link>
+</entry>
+<entry>Jersey extension module providing support for MicroProfile Configuration.</entry>
+</row>
+<row>
+<entry>
+<link xlink:href="https://eclipse-ee4j.github.io/jersey.github.io/project-info/&version;/jersey/project/project/jersey-mp-rest-client/dependencies.html">
+ jersey-mp-rest-client
+</link>
+</entry>
+<entry>Jersey extension module providing support for MicroProfile REST Client.</entry>
+</row>
+<row>
+<entry>
<link xlink:href="https://eclipse-ee4j.github.io/jersey.github.io/project-info/&version;/jersey/project/jersey-mvc/dependencies.html">
jersey-mvc
</link>
@@ -486,6 +542,14 @@
</row>
<row>
<entry>
+<link xlink:href="https://eclipse-ee4j.github.io/jersey.github.io/project-info/&version;/jersey/project/jersey-spring5/dependencies.html">
+ jersey-spring5
+</link>
+</entry>
+<entry>Jersey extension module providing support for Spring 5 integration.</entry>
+</row>
+<row>
+<entry>
<link xlink:href="https://eclipse-ee4j.github.io/jersey.github.io/project-info/&version;/jersey/project/jersey-wadl-doclet/dependencies.html">
jersey-wadl-doclet
</link>
diff --git a/docs/src/main/docbook/user-guide.xml b/docs/src/main/docbook/user-guide.xml
index 799478d..7d41244 100644
--- a/docs/src/main/docbook/user-guide.xml
+++ b/docs/src/main/docbook/user-guide.xml
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<!--
- Copyright (c) 2010, 2021 Oracle and/or its affiliates. All rights reserved.
+ Copyright (c) 2010, 2023 Oracle and/or its affiliates. All rights reserved.
This program and the accompanying materials are made available under the
terms of the Eclipse Public License v. 2.0, which is available at
@@ -105,6 +105,7 @@
<xi:include href="declarative-linking.xml" />
<xi:include href="resource-builder.xml" />
<xi:include href="mp-config.xml" />
+ <xi:include href="micrometer.xml" />
<xi:include href="sse.xml" />
<xi:include href="security.xml" />
<xi:include href="wadl.xml" />
diff --git a/examples/micrometer/README.MD b/examples/micrometer/README.MD
index 609a6ea..ea0e16c 100644
--- a/examples/micrometer/README.MD
+++ b/examples/micrometer/README.MD
@@ -1,16 +1,10 @@
[//]: # " Copyright (c) 2023 Oracle and/or its affiliates. All rights reserved. "
-[//]: # " "
+[//]: # " "
[//]: # " This program and the accompanying materials are made available under the "
-[//]: # " terms of the Eclipse Public License v. 2.0, which is available at "
-[//]: # " http://www.eclipse.org/legal/epl-2.0. "
-[//]: # " "
-[//]: # " This Source Code may also be made available under the following Secondary "
-[//]: # " Licenses when the conditions for such availability set forth in the "
-[//]: # " Eclipse Public License v. 2.0 are satisfied: GNU General Public License, "
-[//]: # " version 2 with the GNU Classpath Exception, which is available at "
-[//]: # " https://www.gnu.org/software/classpath/license.html. "
-[//]: # " "
-[//]: # " SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 "
+[//]: # " terms of the Eclipse Distribution License v. 1.0, which is available at "
+[//]: # " http://www.eclipse.org/org/documents/edl-v10.php. "
+[//]: # " "
+[//]: # " SPDX-License-Identifier: BSD-3-Clause "
jersey-micrometer-webapp
==========================================================
@@ -24,20 +18,25 @@
URI path | Resource class | HTTP methods
------------------------------------------ | ------------------------- | --------------
-**_/micro/meter_** | JerseyResource | GET
-**_/micro/metrics_** | JerseyResource | GET
-**_/micro/metrics/metrics_** | JerseyResource | GET
+**_/micro/timed_** | MeasuredTimedResource | GET
+**_/micro/metrics_** | MetricsResource | GET
+**_/micro/summary_** | SummaryResource | GET
Sample Response
---------------
-```javascript
---- (micro/meter)
-Hello World!
----- (micro/metrics)
-Listing available meters: http.shared.metrics;
----- (micro/metric/metrics)
-Overall requests counts: 9, total time (millis): 35.799483
+```html
+--- (micro/timed)
+Requests to this method are measured. Use /init to see more
+---- (micro/metrics)
+Static meters are initialized, try summary. If you want more measurements just refresh this page several times.
+---- (micro/summary)
+Listing available meters
+Many occurrences of the same name means that there are more meters which could be used with different tags, but this is actually a challenge to handle all available metrics :
+http.timers;
+http.shared.metrics;
+Counts to the init page: 2, time spent on requests to the init page (millis): 2.759025
+Requests to 'measure/timed' counts: 2, total time (millis): 40.110161
```
@@ -48,10 +47,10 @@
> mvn clean compile exec:java
-- <http://localhost:8080/micro/meter>
+- <http://localhost:8080/micro/metrics>
- after few request to the main page go to the url
-- - <http://localhost:8080/micro/metrics>
-- and see the list of available meters
+- <http://localhost:8080/micro/timed>
+- and see the responses from available resource pages
- then go to the
-- - <http://localhost:8080/micro/metrics/metrics>
+- <http://localhost:8080/micro/summary>
- and see statistics for the micro/meter page
\ No newline at end of file
diff --git a/examples/micrometer/pom.xml b/examples/micrometer/pom.xml
index df423e1..c2329fb 100644
--- a/examples/micrometer/pom.xml
+++ b/examples/micrometer/pom.xml
@@ -4,16 +4,10 @@
Copyright (c) 2023 Oracle and/or its affiliates. All rights reserved.
This program and the accompanying materials are made available under the
- terms of the Eclipse Public License v. 2.0, which is available at
- http://www.eclipse.org/legal/epl-2.0.
+ terms of the Eclipse Distribution License v. 1.0, which is available at
+ http://www.eclipse.org/org/documents/edl-v10.php.
- This Source Code may also be made available under the following Secondary
- Licenses when the conditions for such availability set forth in the
- Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- version 2 with the GNU Classpath Exception, which is available at
- https://www.gnu.org/software/classpath/license.html.
-
- SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ SPDX-License-Identifier: BSD-3-Clause
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
diff --git a/examples/micrometer/src/main/java/org/glassfish/jersey/examples/micrometer/App.java b/examples/micrometer/src/main/java/org/glassfish/jersey/examples/micrometer/App.java
index 92dcf22..3e4f465 100644
--- a/examples/micrometer/src/main/java/org/glassfish/jersey/examples/micrometer/App.java
+++ b/examples/micrometer/src/main/java/org/glassfish/jersey/examples/micrometer/App.java
@@ -2,50 +2,34 @@
* Copyright (c) 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
+ * terms of the Eclipse Distribution License v. 1.0, which is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
*
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ * SPDX-License-Identifier: BSD-3-Clause
*/
package org.glassfish.jersey.examples.micrometer;
+import org.glassfish.grizzly.http.server.HttpServer;
+import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
+
import java.io.IOException;
import java.net.URI;
import java.util.logging.Level;
import java.util.logging.Logger;
-import io.micrometer.core.instrument.MeterRegistry;
-import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
-import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
-import org.glassfish.jersey.micrometer.server.DefaultJerseyTagsProvider;
-import org.glassfish.jersey.micrometer.server.MetricsApplicationEventListener;
-import org.glassfish.jersey.server.ResourceConfig;
-
-import org.glassfish.grizzly.http.server.HttpServer;
-
public class App {
private static final URI BASE_URI = URI.create("http://localhost:8080/micro/");
- public static final String ROOT_PATH = "meter";
+ public static final String WEB_PATH = "/micro/";
public static void main(String[] args) {
try {
System.out.println("Micrometer/ Jersey Basic Example App");
- final MeterRegistry registry = new SimpleMeterRegistry();
-
- final ResourceConfig resourceConfig = new ResourceConfig(MicrometerResource.class)
- .register(new MetricsApplicationEventListener(registry, new DefaultJerseyTagsProvider(),
- "http.shared.metrics", true))
- .register(new MetricsResource(registry));
- final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(BASE_URI, resourceConfig, false);
+ final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(BASE_URI,
+ new MetricsResourceConfig(),
+ false);
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
@Override
public void run() {
@@ -55,9 +39,9 @@
server.start();
System.out.println(String.format("Application started.\nTry out %s%s\n"
- + "After several requests go to %s%s\nAnd after that go to the %s%s\n"
+ + "And after that go to the %s%s\n"
+ "Stop the application using CTRL+C",
- BASE_URI, ROOT_PATH, BASE_URI, "metrics", BASE_URI, "metrics/metrics"));
+ BASE_URI, "timed", BASE_URI, "metrics"));
Thread.currentThread().join();
} catch (IOException | InterruptedException ex) {
Logger.getLogger(App.class.getName()).log(Level.SEVERE, null, ex);
diff --git a/examples/micrometer/src/main/java/org/glassfish/jersey/examples/micrometer/MetricsResource.java b/examples/micrometer/src/main/java/org/glassfish/jersey/examples/micrometer/MetricsResource.java
index 60e9194..28f1f11 100644
--- a/examples/micrometer/src/main/java/org/glassfish/jersey/examples/micrometer/MetricsResource.java
+++ b/examples/micrometer/src/main/java/org/glassfish/jersey/examples/micrometer/MetricsResource.java
@@ -2,71 +2,28 @@
* Copyright (c) 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
+ * terms of the Eclipse Distribution License v. 1.0, which is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
*
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ * SPDX-License-Identifier: BSD-3-Clause
*/
package org.glassfish.jersey.examples.micrometer;
-import io.micrometer.core.instrument.Meter;
-import io.micrometer.core.instrument.MeterRegistry;
-import io.micrometer.core.instrument.Timer;
-
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
-import java.util.concurrent.TimeUnit;
+
+import static org.glassfish.jersey.examples.micrometer.App.WEB_PATH;
@Path("metrics")
public class MetricsResource {
- private final MeterRegistry registry;
-
- public MetricsResource(MeterRegistry registry) {
- this.registry = registry;
- }
-
@GET
- @Produces("text/plain")
+ @Produces("text/html")
public String getMeters() {
- final StringBuffer result = new StringBuffer();
- try {
- result.append("Listing available meters: ");
- for (final Meter meter : registry.getMeters()) {
- result.append(meter.getId().getName());
- result.append("; ");
- }
- } catch (Exception ex) {
- System.out.println(ex);
- result.append("Exception occured, see log for details...");
- result.append(ex.toString());
- }
- return result.toString();
+ return "<html><body>Gaining measurements for the summary page, try <a href=\""
+ + WEB_PATH + "summary\">summary</a>. If you want more measurements just refresh this page several times."
+ + "</body></html>";
}
- @GET
- @Path("metrics")
- @Produces("text/plain")
- public String getMetrics() {
- final StringBuffer result = new StringBuffer();
- try {
- final Timer timer = registry.get("http.shared.metrics")
- .tags("method", "GET", "uri", "/micro/meter", "status", "200", "exception", "None", "outcome", "SUCCESS")
- .timer();
- result.append(String.format("Overall requests counts: %d, total time (millis): %f",
- timer.count(), timer.totalTime(TimeUnit.MILLISECONDS)));
- } catch (Exception ex) {
- System.out.println(ex);
- result.append("Exception occured, see log for details...");
- result.append(ex.toString());
- }
- return result.toString();
- }
-}
+}
\ No newline at end of file
diff --git a/examples/micrometer/src/main/java/org/glassfish/jersey/examples/micrometer/MetricsResourceConfig.java b/examples/micrometer/src/main/java/org/glassfish/jersey/examples/micrometer/MetricsResourceConfig.java
new file mode 100644
index 0000000..6ce457c
--- /dev/null
+++ b/examples/micrometer/src/main/java/org/glassfish/jersey/examples/micrometer/MetricsResourceConfig.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Distribution License v. 1.0, which is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+package org.glassfish.jersey.examples.micrometer;
+
+import org.glassfish.jersey.internal.inject.AbstractBinder;
+import org.glassfish.jersey.server.ResourceConfig;
+
+import javax.ws.rs.ApplicationPath;
+
+@ApplicationPath("/")
+public class MetricsResourceConfig extends ResourceConfig {
+
+ private final MetricsStore store = new MetricsStore();
+
+ public MetricsResourceConfig() {
+ register(new AbstractBinder() {
+ @Override
+ protected void configure() {
+ bind(store).to(MetricsStore.class);
+ }
+ });
+ register(store.getMetricsApplicationEventListener());
+ register(TimedResource.class);
+ register(MetricsResource.class);
+ register(SummaryResource.class);
+ }
+
+ public MetricsStore getStore() {
+ return store;
+ }
+}
diff --git a/examples/micrometer/src/main/java/org/glassfish/jersey/examples/micrometer/MetricsStore.java b/examples/micrometer/src/main/java/org/glassfish/jersey/examples/micrometer/MetricsStore.java
new file mode 100644
index 0000000..01eaed8
--- /dev/null
+++ b/examples/micrometer/src/main/java/org/glassfish/jersey/examples/micrometer/MetricsStore.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Distribution License v. 1.0, which is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+package org.glassfish.jersey.examples.micrometer;
+
+import io.micrometer.core.instrument.MeterRegistry;
+import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
+import org.glassfish.jersey.micrometer.server.DefaultJerseyTagsProvider;
+import org.glassfish.jersey.micrometer.server.MetricsApplicationEventListener;
+
+public class MetricsStore {
+
+ public static final String REGISTRY_NAME = "http.shared.metrics";
+ private final MetricsApplicationEventListener metricsApplicationEventListener;
+ private final MeterRegistry registry = new SimpleMeterRegistry();
+
+ public MetricsStore() {
+ metricsApplicationEventListener = new MetricsApplicationEventListener(registry,
+ new DefaultJerseyTagsProvider(),
+ REGISTRY_NAME, true);
+ }
+
+ public MetricsApplicationEventListener getMetricsApplicationEventListener() {
+ return metricsApplicationEventListener;
+ }
+
+ public MeterRegistry getRegistry() {
+ return registry;
+ }
+}
\ No newline at end of file
diff --git a/examples/micrometer/src/main/java/org/glassfish/jersey/examples/micrometer/MicrometerResource.java b/examples/micrometer/src/main/java/org/glassfish/jersey/examples/micrometer/MicrometerResource.java
deleted file mode 100644
index 7ff1083..0000000
--- a/examples/micrometer/src/main/java/org/glassfish/jersey/examples/micrometer/MicrometerResource.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright (c) 2023 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-package org.glassfish.jersey.examples.micrometer;
-
-import javax.ws.rs.GET;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
-
-@Path("meter")
-public class MicrometerResource {
- public static final String CLICHED_MESSAGE = "Hello World!";
-
- @GET
- @Produces("text/plain")
- public String getHello() {
- return CLICHED_MESSAGE;
- }
-
-}
diff --git a/examples/micrometer/src/main/java/org/glassfish/jersey/examples/micrometer/SummaryResource.java b/examples/micrometer/src/main/java/org/glassfish/jersey/examples/micrometer/SummaryResource.java
new file mode 100644
index 0000000..5f82d15
--- /dev/null
+++ b/examples/micrometer/src/main/java/org/glassfish/jersey/examples/micrometer/SummaryResource.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Distribution License v. 1.0, which is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+package org.glassfish.jersey.examples.micrometer;
+
+import io.micrometer.core.instrument.Meter;
+import io.micrometer.core.instrument.Timer;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import java.util.concurrent.TimeUnit;
+
+import static org.glassfish.jersey.examples.micrometer.App.WEB_PATH;
+import static org.glassfish.jersey.examples.micrometer.MetricsStore.REGISTRY_NAME;
+
+@Path("summary")
+public class SummaryResource {
+
+ @Context
+ private MetricsStore store;
+
+ @GET
+ @Produces("text/html")
+ public String getExtendedMeters() {
+ final StringBuffer result = new StringBuffer();
+ try {
+ result.append("<html><body>"
+ + "Listing available meters<br/><br/>Many occurrences of the same name means that there are more meters"
+ + " which could be used with different tags,"
+ + " but this is actually a challenge to handle all available metrics :<br/><br/> ");
+ for (final Meter meter : store.getRegistry().getMeters()) {
+ result.append(meter.getId().getName());
+ result.append(";<br/>\n\r ");
+ }
+ } catch (Exception ex) {
+ result.append("Try clicking links below to gain more metrics.<br/>");
+ }
+ result.append("<br/>\n\r ");
+ result.append("<br/>\n\r ");
+ try {
+ final Timer timer = store.getRegistry().get(REGISTRY_NAME)
+ .tags("method", "GET", "status", "200", "exception", "None",
+ "outcome", "SUCCESS", "uri", "/micro/metrics")
+ .timer();
+
+ result.append(
+ String.format("Counts to the page with standard measurements: %d, time spent on requests to the init "
+ + "page (millis): %f <br/>\n\r",
+ timer.count(), timer.totalTime(TimeUnit.MILLISECONDS)));
+
+ final Timer annotatedTimer = store.getRegistry().timer(TimedResource.TIMER_NAME,
+ "method", "GET", "status", "200", "exception", "None",
+ "outcome", "SUCCESS", "uri", "/micro/timed");
+
+ result.append(
+ String.format("Counts to the page with annotated measurements: %d, total time (millis): %f <br/>\n\r",
+ annotatedTimer.count(), annotatedTimer.totalTime(TimeUnit.MILLISECONDS)));
+
+ } catch (Exception ex) {
+ result.append(String.format("Counts to the init page: %d, total time (millis): %d <br/>\n\r",
+ 0, 0));
+ result.append("Try clicking links below to gain more metrics.<br/>");
+ }
+ result.append("<br/><br/>Available pages for measurements: <a href=\""
+ + WEB_PATH + "metrics\">measure requests in the standard way</a> , <a href=\""
+ + WEB_PATH + "timed\">measure requests in the annotated way</a>");
+ return result.append("</body></html>").toString();
+ }
+}
diff --git a/examples/micrometer/src/main/java/org/glassfish/jersey/examples/micrometer/TimedResource.java b/examples/micrometer/src/main/java/org/glassfish/jersey/examples/micrometer/TimedResource.java
new file mode 100644
index 0000000..654cba4
--- /dev/null
+++ b/examples/micrometer/src/main/java/org/glassfish/jersey/examples/micrometer/TimedResource.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Distribution License v. 1.0, which is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+package org.glassfish.jersey.examples.micrometer;
+
+import io.micrometer.core.annotation.Timed;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+
+import static org.glassfish.jersey.examples.micrometer.App.WEB_PATH;
+
+@Path("timed")
+public class TimedResource {
+
+ public static final String MESSAGE = "<html><body>Gaining measures in the annotated way. "
+ + "<br/>Take a look at <a href=\"" + WEB_PATH + "metrics\">the standard way of measurements</a><br/> "
+ + "Or just go to <a href=\"" + WEB_PATH + "summary\">summary</a> to check what you've got</body></html>";
+ public static final String TIMER_NAME = "http.timers";
+ public static final String TIMER_DESCRIPTION = "resource measurement timer";
+
+ @GET
+ @Produces("text/html")
+ @Timed(value = TIMER_NAME, description = TIMER_DESCRIPTION, histogram = true)
+ public String getTimedMessage() {
+ return MESSAGE;
+ }
+}
diff --git a/examples/micrometer/src/test/java/org/glassfish/jersey/examples/micrometer/MicrometerTest.java b/examples/micrometer/src/test/java/org/glassfish/jersey/examples/micrometer/MicrometerTest.java
index 4a5f4ee..e8612c4 100644
--- a/examples/micrometer/src/test/java/org/glassfish/jersey/examples/micrometer/MicrometerTest.java
+++ b/examples/micrometer/src/test/java/org/glassfish/jersey/examples/micrometer/MicrometerTest.java
@@ -2,63 +2,52 @@
* Copyright (c) 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
+ * terms of the Eclipse Distribution License v. 1.0, which is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
*
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ * SPDX-License-Identifier: BSD-3-Clause
*/
package org.glassfish.jersey.examples.micrometer;
-import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Timer;
-import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
-import org.glassfish.jersey.micrometer.server.DefaultJerseyTagsProvider;
-import org.glassfish.jersey.micrometer.server.MetricsApplicationEventListener;
import org.glassfish.jersey.test.JerseyTest;
-import org.glassfish.jersey.server.ResourceConfig;
import org.junit.jupiter.api.Test;
import javax.ws.rs.core.Application;
-
import java.util.concurrent.TimeUnit;
-import static org.glassfish.jersey.examples.micrometer.MicrometerResource.CLICHED_MESSAGE;
+import static org.glassfish.jersey.examples.micrometer.TimedResource.MESSAGE;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
public class MicrometerTest extends JerseyTest {
- static final String TIMER_METRIC_NAME = "http.server.requests";
+ static final int REQUESTS_COUNT = 10;
- MeterRegistry registry;
+ private MetricsResourceConfig resourceConfig;
@Override
protected Application configure() {
- registry = new SimpleMeterRegistry();
- MetricsApplicationEventListener metricsListener = new MetricsApplicationEventListener(registry,
- new DefaultJerseyTagsProvider(), TIMER_METRIC_NAME, true);
- return new ResourceConfig(MicrometerResource.class)
- .register(metricsListener)
- .register(new MetricsResource(registry));
+ resourceConfig = new MetricsResourceConfig();
+ assertNotNull(this.resourceConfig);
+ return this.resourceConfig;
}
@Test
void meterResourceTest() throws InterruptedException {
- String response = target("/meter").request().get(String.class);
- assertEquals(response, CLICHED_MESSAGE);
+ final String response = target("/timed").request().get(String.class);
+ assertEquals(response, MESSAGE);
+ for (int i = 0; i < REQUESTS_COUNT; i++) {
+ target("/metrics").request().get(String.class);
+ }
// Jersey metrics are recorded asynchronously to the request completing
Thread.sleep(10);
- Timer timer = registry.get(TIMER_METRIC_NAME)
- .tags("method", "GET", "uri", "/meter", "status", "200", "exception", "None", "outcome", "SUCCESS")
+ Timer timer = resourceConfig.getStore().getRegistry()
+ .get(MetricsStore.REGISTRY_NAME)
+ .tags("method", "GET", "uri", "/metrics", "status", "200", "exception", "None", "outcome", "SUCCESS")
.timer();
- assertEquals(timer.count(), 1);
+ assertEquals(REQUESTS_COUNT, timer.count());
assertNotNull(timer.totalTime(TimeUnit.NANOSECONDS));
}
diff --git a/ext/microprofile/pom.xml b/ext/microprofile/pom.xml
index cccbb17..647b7b3 100644
--- a/ext/microprofile/pom.xml
+++ b/ext/microprofile/pom.xml
@@ -33,8 +33,7 @@
<modules>
<module>mp-rest-client</module>
- <module>mp-config</module>
+ <module>mp-config</module>
</modules>
-
-</project>
+</project>
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 576f8c6..53357ac 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1171,7 +1171,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
- <version>2.7</version>
+ <version>3.4.5</version>
<reportSets>
<reportSet>
<reports>
@@ -2323,7 +2323,7 @@
<jsp.version>2.3.6</jsp.version>
<jstl.version>1.2.7</jstl.version>
<jta.api.version>1.3.3</jta.api.version>
- <micrometer.version>1.10.10</micrometer.version>
+ <micrometer.version>1.10.12</micrometer.version>
<micrometer-tracing.version>1.0.9</micrometer-tracing.version>
<microprofile.config.version>2.0.1</microprofile.config.version>
<microprofile.rest.client.version>2.0</microprofile.rest.client.version>