Skip to content

Commit

Permalink
Polish CountedAspect
Browse files Browse the repository at this point in the history
  • Loading branch information
izeye committed Feb 19, 2024
1 parent e68ea21 commit 9da084f
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import io.micrometer.core.annotation.Counted;
import io.micrometer.core.instrument.*;
import io.micrometer.core.lang.NonNullApi;
import io.micrometer.core.lang.Nullable;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
Expand Down Expand Up @@ -103,7 +104,7 @@ public class CountedAspect {
private final Function<ProceedingJoinPoint, Iterable<Tag>> tagsBasedOnJoinPoint;

/**
* A predicate that decides if Timer creation should be skipped for the given join
* A predicate that decides if counter creation should be skipped for the given join
* point.
*/
private final Predicate<ProceedingJoinPoint> shouldSkip;
Expand Down Expand Up @@ -139,8 +140,8 @@ public CountedAspect(MeterRegistry registry, Function<ProceedingJoinPoint, Itera
* Creates a {@code CountedAspect} instance with the given {@code registry} and skip
* predicate.
* @param registry Where we're going to register metrics.
* @param shouldSkip A predicate to decide if creating the timer should be skipped or
* not.
* @param shouldSkip A predicate to decide if creating the counter should be skipped
* or not.
* @since 1.7.0
*/
public CountedAspect(MeterRegistry registry, Predicate<ProceedingJoinPoint> shouldSkip) {
Expand All @@ -153,8 +154,8 @@ public CountedAspect(MeterRegistry registry, Predicate<ProceedingJoinPoint> shou
* provider function and skip predicate.
* @param registry Where we're going to register metrics.
* @param tagsBasedOnJoinPoint A function to generate tags given a join point.
* @param shouldSkip A predicate to decide if creating the timer should be skipped or
* not.
* @param shouldSkip A predicate to decide if creating the counter should be skipped
* or not.
* @since 1.7.0
*/
public CountedAspect(MeterRegistry registry, Function<ProceedingJoinPoint, Iterable<Tag>> tagsBasedOnJoinPoint,
Expand Down Expand Up @@ -183,6 +184,7 @@ public CountedAspect(MeterRegistry registry, Function<ProceedingJoinPoint, Itera
* @throws Throwable When the intercepted method throws one.
*/
@Around("@annotation(counted)")
@Nullable
public Object interceptAndRecord(ProceedingJoinPoint pjp, Counted counted) throws Throwable {
if (shouldSkip.test(pjp)) {
return pjp.proceed();
Expand Down

0 comments on commit 9da084f

Please sign in to comment.