Skip to content

Commit

Permalink
fix reactor#1911 Instrument ScheduledExecutorService via Micrometer
Browse files Browse the repository at this point in the history
Since Micrometer 1.3.0, `ScheduledExecutorService` are instrumented by
Micrometer, which returns the decorated instance with the correct type.

The `TimedScheduledExecutorService` adhoc class has consequently been
removed.

Micrometer 1.2 is no longer supported, but `latest.release` might cause
issues with upcoming breaking changes.
Since the dependency appears in the BOM as optional, we instead make it
an explicit statement about the minimal version Reactor needs.
  • Loading branch information
thiyagu-7 authored and simonbasle committed Oct 23, 2019
1 parent 9e03cfb commit cac0f8c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 47 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ ext {
}

// Metrics
micrometerVersion = 'latest.release' //TODO specify a version of micrometer?
micrometerVersion = '1.3.0' //optional, should be compatible with any 1.3.x, but 1.3.0 is now a baseline

// Logging
slf4jVersion = '1.7.12'
Expand Down Expand Up @@ -261,4 +261,4 @@ if (project.hasProperty('platformVersion')) {
}
}

assemble.dependsOn docsZip
assemble.dependsOn docsZip
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,12 @@
import java.util.HashMap;
import java.util.Map;
import java.util.WeakHashMap;
import java.util.concurrent.Callable;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.BiFunction;

import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Tag;
import io.micrometer.core.instrument.Tags;
import io.micrometer.core.instrument.binder.jvm.ExecutorServiceMetrics;
import io.micrometer.core.instrument.internal.TimedExecutorService;
import io.micrometer.core.instrument.search.Search;

import reactor.core.Disposable;
Expand Down Expand Up @@ -84,14 +78,7 @@ in order to avoid consider two calls in a row as duplicates (yet still being abl
to distinguish between two instances with the same name and configuration).
*/

//the result of `monitor` below is ignored on purpose (the equivalent wrapping is done right after).
//calling this method is still useful, as it binds some gauges from the executor to the registry...
ExecutorServiceMetrics.monitor(globalRegistry, service, executorId, tags);

// TODO return the result of ExecutorServiceMetrics#monitor
// once ScheduledExecutorService gets supported by Micrometer
// See https://github.com/micrometer-metrics/micrometer/issues/1021
return new TimedScheduledExecutorService(globalRegistry, service, executorId, tags);
return ExecutorServiceMetrics.monitor(globalRegistry, service, executorId, tags);
}

@Override
Expand All @@ -107,35 +94,4 @@ public void dispose() {
this.schedulerDifferentiator.clear();
this.executorDifferentiator.clear();
}

static final class TimedScheduledExecutorService extends TimedExecutorService implements ScheduledExecutorService {

final ScheduledExecutorService delegate;

public TimedScheduledExecutorService(MeterRegistry registry, ScheduledExecutorService delegate, String executorServiceName, Iterable<Tag> tags) {
super(registry, delegate, executorServiceName, tags);

this.delegate = delegate;
}

@Override
public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit) {
return delegate.schedule(command, delay, unit);
}

@Override
public <V> ScheduledFuture<V> schedule(Callable<V> callable, long delay, TimeUnit unit) {
return delegate.schedule(callable, delay, unit);
}

@Override
public ScheduledFuture<?> scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit) {
return delegate.scheduleAtFixedRate(command, initialDelay, period, unit);
}

@Override
public ScheduledFuture<?> scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit) {
return delegate.scheduleWithFixedDelay(command, initialDelay, delay, unit);
}
}
}

0 comments on commit cac0f8c

Please sign in to comment.