forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request quarkusio#37638 from ebullient/mp-scope
Add scope tag to all injected MP Metrics
- Loading branch information
Showing
3 changed files
with
82 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 27 additions & 1 deletion
28
...crometer-mp-metrics/src/main/java/io/quarkus/it/micrometer/mpmetrics/MessageResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,60 @@ | ||
package io.quarkus.it.micrometer.mpmetrics; | ||
|
||
import java.util.Collection; | ||
import java.util.Objects; | ||
|
||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.PathParam; | ||
|
||
import org.eclipse.microprofile.metrics.Counter; | ||
import org.eclipse.microprofile.metrics.annotation.Metric; | ||
|
||
import io.micrometer.core.instrument.Meter; | ||
import io.micrometer.core.instrument.MeterRegistry; | ||
import io.micrometer.core.instrument.search.Search; | ||
|
||
@Path("/message") | ||
public class MessageResource { | ||
|
||
private final MeterRegistry registry; | ||
private final Counter first; | ||
private final Counter second; | ||
|
||
public MessageResource(MeterRegistry registry) { | ||
public MessageResource(MeterRegistry registry, | ||
@Metric(name = "first-counter") final Counter first, | ||
@Metric(name = "second-counter") final Counter second) { | ||
this.registry = registry; | ||
this.first = Objects.requireNonNull(first); | ||
this.second = Objects.requireNonNull(second); | ||
} | ||
|
||
@GET | ||
public String message() { | ||
first.inc(); | ||
second.inc(); | ||
return registry.getClass().getName(); | ||
} | ||
|
||
@GET | ||
@Path("fail") | ||
public String fail() { | ||
first.inc(); | ||
throw new NullPointerException("Failed on purpose"); | ||
} | ||
|
||
@GET | ||
@Path("item/{id}") | ||
public String item(@PathParam("id") String id) { | ||
second.inc(); | ||
return "return message with id " + id; | ||
} | ||
|
||
@GET | ||
@Path("mpmetrics") | ||
public String metrics() { | ||
Collection<Meter> meters = Search.in(registry).name(s -> s.contains("mpmetrics")).meters(); | ||
meters.addAll(Search.in(registry).name(s -> s.endsWith("-counter")).meters()); | ||
return meters.stream().allMatch(x -> x.getId().getTag("scope") != null) ? "OK" : "FAIL"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters