Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TimedScheduler to reactor-core-micrometer module #3109

Merged
merged 21 commits into from
Aug 4, 2022
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
b8ccf73
Add TimedScheduler to reactor-core-micrometer module
simonbasle Jul 7, 2022
c1ad1e9
make TimedScheduler package-private
simonbasle Jul 25, 2022
28bf7eb
remove TimedScheduler schedulerName, only use meterPrefix
simonbasle Jul 25, 2022
1694fc8
add Micrometer#timedScheduler javadoc
simonbasle Jul 25, 2022
2c7341c
[BREAKING] Remove enable/disableSchedulerMetricsDecorator
simonbasle Jul 25, 2022
9eafbc1
update the deprecation notice in Schedulers
simonbasle Jul 25, 2022
472c74f
merge main to get latest changes like observation()
simonbasle Jul 25, 2022
d5b0ed9
polish meters, add tests
simonbasle Jul 26, 2022
5220d2f
Refactor TimedScheduler to use LongTaskTimers and Counters
simonbasle Jul 27, 2022
97795a1
WIP add counter for periodical re-runs
simonbasle Jul 27, 2022
e45955e
Merge latest changes from 'main' (removing Clock/common registry)
simonbasle Jul 28, 2022
ab23d35
Merge 'main': fixing compilation issues
simonbasle Jul 28, 2022
73a76ce
fix tests
simonbasle Jul 28, 2022
1ed20ee
rework 4 counters: same name, tag differentiator
simonbasle Aug 3, 2022
8e28a86
fix Micrometer test now that we've added a tag
simonbasle Aug 4, 2022
dc35b4d
fix review comments, notably 'periodic' wording
simonbasle Aug 4, 2022
8859f80
move tests from confusing case TimedSchedulerTest to SingleSchedulerT…
simonbasle Aug 4, 2022
447cd7e
fix review comments in tests, except slow tests
simonbasle Aug 4, 2022
34b3873
use MockClock to assert precise timings of active vs pending durations
simonbasle Aug 4, 2022
505e58c
review: use mock instead of spy
simonbasle Aug 4, 2022
a42b8f3
polish: close registry afterEach test, fix 1 license header
simonbasle Aug 4, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions reactor-core-micrometer/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ dependencies {
testRuntimeOnly libs.logback
testImplementation libs.assertj
testImplementation libs.mockito
testImplementation libs.awaitility
}

tasks.withType(Test).all {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,22 @@

package reactor.core.observability.micrometer;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.ScheduledExecutorService;

import io.micrometer.common.KeyValue;
import io.micrometer.common.KeyValues;
import io.micrometer.core.instrument.Clock;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Metrics;
import io.micrometer.core.instrument.Tag;
import io.micrometer.core.instrument.Tags;
import io.micrometer.observation.Observation;
import io.micrometer.observation.ObservationRegistry;

import reactor.core.observability.SignalListener;
import reactor.core.observability.SignalListenerFactory;
import reactor.core.scheduler.Scheduler;
import reactor.core.scheduler.Schedulers;

public final class Micrometer {

private static final String SCHEDULERS_DECORATOR_KEY = "reactor.core.observability.micrometer.schedulerDecorator";

/**
* The default "name" to use as a prefix for meter if the instrumented sequence doesn't define a {@link reactor.core.publisher.Flux#name(String) name}.
*/
Expand Down Expand Up @@ -94,29 +90,33 @@ public final class Micrometer {
return new MicrometerObservationListenerFactory<>(registry);
}

//FIXME: remove these and replace with an option to decorate an arbitrary Scheduler

/**
* 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 reactor.util.Metrics.MicrometerConfiguration#useRegistry(MeterRegistry)}
* prior to using this method, the default being {@link io.micrometer.core.instrument.Metrics#globalRegistry}.
* Wrap a {@link Scheduler} in an instance that gather various task-related metrics using
chemicL marked this conversation as resolved.
Show resolved Hide resolved
* the provided {@link MeterRegistry} and naming meters using the provided {@code metricsPrefix}.
* Note that no tags are set up for these meters.
*
* @implNote Note that this is added as a decorator via Schedulers when enabling metrics for schedulers,
* which doesn't change the Factory.
* @param original the original {@link Scheduler} to decorate with metrics
* @param meterRegistry the {@link MeterRegistry} in which to register the various meters
* @param metricsPrefix the prefix to use in meter names. if needed, a dot is added at the end
chemicL marked this conversation as resolved.
Show resolved Hide resolved
* @return a {@link Scheduler} that is instrumented with dedicated metrics
*/
@Deprecated
public static void enableSchedulersMetricsDecorator() {
Schedulers.addExecutorServiceDecorator(SCHEDULERS_DECORATOR_KEY,
new MicrometerSchedulerMetricsDecorator(reactor.util.Metrics.MicrometerConfiguration.getRegistry()));
public static Scheduler timedScheduler(Scheduler original, MeterRegistry meterRegistry, String metricsPrefix) {
return new TimedScheduler(original, meterRegistry, metricsPrefix, Tags.empty());
}

/**
* If {@link #enableSchedulersMetricsDecorator()} has been previously called, removes the decorator.
* No-op if {@link #enableSchedulersMetricsDecorator()} hasn't been called.
* Wrap a {@link Scheduler} in an instance that gather various task-related metrics using
chemicL marked this conversation as resolved.
Show resolved Hide resolved
* the provided {@link MeterRegistry} and naming meters using the provided {@code metricsPrefix}.
* User-provided collection of {@link Tag} (ie. {@link Tags}) can also be provided to be added to
* all the meters of that timed Scheduler..
chemicL marked this conversation as resolved.
Show resolved Hide resolved
*
* @param original the original {@link Scheduler} to decorate with metrics
* @param meterRegistry the {@link MeterRegistry} in which to register the various meters
* @param metricsPrefix the prefix to use in meter names. if needed, a dot is added at the end
chemicL marked this conversation as resolved.
Show resolved Hide resolved
* @param tags the tags to put on meters
* @return a {@link Scheduler} that is instrumented with dedicated metrics
*/
public static void disableSchedulersMetricsDecorator() {
Schedulers.removeExecutorServiceDecorator(SCHEDULERS_DECORATOR_KEY);
public static Scheduler timedScheduler(Scheduler original, MeterRegistry meterRegistry, String metricsPrefix, Iterable<Tag> tags) {
return new TimedScheduler(original, meterRegistry, metricsPrefix, tags);
}
}

This file was deleted.