Skip to content

Commit

Permalink
Polish aspect changes
Browse files Browse the repository at this point in the history
  • Loading branch information
izeye committed Apr 10, 2021
1 parent 08d94f6 commit 1b01022
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
/**
* <p>
* Aspect responsible for intercepting all methods annotated with the {@link Counted @Counted}
* annotation and record a few counter metrics about their execution status.<br />
* annotation and recording a few counter metrics about their execution status.<br />
* The aspect supports programmatic customizations through constructor-injectable custom logic.
* </p>
* <p>
Expand Down Expand Up @@ -90,7 +90,7 @@ public class CountedAspect {
/**
* Where we're going register metrics.
*/
private final MeterRegistry meterRegistry;
private final MeterRegistry registry;

/**
* A function to produce additional tags for any given join point.
Expand All @@ -105,13 +105,14 @@ public class CountedAspect {
/**
* Creates a {@code CountedAspect} instance with {@link Metrics#globalRegistry}.
*
* @since 1.7.0
*/
public CountedAspect() {
this(Metrics.globalRegistry);
}

/**
* Creates a {@code CountedAspect} instance with the given {@code meterRegistry}.
* Creates a {@code CountedAspect} instance with the given {@code registry}.
*
* @param registry Where we're going to register metrics.
*/
Expand All @@ -120,39 +121,41 @@ public CountedAspect(MeterRegistry registry) {
}

/**
* Creates a {@code CountedAspect} instance with the given {@code meterRegistry} and tags provider function.
* Creates a {@code CountedAspect} instance with the given {@code registry} and tags provider function.
*
* @param meterRegistry Where we're going to register metrics.
* @param registry Where we're going to register metrics.
* @param tagsBasedOnJoinPoint A function to generate tags given a join point.
*/
public CountedAspect(MeterRegistry meterRegistry, Function<ProceedingJoinPoint, Iterable<Tag>> tagsBasedOnJoinPoint) {
this(meterRegistry, tagsBasedOnJoinPoint, DONT_SKIP_ANYTHING);
public CountedAspect(MeterRegistry registry, Function<ProceedingJoinPoint, Iterable<Tag>> tagsBasedOnJoinPoint) {
this(registry, tagsBasedOnJoinPoint, DONT_SKIP_ANYTHING);
}

/**
* Creates a {@code CountedAspect} instance with the given {@code meterRegistry} and skip predicate.
* Creates a {@code CountedAspect} instance with the given {@code registry} and skip predicate.
*
* @param meterRegistry Where we're going to register metrics.
* @param registry Where we're going to register metrics.
* @param shouldSkip A predicate to decide if creating the timer should be skipped or not.
* @since 1.7.0
*/
public CountedAspect(MeterRegistry meterRegistry, Predicate<ProceedingJoinPoint> shouldSkip) {
public CountedAspect(MeterRegistry registry, Predicate<ProceedingJoinPoint> shouldSkip) {
this(
meterRegistry,
registry,
pjp -> Tags.of("class", pjp.getStaticPart().getSignature().getDeclaringTypeName(),
"method", pjp.getStaticPart().getSignature().getName()),
shouldSkip
);
}

/**
* Creates a {@code CountedAspect} instance with the given {@code meterRegistry}, tags provider function and skip predicate.
* Creates a {@code CountedAspect} instance with the given {@code registry}, tags provider function and skip predicate.
*
* @param meterRegistry Where we're going to register metrics.
* @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.
* @since 1.7.0
*/
public CountedAspect(MeterRegistry meterRegistry, Function<ProceedingJoinPoint, Iterable<Tag>> tagsBasedOnJoinPoint, Predicate<ProceedingJoinPoint> shouldSkip) {
this.meterRegistry = meterRegistry;
public CountedAspect(MeterRegistry registry, Function<ProceedingJoinPoint, Iterable<Tag>> tagsBasedOnJoinPoint, Predicate<ProceedingJoinPoint> shouldSkip) {
this.registry = registry;
this.tagsBasedOnJoinPoint = tagsBasedOnJoinPoint;
this.shouldSkip = shouldSkip;
}
Expand Down Expand Up @@ -221,7 +224,7 @@ private void record(ProceedingJoinPoint pjp, Counted counted, String exception,
.tag(EXCEPTION_TAG, exception)
.tag(RESULT_TAG, result)
.tags(counted.extraTags())
.register(meterRegistry)
.register(registry)
.increment();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public TimedAspect() {
}

/**
* Creates a {@code TimedAspect} instance with the given {@code meterRegistry}.
* Creates a {@code TimedAspect} instance with the given {@code registry}.
*
* @param registry Where we're going to register metrics.
*/
Expand All @@ -111,7 +111,7 @@ public TimedAspect(MeterRegistry registry) {
}

/**
* Creates a {@code TimedAspect} instance with the given {@code meterRegistry} and tags provider function.
* Creates a {@code TimedAspect} instance with the given {@code registry} and tags provider function.
*
* @param registry Where we're going to register metrics.
* @param tagsBasedOnJoinPoint A function to generate tags given a join point.
Expand All @@ -121,10 +121,11 @@ public TimedAspect(MeterRegistry registry, Function<ProceedingJoinPoint, Iterabl
}

/**
* Creates a {@code TimedAspect} instance with the given {@code meterRegistry} and skip predicate.
* Creates a {@code TimedAspect} 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.
* @since 1.7.0
*/
public TimedAspect(MeterRegistry registry, Predicate<ProceedingJoinPoint> shouldSkip) {
this(
Expand All @@ -136,11 +137,12 @@ public TimedAspect(MeterRegistry registry, Predicate<ProceedingJoinPoint> should
}

/**
* Creates a {@code TimedAspect} instance with the given {@code meterRegistry}, tags provider function and skip predicate.
* Creates a {@code TimedAspect} instance with the given {@code registry}, tags 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.
* @since 1.7.0
*/
public TimedAspect(MeterRegistry registry, Function<ProceedingJoinPoint, Iterable<Tag>> tagsBasedOnJoinPoint, Predicate<ProceedingJoinPoint> shouldSkip) {
this.registry = registry;
Expand Down

0 comments on commit 1b01022

Please sign in to comment.