-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve REST endpoint details in prometheus metrics endpoint (#100)
* Decorate endpoints for Metrics fetch Signed-off-by: “Nithin <[email protected]> * Introduce aspects for decorating REST endpoints for metrics publish Signed-off-by: “Nithin <[email protected]> --------- Signed-off-by: “Nithin <[email protected]> Co-authored-by: “Nithin <[email protected]>
- Loading branch information
1 parent
da99aeb
commit 766504b
Showing
5 changed files
with
80 additions
and
0 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
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
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
16 changes: 16 additions & 0 deletions
16
src/main/java/hlf/java/rest/client/metrics/MetricsTrackedEndpoint.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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package hlf.java.rest.client.metrics; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Target(ElementType.METHOD) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface MetricsTrackedEndpoint { | ||
String name(); | ||
|
||
String uri(); | ||
|
||
String method(); | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/hlf/java/rest/client/metrics/MetricsTrackedEndpointAspect.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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package hlf.java.rest.client.metrics; | ||
|
||
import io.micrometer.core.instrument.Gauge; | ||
import io.micrometer.core.instrument.MeterRegistry; | ||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import org.aspectj.lang.JoinPoint; | ||
import org.aspectj.lang.annotation.After; | ||
import org.aspectj.lang.annotation.Aspect; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Aspect | ||
@Component | ||
public class MetricsTrackedEndpointAspect { | ||
|
||
@Autowired private MeterRegistry meterRegistry; | ||
|
||
private Map<String, Boolean> trackedEndpoints = new ConcurrentHashMap<>(); | ||
|
||
@After("@annotation(metricsTrackedEndpoint)") | ||
public void afterTimedEndpoint( | ||
JoinPoint joinPoint, MetricsTrackedEndpoint metricsTrackedEndpoint) { | ||
|
||
trackedEndpoints.computeIfAbsent( | ||
metricsTrackedEndpoint.name(), | ||
val -> { | ||
Gauge.builder("tracked_endpoints", () -> 1L) | ||
.tag("name", metricsTrackedEndpoint.name()) | ||
.tag("method", metricsTrackedEndpoint.method()) | ||
.tag("uri", metricsTrackedEndpoint.uri()) | ||
.register(meterRegistry); | ||
|
||
return true; | ||
}); | ||
} | ||
} |