Skip to content

Commit

Permalink
Merge branch '1.8.x' into 1.9.x
Browse files Browse the repository at this point in the history
  • Loading branch information
shakuzen committed Jun 10, 2022
2 parents dc22cca + 5dd6ef6 commit efbd6cf
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -279,18 +279,18 @@ public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise)
@ParameterizedTest
@EnumSource(StatsdProtocol.class)
void receiveParallelMetricsSuccessfully(StatsdProtocol protocol) throws InterruptedException {
final int N = 10;
final int n = 10;

skipUdsTestOnWindows(protocol);
serverLatch = new CountDownLatch(N);
serverLatch = new CountDownLatch(n);
server = startServer(protocol, 0);
final int port = getPort(protocol);

meterRegistry = new StatsdMeterRegistry(getUnbufferedConfig(protocol, port), Clock.SYSTEM);
startRegistryAndWaitForClient();
Counter counter = Counter.builder("my.counter").register(meterRegistry);

IntStream.range(0, N).parallel().forEach(ignored -> counter.increment());
IntStream.range(0, n).parallel().forEach(ignored -> counter.increment());

assertThat(serverLatch.await(3, TimeUnit.SECONDS)).isTrue();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ class CompositeTimer extends AbstractCompositeMeter<Timer> implements Timer {

@Override
public void record(long amount, TimeUnit unit) {
for (Timer ds : getChildren()) {
ds.record(amount, unit);
for (Timer timer : getChildren()) {
timer.record(amount, unit);
}
}

@Override
public void record(Duration duration) {
for (Timer ds : getChildren()) {
ds.record(duration);
for (Timer timer : getChildren()) {
timer.record(duration);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class TimeWindowMax {

private final long durationBetweenRotatesMillis;

private AtomicLong[] ringBuffer;
private final AtomicLong[] ringBuffer;

private int currentBucket;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class TimeWindowSum {

private final long durationBetweenRotatesMillis;

private AtomicLong[] ringBuffer;
private final AtomicLong[] ringBuffer;

private int currentBucket;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ private void publishSafely() {
publish();
}
catch (Throwable e) {
logger.warn("Unexpected exception thrown while publishing metrics for " + this.getClass().getSimpleName(),
e);
logger.warn("Unexpected exception thrown while publishing metrics for " + getClass().getSimpleName(), e);
}
}

Expand All @@ -72,7 +71,7 @@ public void start(ThreadFactory threadFactory) {
stop();

if (config.enabled()) {
logger.info("publishing metrics for " + this.getClass().getSimpleName() + " every "
logger.info("publishing metrics for " + getClass().getSimpleName() + " every "
+ TimeUtils.format(config.step()));

scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(threadFactory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ void countedWithSuccessfulMetrics() {
countedService.succeedWithMetrics();

Counter counter = meterRegistry.get("metric.success").tag("method", "succeedWithMetrics")
.tag("class", this.getClass().getName() + "$CountedService").tag("extra", "tag")
.tag("result", "success").counter();
.tag("class", getClass().getName() + "$CountedService").tag("extra", "tag").tag("result", "success")
.counter();

assertThat(counter.count()).isOne();
assertThat(counter.getId().getDescription()).isNull();
Expand All @@ -82,7 +82,7 @@ void countedWithFailure() {
}

Counter counter = meterRegistry.get("metric.failing").tag("method", "fail")
.tag("class", this.getClass().getName() + "$CountedService").tag("exception", "RuntimeException")
.tag("class", getClass().getName() + "$CountedService").tag("exception", "RuntimeException")
.tag("result", "failure").counter();

assertThat(counter.count()).isOne();
Expand Down Expand Up @@ -119,14 +119,14 @@ void countedWithSuccessfulMetricsWhenCompleted() {
CompletableFuture<?> completableFuture = asyncCountedService.succeedWithMetrics(guardedResult);

assertThat(meterRegistry.find("metric.success").tag("method", "succeedWithMetrics")
.tag("class", this.getClass().getName() + "$AsyncCountedService").tag("extra", "tag")
.tag("class", getClass().getName() + "$AsyncCountedService").tag("extra", "tag")
.tag("exception", "none").tag("result", "success").counter()).isNull();

guardedResult.complete();
completableFuture.join();

Counter counterAfterCompletion = meterRegistry.get("metric.success").tag("method", "succeedWithMetrics")
.tag("class", this.getClass().getName() + "$AsyncCountedService").tag("extra", "tag")
.tag("class", getClass().getName() + "$AsyncCountedService").tag("extra", "tag")
.tag("exception", "none").tag("result", "success").counter();

assertThat(counterAfterCompletion.count()).isOne();
Expand All @@ -139,14 +139,14 @@ void countedWithFailureWhenCompleted() {
CompletableFuture<?> completableFuture = asyncCountedService.fail(guardedResult);

assertThat(meterRegistry.find("metric.failing").tag("method", "fail")
.tag("class", this.getClass().getName() + "$AsyncCountedService").tag("exception", "RuntimeException")
.tag("class", getClass().getName() + "$AsyncCountedService").tag("exception", "RuntimeException")
.tag("result", "failure").counter()).isNull();

guardedResult.complete(new RuntimeException());
assertThatThrownBy(completableFuture::join).isInstanceOf(RuntimeException.class);

Counter counter = meterRegistry.get("metric.failing").tag("method", "fail")
.tag("class", this.getClass().getName() + "$AsyncCountedService").tag("exception", "RuntimeException")
.tag("class", getClass().getName() + "$AsyncCountedService").tag("exception", "RuntimeException")
.tag("result", "failure").counter();

assertThat(counter.count()).isOne();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void timeMethod() {

service.call();

assertThat(registry.get("call").tag("class", this.getClass().getName() + "$TimedService").tag("method", "call")
assertThat(registry.get("call").tag("class", getClass().getName() + "$TimedService").tag("method", "call")
.tag("extra", "tag").timer().count()).isEqualTo(1);
}

Expand Down Expand Up @@ -79,7 +79,7 @@ void timeMethodWithLongTaskTimer() {

service.longCall();

assertThat(registry.get("longCall").tag("class", this.getClass().getName() + "$TimedService")
assertThat(registry.get("longCall").tag("class", getClass().getName() + "$TimedService")
.tag("method", "longCall").tag("extra", "tag").longTaskTimers().size()).isEqualTo(1);
}

Expand All @@ -95,7 +95,7 @@ void timeMethodFailure() {
service.call();

assertThatExceptionOfType(MeterNotFoundException.class).isThrownBy(() -> {
failingRegistry.get("call").tag("class", this.getClass().getName() + "$TimedService").tag("method", "call")
failingRegistry.get("call").tag("class", getClass().getName() + "$TimedService").tag("method", "call")
.tag("extra", "tag").timer();
});
}
Expand All @@ -112,7 +112,7 @@ void timeMethodFailureWithLongTaskTimer() {
service.longCall();

assertThatExceptionOfType(MeterNotFoundException.class).isThrownBy(() -> {
failingRegistry.get("longCall").tag("class", this.getClass().getName() + "$TimedService")
failingRegistry.get("longCall").tag("class", getClass().getName() + "$TimedService")
.tag("method", "longCall").tag("extra", "tag").longTaskTimer();
});
}
Expand All @@ -129,14 +129,14 @@ void timeMethodWhenCompleted() {
GuardedResult guardedResult = new GuardedResult();
CompletableFuture<?> completableFuture = service.call(guardedResult);

assertThat(registry.find("call").tag("class", this.getClass().getName() + "$AsyncTimedService")
.tag("method", "call").tag("extra", "tag").tag("exception", "none").timer()).isNull();
assertThat(registry.find("call").tag("class", getClass().getName() + "$AsyncTimedService").tag("method", "call")
.tag("extra", "tag").tag("exception", "none").timer()).isNull();

guardedResult.complete();
completableFuture.join();

assertThat(registry.get("call").tag("class", this.getClass().getName() + "$AsyncTimedService")
.tag("method", "call").tag("extra", "tag").tag("exception", "none").timer().count()).isEqualTo(1);
assertThat(registry.get("call").tag("class", getClass().getName() + "$AsyncTimedService").tag("method", "call")
.tag("extra", "tag").tag("exception", "none").timer().count()).isEqualTo(1);
}

@Test
Expand All @@ -151,15 +151,14 @@ void timeMethodWhenCompletedExceptionally() {
GuardedResult guardedResult = new GuardedResult();
CompletableFuture<?> completableFuture = service.call(guardedResult);

assertThat(registry.find("call").tag("class", this.getClass().getName() + "$AsyncTimedService")
.tag("method", "call").tag("extra", "tag").tag("exception", "NullPointerException").timer()).isNull();
assertThat(registry.find("call").tag("class", getClass().getName() + "$AsyncTimedService").tag("method", "call")
.tag("extra", "tag").tag("exception", "NullPointerException").timer()).isNull();

guardedResult.complete(new NullPointerException());
catchThrowableOfType(completableFuture::join, CompletionException.class);

assertThat(registry.get("call").tag("class", this.getClass().getName() + "$AsyncTimedService")
.tag("method", "call").tag("extra", "tag").tag("exception", "NullPointerException").timer().count())
.isEqualTo(1);
assertThat(registry.get("call").tag("class", getClass().getName() + "$AsyncTimedService").tag("method", "call")
.tag("extra", "tag").tag("exception", "NullPointerException").timer().count()).isEqualTo(1);
}

@Test
Expand All @@ -174,13 +173,13 @@ void timeMethodWithLongTaskTimerWhenCompleted() {
GuardedResult guardedResult = new GuardedResult();
CompletableFuture<?> completableFuture = service.longCall(guardedResult);

assertThat(registry.find("longCall").tag("class", this.getClass().getName() + "$AsyncTimedService")
assertThat(registry.find("longCall").tag("class", getClass().getName() + "$AsyncTimedService")
.tag("method", "longCall").tag("extra", "tag").longTaskTimer().activeTasks()).isEqualTo(1);

guardedResult.complete();
completableFuture.join();

assertThat(registry.get("longCall").tag("class", this.getClass().getName() + "$AsyncTimedService")
assertThat(registry.get("longCall").tag("class", getClass().getName() + "$AsyncTimedService")
.tag("method", "longCall").tag("extra", "tag").longTaskTimer().activeTasks()).isEqualTo(0);
}

Expand All @@ -196,13 +195,13 @@ void timeMethodWithLongTaskTimerWhenCompletedExceptionally() {
GuardedResult guardedResult = new GuardedResult();
CompletableFuture<?> completableFuture = service.longCall(guardedResult);

assertThat(registry.find("longCall").tag("class", this.getClass().getName() + "$AsyncTimedService")
assertThat(registry.find("longCall").tag("class", getClass().getName() + "$AsyncTimedService")
.tag("method", "longCall").tag("extra", "tag").longTaskTimer().activeTasks()).isEqualTo(1);

guardedResult.complete(new NullPointerException());
catchThrowableOfType(completableFuture::join, CompletionException.class);

assertThat(registry.get("longCall").tag("class", this.getClass().getName() + "$AsyncTimedService")
assertThat(registry.get("longCall").tag("class", getClass().getName() + "$AsyncTimedService")
.tag("method", "longCall").tag("extra", "tag").longTaskTimer().activeTasks()).isEqualTo(0);
}

Expand All @@ -220,8 +219,8 @@ void timeMethodFailureWhenCompletedExceptionally() {
guardedResult.complete();
completableFuture.join();

assertThatExceptionOfType(MeterNotFoundException.class).isThrownBy(
() -> failingRegistry.get("call").tag("class", this.getClass().getName() + "$AsyncTimedService")
assertThatExceptionOfType(MeterNotFoundException.class)
.isThrownBy(() -> failingRegistry.get("call").tag("class", getClass().getName() + "$AsyncTimedService")
.tag("method", "call").tag("extra", "tag").tag("exception", "none").timer());
}

Expand All @@ -240,7 +239,7 @@ void timeMethodFailureWithLongTaskTimerWhenCompleted() {
completableFuture.join();

assertThatExceptionOfType(MeterNotFoundException.class).isThrownBy(() -> {
failingRegistry.get("longCall").tag("class", this.getClass().getName() + "$AsyncTimedService")
failingRegistry.get("longCall").tag("class", getClass().getName() + "$AsyncTimedService")
.tag("method", "longCall").tag("extra", "tag").longTaskTimer();
});
}
Expand Down

0 comments on commit efbd6cf

Please sign in to comment.