Skip to content

Commit

Permalink
alignment
Browse files Browse the repository at this point in the history
Signed-off-by: Maxim Nesen <[email protected]>
  • Loading branch information
senivam committed Oct 17, 2023
1 parent 9f04352 commit fdcfea5
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 33 deletions.
49 changes: 21 additions & 28 deletions docs/src/main/docbook/micrometer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,32 +30,26 @@
<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 &micrometer.jersey.link;
There is also support for Jakarta EE 10 integration. Detailed documentation regarding metrics fine-tuning
can be found at the &micrometer.link;
Before Jersey 2.41, it was possible to integrate Micrometer with Jersey using directly &micrometer.jersey.link;.
There is also support for Jakarta EE 10 integration. The detailed documentation regarding metrics fine-tuning
can be found at the &micrometer.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">
&lt;dependency>
&lt;groupId>org.glassfish.jersey.ext.micrometer&lt;/groupId>
&lt;artifactId>jersey-micrometer&lt;/artifactId>
&lt;version>&version;&lt;/scope>
&lt;/dependency>
</programlisting>
<programlisting language="xml" linenumbering="unnumbered">&lt;dependency>
&lt;groupId>org.glassfish.jersey.ext.micrometer&lt;/groupId>
&lt;artifactId>jersey-micrometer&lt;/artifactId>
&lt;version>&version;&lt;/scope>
&lt;/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(
<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>
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
Expand All @@ -72,21 +66,20 @@
</para>
<para>
Implementing resource methods, which should be measured, several annotations can be used. The basic example
demonstrates the <listeral>@Counted</listeral> annotation.
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 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 set of <literal>@Timed</literal>.
<literal>@TimedSet</literal> which is a set of <literal>@Timed</literal>.
</para>
</section>
</chapter>
2 changes: 1 addition & 1 deletion docs/src/main/docbook/user-guide.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ This line fits the page width.
<xi:include href="uris-and-links.xml" />
<xi:include href="declarative-linking.xml" />
<xi:include href="resource-builder.xml" />
<xi:include href="micrometer.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" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
@Path("measure")
public class MeasuredTimedResource {

public static final String CLICHED_MESSAGE = "Requests to this method are measured. Use /metrics to see more";
public static final String MESSAGE = "Requests to this method are measured. Use /metrics to see more";
public static final String TIMER_NAME = "http.timers";
public static final String TIMER_DESCRIPTION = "resource measurement timer";

Expand All @@ -28,6 +28,6 @@ public class MeasuredTimedResource {
@Timed(value = TIMER_NAME, description = TIMER_DESCRIPTION, histogram = true)
@Path("timed")
public String getTimedMessage() {
return CLICHED_MESSAGE;
return MESSAGE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import javax.ws.rs.core.Application;
import java.util.concurrent.TimeUnit;

import static org.glassfish.jersey.examples.micrometer.MeasuredTimedResource.CLICHED_MESSAGE;
import static org.glassfish.jersey.examples.micrometer.MeasuredTimedResource.MESSAGE;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

Expand All @@ -37,7 +37,7 @@ protected Application configure() {
@Test
void meterResourceTest() throws InterruptedException {
final String response = target("/measure/timed").request().get(String.class);
assertEquals(response, CLICHED_MESSAGE);
assertEquals(response, MESSAGE);
for (int i = 0; i < REQUESTS_COUNT; i++) {
target("/metrics").request().get(String.class);
}
Expand Down

0 comments on commit fdcfea5

Please sign in to comment.