Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4.x Refactor archetype metrics #7556

Merged
merged 2 commits into from
Sep 9, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions archetypes/helidon/src/main/archetype/common/extra.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ java -cp "target/classes:target/libs/*" {{package}}.WebClientMain PORT
<value key="groupId">io.helidon.microprofile.metrics</value>
<value key="artifactId">helidon-microprofile-metrics</value>
</map>
<map>
<value key="groupId">io.helidon.metrics</value>
<value key="artifactId">helidon-metrics</value>
<value key="scope">compile</value>
tvallin marked this conversation as resolved.
Show resolved Hide resolved
</map>
</list>
<list key="modules">
<value if="${flavor} == 'mp'">io.helidon.microprofile.faulttolerance</value>
Expand Down
151 changes: 84 additions & 67 deletions archetypes/helidon/src/main/archetype/common/observability.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,24 @@ curl -H 'Accept: application/json' -X GET http://localhost:8080/metrics

]]></value>
</list>
<list key="dependencies" if="${flavor} == 'mp'">
<map order="800">
<list key="dependencies">
<map>
<value key="groupId">io.helidon.metrics</value>
<value key="artifactId">helidon-metrics</value>
<value key="scope">runtime</value>
</map>
<map if="${flavor} == 'mp'">
<value key="groupId">org.eclipse.microprofile.metrics</value>
<value key="artifactId">microprofile-metrics-api</value>
</map>
<map order="800">
<map if="${flavor} == 'mp'">
<value key="groupId">io.helidon.microprofile.metrics</value>
<value key="artifactId">helidon-microprofile-metrics</value>
</map>
<map if="${flavor} == 'se'">
<value key="groupId">io.helidon.webserver.observe</value>
<value key="artifactId">helidon-webserver-observe-metrics</value>
</map>
</list>
<list key="SimpleGreetService-imports" if="${flavor} == 'mp'">
<value>org.eclipse.microprofile.metrics.MetricUnits</value>
Expand Down Expand Up @@ -98,9 +107,23 @@ curl -H 'Accept: application/json' -X GET http://localhost:8080/metrics
<value>org.eclipse.microprofile.metrics.Counter</value>
<value>org.eclipse.microprofile.metrics.MetricRegistry</value>
</list>
<list key="MainTest-helidon-imports">
<value>io.helidon.metrics.api.MetricsFactory</value>
</list>
<list key="MainTest-other-imports">
<value>org.junit.jupiter.api.BeforeAll</value>
</list>
<list key="MainTest-static-imports" if="${flavor} == 'mp'">
<value>static org.junit.jupiter.api.Assertions.assertEquals</value>
</list>
<list key="MainTest-methods" order="999">
<value><![CDATA[
@BeforeAll
static void clear() {
MetricsFactory.closeAll();
}
]]></value>
</list>
<list key="MainTest-methods" if="${flavor} == 'mp'">
<value><![CDATA[
@Test
Expand Down Expand Up @@ -190,7 +213,6 @@ curl -H 'Accept: application/json' -X GET http://localhost:8080/metrics
</list>
<list key="modules" if="${flavor} == 'mp'">
<value>io.helidon.microprofile.metrics</value>
<value>micrometer.core</value>
</list>
</model>
</output>
Expand All @@ -201,18 +223,28 @@ curl -H 'Accept: application/json' -X GET http://localhost:8080/metrics
<output>
<model>
<list key="dependencies">
<map if="${flavor} == 'mp'">
<value key="groupId">io.helidon.integrations.micrometer</value>
<value key="artifactId">helidon-integrations-micrometer-cdi</value>
<map>
<value key="groupId">io.helidon.metrics</value>
<value key="artifactId">helidon-metrics-api</value>
<value key="scope">compile</value>
tvallin marked this conversation as resolved.
Show resolved Hide resolved
</map>
<map>
<value key="groupId">io.helidon.metrics</value>
<value key="artifactId">helidon-metrics</value>
<value key="scope">runtime</value>
</map>
<map if="${flavor} == 'se'">
<value key="groupId">io.helidon.integrations.micrometer</value>
<value key="artifactId">helidon-integrations-micrometer</value>
<value key="groupId">io.helidon.webserver.observe</value>
<value key="artifactId">helidon-webserver-observe-metrics</value>
</map>
<map if="${flavor} == 'mp'">
<value key="groupId">org.eclipse.microprofile.metrics</value>
<value key="artifactId">microprofile-metrics-api</value>
</map>
</list>
<list key="SimpleGreetService-imports" if="${flavor} == 'mp'">
<value>io.micrometer.core.annotation.Counted</value>
<value>io.micrometer.core.annotation.Timed</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" if="${flavor} == 'mp'">
Expand All @@ -227,17 +259,34 @@ curl -H 'Accept: application/json' -X GET http://localhost:8080/metrics
@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)
@Counted(name = PERSONALIZED_GETS_COUNTER_NAME, description = PERSONALIZED_GETS_COUNTER_DESCRIPTION, absolute = true)
@Timed(name = GETS_TIMER_NAME, description = GETS_TIMER_DESCRIPTION, absolute = true)
public String getMessage(@PathParam("name") String name) {
return String.format("Hello %s", name);
}]]></value>
</list>
<list key="Main-helidon-imports" if="${flavor} == 'mp'">
<value>io.helidon.integrations.micrometer.MicrometerSupport</value>
<list key="MainTest-java-imports" if="${flavor} == 'mp'">
<value>org.eclipse.microprofile.metrics.Counter</value>
<value>org.eclipse.microprofile.metrics.MetricRegistry</value>
</list>
<list key="MainTest-helidon-imports">
<value>io.helidon.metrics.api.MetricsFactory</value>
</list>
<list key="MainTest-other-imports">
<value>org.junit.jupiter.api.BeforeAll</value>
</list>
<list key="MainTest-static-fields" if="${flavor} == 'mp'">
<value><![CDATA[
@Inject
private MetricRegistry registry;]]></value>
</list>
<list key="Main-createRouting" if="${flavor} == 'mp'">
<value><![CDATA[ MicrometerSupport micrometerSupport = MicrometerSupport.create();]]></value>
<list key="MainTest-methods" order="999">
<value><![CDATA[
@BeforeAll
static void clear() {
MetricsFactory.closeAll();
}
]]></value>
</list>
<list key="MainTest-methods" if="${flavor} == 'mp'">
<value><![CDATA[
Expand All @@ -249,58 +298,50 @@ curl -H 'Accept: application/json' -X GET http://localhost:8080/metrics

assertThat(message, is("Hello Joe"));
Counter counter = registry.counter("personalizedGets");
double before = counter.count();
double before = counter.getCount();

message = target.path("simple-greet/Eric")
.request()
.get(String.class);

assertThat(message, is("Hello Eric"));
double after = counter.count();
double after = counter.getCount();
assertEquals(1d, after - before, "Difference in personalized greeting counter between successive calls");
}]]></value>
</list>
<list key="MainTest-static-fields" if="${flavor} == 'mp'">
<value><![CDATA[
@Inject
private MeterRegistry registry;]]></value>
tjquinno marked this conversation as resolved.
Show resolved Hide resolved
</list>
<list key="MainTest-java-imports" if="${flavor} == 'mp'">
<value>io.micrometer.core.instrument.Counter</value>
<value>io.micrometer.core.instrument.MeterRegistry</value>
</list>
<list key="MainTest-static-imports" if="${flavor} == 'mp'">
<value>static org.junit.jupiter.api.Assertions.assertEquals</value>
</list>
<list key="readme-sections" if="${flavor} == 'se'">
<value><![CDATA[
## Using Micrometer

Access the `/micrometer` endpoint which reports the newly-added timer and counter.
Access the `/observe/metrics` endpoint which reports the newly-added timer and counter.

```bash
curl http://localhost:8080/micrometer
curl http://localhost:8080/observe/metrics
```
`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
curl http://localhost:8080/observe/metrics
# HELP allRequests_total
# TYPE allRequests_total counter
allRequests_total 0.0
```
]]></value>
</list>
<list key="MetricsService-imports">
<value>io.helidon.integrations.micrometer.MicrometerFeature</value>
<value>io.micrometer.core.instrument.Counter</value>
<value>io.micrometer.core.instrument.Timer</value>
<value>io.helidon.metrics.api.Counter</value>
<value>io.helidon.metrics.api.Metrics</value>
<value>io.helidon.metrics.api.MeterRegistry</value>
<value>io.helidon.metrics.api.Timer</value>
</list>
<list key="MetricsService-routing">
<value><![CDATA[
.get((req, resp) -> getTimer.record(resp::next))
.get((req, resp) -> getTimer.record((Runnable) resp::next))
.get("/{name}",
(req, resp) -> {
personalizedGetCounter.increment();
Expand All @@ -313,24 +354,13 @@ allRequests_total 0.0
static final String ALL_GETS_TIMER_NAME = "allGets";

private final Timer getTimer;
private final Counter personalizedGetCounter;
private final MicrometerFeature micrometerFeature;]]></value>
private final Counter personalizedGetCounter;]]></value>
</list>
<list key="MetricsService-constructor">
<value><![CDATA[
this.micrometerFeature = MicrometerFeature.create(config);
this.personalizedGetCounter = micrometerFeature.registry()
.counter(PERSONALIZED_GETS_COUNTER_NAME);
this.getTimer = Timer.builder(ALL_GETS_TIMER_NAME)
.publishPercentileHistogram()
.register(micrometerFeature.registry());]]></value>
</list>
<list key="MetricsService-methods">
<value><![CDATA[
MicrometerFeature micrometerFeature() {
return micrometerFeature;
}
]]></value>
MeterRegistry registry = Metrics.globalRegistry();
this.personalizedGetCounter = registry.getOrCreate(Counter.builder(PERSONALIZED_GETS_COUNTER_NAME));
this.getTimer = registry.getOrCreate(Timer.builder(ALL_GETS_TIMER_NAME));]]></value>
</list>
<list key="MainTest-static-imports">
<value if="${flavor} == 'se'">org.hamcrest.CoreMatchers.containsString</value>
Expand All @@ -350,7 +380,7 @@ allRequests_total 0.0
assertThat(response.status().code(), is(200));

response = client.get()
.path("/micrometer")
.path("/observe/metrics")
.request();
assertThat(response.status().code(), is(200));

Expand All @@ -373,12 +403,10 @@ allRequests_total 0.0
]]></value>
</list>
<list key="Main-routing-builder" if="${flavor} == 'se'">
<value><![CDATA[.register("/metrics-greet", metricsService)
.addFeature(metricsService.micrometerFeature())]]></value>
<value><![CDATA[.register("/metrics-greet", metricsService)]]></value>
</list>
<list key="modules">
<value if="${flavor} == 'se'">io.helidon.integrations.micrometer</value>
<value>micrometer.core</value>
<list key="modules" if="${flavor} == 'mp'">
<value>io.helidon.microprofile.metrics</value>
</list>
</model>
</output>
Expand All @@ -391,17 +419,6 @@ allRequests_total 0.0
optional="true">
<output>
<model>
<list key="MainTest-methods" if="${flavor} == 'mp'">
<value><![CDATA[
@Test
void testMetrics() {
Response response = target
.path("metrics")
.request()
.get();
assertThat(response.getStatus(), is(200));
}]]></value>
</list>
<list key="readme-sections" if="!(${metrics.provider} == 'microprofile') &amp;&amp; ${flavor} != 'se'">
<value><![CDATA[
## Try metrics
Expand Down
5 changes: 5 additions & 0 deletions archetypes/helidon/src/main/archetype/mp/oci/oci-mp.xml
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ ocimetrics:
<value key="artifactId">jandex</value>
<value key="scope">runtime</value>
</map>
<map order="0">
<value key="groupId">io.helidon.metrics</value>
<value key="artifactId">helidon-metrics</value>
<value key="scope">runtime</value>
</map>
<map order="0">
<value key="groupId">org.junit.jupiter</value>
<value key="artifactId">junit-jupiter-api</value>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,6 @@
<value>.addFeature(observe)</value>
</list>
<list key="dependencies">
<map if="${metrics}">
<value key="groupId">io.helidon.webserver.observe</value>
<value key="artifactId">helidon-webserver-observe-metrics</value>
</map>
<map if="${metrics}">
<value key="groupId">io.helidon.metrics</value>
<value key="artifactId">helidon-metrics</value>
</map>
<map if="${tracing}">
<value key="groupId">io.helidon.webserver</value>
<value key="artifactId">helidon-webserver-tracing</value>
Expand Down
Loading