Skip to content

Commit

Permalink
Fix a couple reactor-core-micrometer module compilation errors (#3132)
Browse files Browse the repository at this point in the history
The Micrometer#useRegistry has been removed but the scheduler hook
was still referencing it instead of the (deprecated) one in core.

This fixes the situation by using core's Metrics.MicrometerConfiguration
getRegistry.

Additionally, some tests compare to KeyValue#toString, which has
recently been polished to have `keyValue` prefix rather than `tag`.
  • Loading branch information
simonbasle committed Jul 28, 2022
1 parent 687fdf8 commit 2bedc5f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
Expand Up @@ -100,15 +100,16 @@ public final class Micrometer {
* Set-up a decorator that will instrument any {@link ExecutorService} that backs a reactor-core {@link Scheduler}
* (or scheduler implementations which use {@link Schedulers#decorateExecutorService(Scheduler, ScheduledExecutorService)}).
* <p>
* The {@link MeterRegistry} to use can be configured via {@link #useRegistry(MeterRegistry)}
* The {@link MeterRegistry} to use can be configured via {@link reactor.util.Metrics.MicrometerConfiguration#useRegistry(MeterRegistry)}
* prior to using this method, the default being {@link io.micrometer.core.instrument.Metrics#globalRegistry}.
*
* @implNote Note that this is added as a decorator via Schedulers when enabling metrics for schedulers,
* which doesn't change the Factory.
*/
@Deprecated
public static void enableSchedulersMetricsDecorator() {
Schedulers.addExecutorServiceDecorator(SCHEDULERS_DECORATOR_KEY,
new MicrometerSchedulerMetricsDecorator(getRegistry()));
new MicrometerSchedulerMetricsDecorator(reactor.util.Metrics.MicrometerConfiguration.getRegistry()));
}

/**
Expand Down
Expand Up @@ -125,7 +125,7 @@ void resolveKeyValues_notSet() {
KeyValues resolvedKeyValues = MicrometerObservationListenerConfiguration.resolveKeyValues(flux, defaultKeyValues);

assertThat(resolvedKeyValues.stream().map(Object::toString))
.containsExactly("tag(common1=commonValue1)");
.containsExactly("keyValue(common1=commonValue1)");
}

@Test
Expand All @@ -138,8 +138,8 @@ void resolveKeyValues_setRightAbove() {
KeyValues resolvedKeyValues = MicrometerObservationListenerConfiguration.resolveKeyValues(flux, defaultKeyValues);

assertThat(resolvedKeyValues.stream().map(Object::toString)).containsExactlyInAnyOrder(
"tag(common1=commonValue1)",
"tag(k1=v1)"
"keyValue(common1=commonValue1)",
"keyValue(k1=v1)"
);
}

Expand All @@ -155,8 +155,8 @@ void resolveKeyValues_setHigherAbove() {
KeyValues resolvedKeyValues = MicrometerObservationListenerConfiguration.resolveKeyValues(flux, defaultKeyValues);

assertThat(resolvedKeyValues.stream().map(Object::toString)).containsExactlyInAnyOrder(
"tag(common1=commonValue1)",
"tag(k1=v1)"
"keyValue(common1=commonValue1)",
"keyValue(k1=v1)"
);
}

Expand All @@ -172,9 +172,9 @@ void resolveKeyValues_multipleScatteredKeyValuesSetAbove() {
KeyValues resolvedKeyValues = MicrometerObservationListenerConfiguration.resolveKeyValues(flux, defaultKeyValues);

assertThat(resolvedKeyValues.stream().map(Object::toString)).containsExactlyInAnyOrder(
"tag(common1=commonValue1)",
"tag(k1=v1)",
"tag(k2=v2)"
"keyValue(common1=commonValue1)",
"keyValue(k1=v1)",
"keyValue(k2=v2)"
);
}

Expand All @@ -191,9 +191,9 @@ void resolveKeyValues_multipleScatteredKeyValuesSetAboveWithDeduplication() {
KeyValues resolvedKeyValues = MicrometerObservationListenerConfiguration.resolveKeyValues(flux, defaultKeyValues);

assertThat(resolvedKeyValues.stream().map(Object::toString)).containsExactly(
"tag(common1=commonValue1)",
"tag(k1=v1)",
"tag(k2=v2)"
"keyValue(common1=commonValue1)",
"keyValue(k1=v1)",
"keyValue(k2=v2)"
);
}

Expand All @@ -204,6 +204,6 @@ void resolveKeyValues_notScannable() {

KeyValues resolvedKeyValues = MicrometerObservationListenerConfiguration.resolveKeyValues(publisher, defaultKeyValues);

assertThat(resolvedKeyValues.stream().map(Object::toString)).containsExactly("tag(common1=commonValue1)");
assertThat(resolvedKeyValues.stream().map(Object::toString)).containsExactly("keyValue(common1=commonValue1)");
}
}
Expand Up @@ -46,7 +46,7 @@ void configurationFromMono() {

assertThat(configuration.registry).as("registry").isSameAs(CUSTOM_REGISTRY);
assertThat(configuration.isMono).as("isMono").isTrue();
assertThat(configuration.commonKeyValues).map(Object::toString).containsExactly("tag(" + "reactor.type" + "=Mono)");
assertThat(configuration.commonKeyValues).map(Object::toString).containsExactly("keyValue(" + "reactor.type" + "=Mono)");
}

@Test
Expand All @@ -55,7 +55,7 @@ void configurationFromFlux() {

assertThat(configuration.registry).as("registry").isSameAs(CUSTOM_REGISTRY);
assertThat(configuration.isMono).as("isMono").isFalse();
assertThat(configuration.commonKeyValues).map(Object::toString).containsExactly("tag(" + "reactor.type" + "=Flux)");
assertThat(configuration.commonKeyValues).map(Object::toString).containsExactly("keyValue(" + "reactor.type" + "=Flux)");
}

@Test
Expand Down

0 comments on commit 2bedc5f

Please sign in to comment.