Skip to content

Commit

Permalink
Update MP Metrics Starter UI (#9403)
Browse files Browse the repository at this point in the history
  • Loading branch information
tvallin authored Oct 25, 2024
1 parent 28a61b0 commit 6d1b5b1
Show file tree
Hide file tree
Showing 4 changed files with 222 additions and 309 deletions.
289 changes: 3 additions & 286 deletions archetypes/helidon/src/main/archetype/common/observability.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,295 +28,13 @@
default="false"
optional="true">
<inputs>
<enum id="provider"
name="Select a Metrics Provider"
default="microprofile"
optional="true"
if="${flavor} == 'mp'">
<option value="microprofile"
name="MicroProfile"
description="Expose metrics using the MicroProfile API">
<output>
<model>
<list key="readme-sections">
<value><![CDATA[
## Try metrics
```
# Prometheus Format
curl -s -X GET http://localhost:8080/metrics
# TYPE base:gc_g1_young_generation_count gauge
. . .
# JSON Format
curl -H 'Accept: application/json' -X GET http://localhost:8080/metrics
{"base":...
. . .
```
]]></value>
</list>
<list key="dependencies">
<map order="800">
<value key="groupId">org.eclipse.microprofile.metrics</value>
<value key="artifactId">microprofile-metrics-api</value>
</map>
<map order="800">
<value key="groupId">io.helidon.microprofile.metrics</value>
<value key="artifactId">helidon-microprofile-metrics</value>
</map>
</list>
<list key="SimpleGreetService-imports">
<value>org.eclipse.microprofile.metrics.MetricUnits</value>
<value>org.eclipse.microprofile.metrics.annotation.Counted</value>
<value>org.eclipse.microprofile.metrics.annotation.Timed</value>
<value>jakarta.ws.rs.PathParam</value>
</list>
<list key="SimpleGreetResource-static-fields">
<value><![CDATA[
private static final String PERSONALIZED_GETS_COUNTER_NAME = "personalizedGets";
private static final String PERSONALIZED_GETS_COUNTER_DESCRIPTION = "Counts personalized GET operations";
private static final String GETS_TIMER_NAME = "allGets";
private static final String GETS_TIMER_DESCRIPTION = "Tracks all GET operations";]]></value>
</list>
<list key="SimpleGreetService-methods">
<value><![CDATA[
@Path("/{name}")
@GET
@Produces(MediaType.APPLICATION_JSON)
@Counted(name = PERSONALIZED_GETS_COUNTER_NAME,
absolute = true,
description = PERSONALIZED_GETS_COUNTER_DESCRIPTION)
@Timed(name = GETS_TIMER_NAME,
description = GETS_TIMER_DESCRIPTION,
unit = MetricUnits.SECONDS,
absolute = true)
public String getMessage(@PathParam("name") String name) {
return String.format("Hello %s", name);
}]]></value>
</list>
<list key="MainTest-java-imports">
<value>org.eclipse.microprofile.metrics.Counter</value>
<value>org.eclipse.microprofile.metrics.MetricRegistry</value>
</list>
<list key="MainTest-static-imports">
<value>static org.junit.jupiter.api.Assertions.assertEquals</value>
</list>
<list key="MainTest-methods">
<value><![CDATA[
@Test
void testMicroprofileMetrics() {
String message = target.path("simple-greet/Joe")
.request()
.get(String.class);
assertThat(message, is("Hello Joe"));
Counter counter = registry.counter("personalizedGets");
double before = counter.getCount();
message = target.path("simple-greet/Eric")
.request()
.get(String.class);
assertThat(message, is("Hello Eric"));
double after = counter.getCount();
assertEquals(1d, after - before, "Difference in personalized greeting counter between successive calls");
}]]></value>
</list>
<list key="MainTest-static-fields">
<value><![CDATA[
@Inject
private MetricRegistry registry;]]></value>
</list>
<list key="module-requires">
<value>io.helidon.microprofile.metrics</value>
</list>
</model>
</output>
</option>
<option value="micrometer"
name="Micrometer"
description="Expose metrics using the Micrometer API">
<output>
<model>
<list key="dependencies">
<map>
<value key="groupId">io.helidon.integrations.micrometer</value>
<value key="artifactId">helidon-integrations-micrometer-cdi</value>
</map>
</list>
<list key="SimpleGreetService-imports">
<value>io.micrometer.core.annotation.Counted</value>
<value>io.micrometer.core.annotation.Timed</value>
<value>jakarta.ws.rs.PathParam</value>
</list>
<list key="SimpleGreetResource-static-fields">
<value><![CDATA[
private static final String PERSONALIZED_GETS_COUNTER_NAME = "personalizedGets";
private static final String PERSONALIZED_GETS_COUNTER_DESCRIPTION = "Counts personalized GET operations";
private static final String GETS_TIMER_NAME = "allGets";
private static final String GETS_TIMER_DESCRIPTION = "Tracks all GET operations";]]></value>
</list>
<list key="SimpleGreetService-methods">
<value><![CDATA[
@Path("/{name}")
@GET
@Produces(MediaType.APPLICATION_JSON)
@Counted(value = PERSONALIZED_GETS_COUNTER_NAME, description = PERSONALIZED_GETS_COUNTER_DESCRIPTION)
@Timed(value = GETS_TIMER_NAME, description = GETS_TIMER_DESCRIPTION, histogram = true)
public String getMessage(@PathParam("name") String name) {
return String.format("Hello %s", name);
}]]></value>
</list>
<list key="Main-helidon-imports">
<value>io.helidon.integrations.micrometer.MicrometerSupport</value>
</list>
<list key="Main-createRouting">
<value><![CDATA[ MicrometerSupport micrometerSupport = MicrometerSupport.create();]]></value>
</list>
<list key="Main-routingBuilder">
<value><![CDATA[ .register(micrometerSupport)
.register("/micrometer-greet", new SimpleGreetService(config, micrometerSupport.registry()))]]></value>
</list>
<list key="MainTest-methods">
<value><![CDATA[
@Test
void testMicrometerMetrics() {
String message = target.path("simple-greet/Joe")
.request()
.get(String.class);
assertThat(message, is("Hello Joe"));
Counter counter = registry.counter("personalizedGets");
double before = counter.count();
message = target.path("simple-greet/Eric")
.request()
.get(String.class);
assertThat(message, is("Hello Eric"));
double after = counter.count();
assertEquals(1d, after - before, "Difference in personalized greeting counter between successive calls");
}]]></value>
</list>
<list key="MainTest-static-fields">
<value><![CDATA[
@Inject
private MeterRegistry registry;]]></value>
</list>
<list key="MainTest-java-imports">
<value>io.micrometer.core.instrument.Counter</value>
<value>io.micrometer.core.instrument.MeterRegistry</value>
</list>
<list key="MainTest-static-imports">
<value>static org.junit.jupiter.api.Assertions.assertEquals</value>
</list>
<list key="module-requires">
<value>io.helidon.integrations.micrometer</value>
</list>
<list key="readme-sections">
<value><![CDATA[
## Using Micrometer
Access the `/micrometer` endpoint which reports the newly-added timer and counter.
```bash
curl http://localhost:8080/micrometer
```
`SimpleGreetService` has a micrometer counter that is incremented each time a GET request is made at
`http://localhost:8080/greet-count`. The counter name is `allRequests` and is shown in the console
with the number of time it was triggered.
```
curl http://localhost:8080/micrometer
# HELP allRequests_total
# TYPE allRequests_total counter
allRequests_total 0.0
```
]]></value>
</list>
</model>
</output>
</option>
</enum>
<boolean id="builtin"
name="Built-in Metrics"
description="Expose common metrics"
default="true"
optional="true">
<output>
<model>
<list key="dependencies">
<map order="800" if="${flavor} == 'se'">
<value key="groupId">io.helidon.metrics</value>
<value key="artifactId">helidon-metrics</value>
</map>
</list>
<list key="Main-helidon-imports" if="${flavor} == 'se'">
<value>io.helidon.metrics.MetricsSupport</value>
</list>
<list key="Main-routingBuilder" if="${flavor} == 'se'">
<value><![CDATA[ .register(MetricsSupport.create()) // Metrics at "/metrics"]]></value>
</list>
<list key="MainTest-methods">
<value if="${flavor} == 'mp'"><![CDATA[
@Test
void testMetrics() {
Response response = target
.path("metrics")
.request()
.get();
assertThat(response.getStatus(), is(200));
}]]></value>
<value if="${flavor} == 'se'"><![CDATA[
@Test
void testMetrics() {
WebClientResponse response = webClient.get()
.path("/metrics")
.request()
.await(Duration.ofSeconds(5));
assertThat(response.status().code(), is(200));
}]]></value>
</list>
<list key="module-requires" if="${flavor} == 'se'">
<value>io.helidon.metrics</value>
</list>
<list key="readme-sections" if="${flavor} == 'se'">
<value><![CDATA[
## Try metrics
```
# Prometheus Format
curl -s -X GET http://localhost:8080/metrics
# TYPE base:gc_g1_young_generation_count gauge
. . .
# JSON Format
curl -H 'Accept: application/json' -X GET http://localhost:8080/metrics
{"base":...
. . .
```
]]></value>
</list>
</model>
</output>
</boolean>
optional="true"
if="${flavor} == 'se'"/>
</inputs>
<output if="${db} &amp;&amp; ${flavor} == 'se'">
<model>
<list key="dependencies">
<map>
<value key="groupId">io.helidon.dbclient</value>
<value key="artifactId">helidon-dbclient-metrics-jdbc</value>
</map>
<map>
<value key="groupId">io.helidon.dbclient</value>
<value key="artifactId">helidon-dbclient-metrics</value>
</map>
</list>
</model>
</output>
</boolean>
<boolean id="health"
name="Health Checks"
Expand Down Expand Up @@ -484,8 +202,7 @@ curl -s -X GET http://localhost:8080/health
<!-- TODO https://github.com/oracle/helidon-build-tools/issues/609 -->
<model>
<value key="metrics" if="${metrics}">true</value>
<value key="metrics.provider" if="${metrics} &amp;&amp; ${flavor} == 'mp'">${metrics.provider}</value>
<value key="metrics.builtin" if="${metrics}">${metrics.builtin}</value>
<value key="metrics.builtin" if="${metrics} &amp;&amp; ${flavor} == 'se'">${metrics.builtin}</value>
<value key="health" if="${health}">true</value>
<value key="health.builtin" if="${health}">${health.builtin}</value>
<value key="tracing" if="${tracing}">true</value>
Expand Down
1 change: 0 additions & 1 deletion archetypes/helidon/src/main/archetype/common/presets.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
<value>json</value>
</list>
<boolean path="metrics">true</boolean>
<enum path="metrics.provider">microprofile</enum>
<boolean path="metrics.builtin">true</boolean>
<boolean path="health">true</boolean>
<boolean path="health.builtin">true</boolean>
Expand Down
Loading

0 comments on commit 6d1b5b1

Please sign in to comment.