Skip to content

Commit

Permalink
Merge branch '1.14.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
shakuzen committed Dec 16, 2024
2 parents 3c53a7c + 6ed8fd9 commit 56995b2
Show file tree
Hide file tree
Showing 18 changed files with 241 additions and 63 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,8 @@ bin/
.vscode
.DS_Store
.java-version

# jcstress
generated/
results/
jcstress-results-*.bin.gz
7 changes: 5 additions & 2 deletions concurrency-tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ plugins {
}

dependencies {
// Comment out the local project references and reference an old version to compare jcstress results across versions
// Make sure to use a consistent version for all micrometer dependencies
implementation project(":micrometer-core")
// implementation("io.micrometer:micrometer-core:1.12.4")
// implementation("io.micrometer:micrometer-core:1.14.1")
implementation project(":micrometer-registry-prometheus")
// implementation("io.micrometer:micrometer-registry-prometheus:1.14.1")
runtimeOnly(libs.logbackLatest)
}

jcstress {
libs.jcstressCore
jcstressDependency libs.jcstressCore.get().toString()

// This affects how long and thorough testing will be
// In order of increasing stress: sanity, quick, default, tough, stress
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,31 +35,68 @@ public class ObservationContextConcurrencyTest {
@State
@Outcome(id = "No exception, No exception", expect = ACCEPTABLE)
@Outcome(expect = FORBIDDEN)
public static class ConsistentKeyValues {
public static class ConsistentKeyValuesGetAdd {

private final Observation.Context context = new TestContext();

private final String uuid = UUID.randomUUID().toString();

@Actor
public void read(LL_Result r) {
public void get(LL_Result r) {
try {
context.getHighCardinalityKeyValues();
r.r1 = "No exception";
}
catch (Exception e) {
r.r1 = e.getClass();
r.r1 = e.getClass().getSimpleName();
}
}

@Actor
public void write(LL_Result r) {
public void add(LL_Result r) {
try {
context.addHighCardinalityKeyValue(KeyValue.of(uuid, uuid));
context.addHighCardinalityKeyValue(KeyValue.of("uuid", uuid));
r.r2 = "No exception";
}
catch (Exception e) {
r.r2 = e.getClass();
r.r2 = e.getClass().getSimpleName();
}
}

}

@JCStressTest
@State
@Outcome(id = "No exception, No exception", expect = ACCEPTABLE)
@Outcome(expect = FORBIDDEN)
public static class ConsistentKeyValuesGetRemove {

private final Observation.Context context = new TestContext();

public ConsistentKeyValuesGetRemove() {
context.addLowCardinalityKeyValue(KeyValue.of("keep", "donotremoveme"));
context.addLowCardinalityKeyValue(KeyValue.of("remove", "removeme"));
}

@Actor
public void get(LL_Result r) {
try {
context.getAllKeyValues();
r.r1 = "No exception";
}
catch (Exception e) {
r.r1 = e.getClass().getSimpleName();
}
}

@Actor
public void remove(LL_Result r) {
try {
context.removeLowCardinalityKeyValue("remove");
r.r2 = "No exception";
}
catch (Exception e) {
r.r2 = e.getClass().getSimpleName();
}
}

Expand Down
2 changes: 0 additions & 2 deletions docs/modules/ROOT/pages/concepts/counters.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ Counter counter = Counter

The `micrometer-core` module contains a `@Counted` annotation that frameworks can use to add counting support to either specific types of methods such as those serving web request endpoints or, more generally, to all methods.

WARNING: Micrometer's Spring Boot configuration does _not_ recognize `@Counted` on arbitrary methods.

Also, an incubating AspectJ aspect is included in `micrometer-core`. You can use it in your application either through compile/load time AspectJ weaving or through framework facilities that interpret AspectJ aspects and proxy targeted methods in some other way, such as Spring AOP. Here is a sample Spring AOP configuration:

[source,java]
Expand Down
2 changes: 0 additions & 2 deletions docs/modules/ROOT/pages/concepts/timers.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ Note how we do not decide the timer to which to accumulate the sample until it i

The `micrometer-core` module contains a `@Timed` annotation that frameworks can use to add timing support to either specific types of methods such as those serving web request endpoints or, more generally, to all methods.

WARNING: Micrometer's Spring Boot configuration does _not_ recognize `@Timed` on arbitrary methods.

Also, an incubating AspectJ aspect is included in `micrometer-core`. You can use it in your application either through compile/load time AspectJ weaving or through framework facilities that interpret AspectJ aspects and proxy targeted methods in some other way, such as Spring AOP. Here is a sample Spring AOP configuration:

[source,java]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class TimedAspectTest {
// end::resolvers[]

@ParameterizedTest
@EnumSource(AnnotatedTestClass.class)
@EnumSource
void meterTagsWithText(AnnotatedTestClass annotatedClass) {
MeterRegistry registry = new SimpleMeterRegistry();
TimedAspect timedAspect = new TimedAspect(registry);
Expand All @@ -63,7 +63,7 @@ void meterTagsWithText(AnnotatedTestClass annotatedClass) {
}

@ParameterizedTest
@EnumSource(AnnotatedTestClass.class)
@EnumSource
void meterTagsWithResolver(AnnotatedTestClass annotatedClass) {
MeterRegistry registry = new SimpleMeterRegistry();
TimedAspect timedAspect = new TimedAspect(registry);
Expand All @@ -88,7 +88,7 @@ void meterTagsWithResolver(AnnotatedTestClass annotatedClass) {
}

@ParameterizedTest
@EnumSource(AnnotatedTestClass.class)
@EnumSource
void meterTagsWithExpression(AnnotatedTestClass annotatedClass) {
MeterRegistry registry = new SimpleMeterRegistry();
TimedAspect timedAspect = new TimedAspect(registry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void cleanUp() {
}

@ParameterizedTest
@EnumSource(StatsdProtocol.class)
@EnumSource
void receiveAllBufferedMetricsAfterCloseSuccessfully(StatsdProtocol protocol) throws InterruptedException {
skipUdsTestOnWindows(protocol);
serverLatch = new CountDownLatch(3);
Expand All @@ -98,7 +98,7 @@ void receiveAllBufferedMetricsAfterCloseSuccessfully(StatsdProtocol protocol) th
}

@ParameterizedTest
@EnumSource(StatsdProtocol.class)
@EnumSource
void receiveMetricsSuccessfully(StatsdProtocol protocol) throws InterruptedException {
skipUdsTestOnWindows(protocol);
serverLatch = new CountDownLatch(3);
Expand All @@ -116,7 +116,7 @@ void receiveMetricsSuccessfully(StatsdProtocol protocol) throws InterruptedExcep
}

@ParameterizedTest
@EnumSource(StatsdProtocol.class)
@EnumSource
void resumeSendingMetrics_whenServerIntermittentlyFails(StatsdProtocol protocol) throws InterruptedException {
skipUdsTestOnWindows(protocol);
serverLatch = new CountDownLatch(1);
Expand Down Expand Up @@ -163,7 +163,7 @@ void resumeSendingMetrics_whenServerIntermittentlyFails(StatsdProtocol protocol)
}

@ParameterizedTest
@EnumSource(StatsdProtocol.class)
@EnumSource
@Issue("#1676")
void stopAndStartMeterRegistrySendsMetrics(StatsdProtocol protocol) throws InterruptedException {
skipUdsTestOnWindows(protocol);
Expand Down Expand Up @@ -206,7 +206,7 @@ void stopAndStartMeterRegistryWithLineSink() throws InterruptedException {
}

@ParameterizedTest
@EnumSource(StatsdProtocol.class)
@EnumSource
void whenBackendInitiallyDown_metricsSentAfterBackendStarts(StatsdProtocol protocol) throws InterruptedException {
skipUdsTestOnWindows(protocol);
AtomicInteger writeCount = new AtomicInteger();
Expand Down Expand Up @@ -245,7 +245,7 @@ void whenBackendInitiallyDown_metricsSentAfterBackendStarts(StatsdProtocol proto
}

@ParameterizedTest
@EnumSource(StatsdProtocol.class)
@EnumSource
void whenRegistryStopped_doNotConnectToBackend(StatsdProtocol protocol) throws InterruptedException {
skipUdsTestOnWindows(protocol);
serverLatch = new CountDownLatch(3);
Expand All @@ -264,7 +264,7 @@ void whenRegistryStopped_doNotConnectToBackend(StatsdProtocol protocol) throws I
}

@ParameterizedTest
@EnumSource(StatsdProtocol.class)
@EnumSource
@Issue("#2177")
void whenSendError_reconnectsAndWritesNewMetrics(StatsdProtocol protocol) throws InterruptedException {
skipUdsTestOnWindows(protocol);
Expand Down Expand Up @@ -296,7 +296,7 @@ public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise)

@Issue("#2880")
@ParameterizedTest
@EnumSource(StatsdProtocol.class)
@EnumSource
void receiveParallelMetricsSuccessfully(StatsdProtocol protocol) throws InterruptedException {
final int n = 10;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public StatsdFlavor flavor() {
}

@ParameterizedTest
@EnumSource(StatsdFlavor.class)
@EnumSource
void counterLineProtocol(StatsdFlavor flavor) {
String line = null;
switch (flavor) {
Expand Down Expand Up @@ -113,7 +113,7 @@ void counterLineProtocol(StatsdFlavor flavor) {
}

@ParameterizedTest
@EnumSource(StatsdFlavor.class)
@EnumSource
void gaugeLineProtocol(StatsdFlavor flavor) {
final AtomicInteger n = new AtomicInteger(2);
final StatsdConfig config = configWithFlavor(flavor);
Expand Down Expand Up @@ -146,7 +146,7 @@ void gaugeLineProtocol(StatsdFlavor flavor) {
}

@ParameterizedTest
@EnumSource(StatsdFlavor.class)
@EnumSource
void timerLineProtocol(StatsdFlavor flavor) {
String line = null;
switch (flavor) {
Expand Down Expand Up @@ -179,7 +179,7 @@ void timerLineProtocol(StatsdFlavor flavor) {
}

@ParameterizedTest
@EnumSource(StatsdFlavor.class)
@EnumSource
void summaryLineProtocol(StatsdFlavor flavor) {
String line = null;
switch (flavor) {
Expand Down Expand Up @@ -212,7 +212,7 @@ void summaryLineProtocol(StatsdFlavor flavor) {
}

@ParameterizedTest
@EnumSource(StatsdFlavor.class)
@EnumSource
void longTaskTimerLineProtocol(StatsdFlavor flavor) {
final StatsdConfig config = configWithFlavor(flavor);
long stepMillis = config.step().toMillis();
Expand Down Expand Up @@ -287,7 +287,7 @@ void counterIncrementDoesNotCauseStackOverflow() {
}

@ParameterizedTest
@EnumSource(StatsdFlavor.class)
@EnumSource
@Issue("#370")
void serviceLevelObjectivesOnlyNoPercentileHistogram(StatsdFlavor flavor) {
StatsdConfig config = configWithFlavor(flavor);
Expand Down Expand Up @@ -391,7 +391,7 @@ void interactWithStoppedRegistry() {
}

@ParameterizedTest
@EnumSource(StatsdFlavor.class)
@EnumSource
@Issue("#600")
void memoryPerformanceOfNamingConventionInHotLoops(StatsdFlavor flavor) {
AtomicInteger namingConventionUses = new AtomicInteger();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
* @author Jonatan Ivanov
* @author Johnny Lim
* @author Yanming Zhou
* @author Jeonggi Kim
* @since 1.2.0
* @see Counted
*/
Expand Down Expand Up @@ -237,8 +238,17 @@ private Object perform(ProceedingJoinPoint pjp, Counted counted) throws Throwabl

if (stopWhenCompleted) {
try {
return ((CompletionStage<?>) pjp.proceed())
.whenComplete((result, throwable) -> recordCompletionResult(pjp, counted, throwable));
Object result = pjp.proceed();
if (result == null) {
if (!counted.recordFailuresOnly()) {
record(pjp, counted, DEFAULT_EXCEPTION_TAG_VALUE, RESULT_TAG_SUCCESS_VALUE);
}
return result;
}
else {
CompletionStage<?> stage = ((CompletionStage<?>) result);
return stage.whenComplete((res, throwable) -> recordCompletionResult(pjp, counted, throwable));
}
}
catch (Throwable e) {
record(pjp, counted, e.getClass().getSimpleName(), RESULT_TAG_FAILURE_VALUE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
* @author Nejc Korasa
* @author Jonatan Ivanov
* @author Yanming Zhou
* @author Jeonggi Kim
* @since 1.0.0
*/
@Aspect
Expand Down Expand Up @@ -235,8 +236,16 @@ private Object processWithTimer(ProceedingJoinPoint pjp, Timed timed, String met

if (stopWhenCompleted) {
try {
return ((CompletionStage<?>) pjp.proceed()).whenComplete(
(result, throwable) -> record(pjp, timed, metricName, sample, getExceptionTag(throwable)));
Object result = pjp.proceed();
if (result == null) {
record(pjp, timed, metricName, sample, DEFAULT_EXCEPTION_TAG_VALUE);
return result;
}
else {
CompletionStage<?> stage = ((CompletionStage<?>) result);
return stage.whenComplete(
(res, throwable) -> record(pjp, timed, metricName, sample, getExceptionTag(throwable)));
}
}
catch (Throwable e) {
record(pjp, timed, metricName, sample, e.getClass().getSimpleName());
Expand Down Expand Up @@ -307,8 +316,15 @@ private Object processWithLongTaskTimer(ProceedingJoinPoint pjp, Timed timed, St

if (stopWhenCompleted) {
try {
return ((CompletionStage<?>) pjp.proceed())
.whenComplete((result, throwable) -> sample.ifPresent(this::stopTimer));
Object result = pjp.proceed();
if (result == null) {
sample.ifPresent(this::stopTimer);
return result;
}
else {
CompletionStage<?> stage = ((CompletionStage<?>) result);
return stage.whenComplete((res, throwable) -> sample.ifPresent(this::stopTimer));
}
}
catch (Throwable e) {
sample.ifPresent(this::stopTimer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ void loadFailure() {
}

@ParameterizedTest
@EnumSource(RemovalCause.class)
@EnumSource
void evictionWithCause(RemovalCause cause) {
stats.recordEviction(3, cause);
DistributionSummary summary = fetch("cache.evictions", "cause", cause.name()).summary();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
*
* @author Jonatan Ivanov
* @author Yanming Zhou
* @author Jeonggi Kim
* @since 1.10.0
*/
@Aspect
Expand Down Expand Up @@ -148,8 +149,15 @@ private Object observe(ProceedingJoinPoint pjp, Method method, Observed observed
observation.start();
Observation.Scope scope = observation.openScope();
try {
return ((CompletionStage<?>) pjp.proceed())
.whenComplete((result, error) -> stopObservation(observation, scope, error));
Object result = pjp.proceed();
if (result == null) {
stopObservation(observation, scope, null);
return result;
}
else {
CompletionStage<?> stage = (CompletionStage<?>) result;
return stage.whenComplete((res, error) -> stopObservation(observation, scope, error));
}
}
catch (Throwable error) {
stopObservation(observation, scope, error);
Expand Down
Loading

0 comments on commit 56995b2

Please sign in to comment.