Skip to content

Commit

Permalink
New properties-based filter structure (fixes micrometer-metrics#366)
Browse files Browse the repository at this point in the history
* Polish on unused thrown exceptions, imports.
* Added eclipse APT plugin to test Spring property autocompletion in Eclipse
jkschneider committed Jan 25, 2018
1 parent 1341ad4 commit 71576d1
Showing 120 changed files with 1,500 additions and 1,218 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -13,3 +13,4 @@ out/
.settings/
.sts4-cache/
bin/
.factorypath
4 changes: 2 additions & 2 deletions micrometer-core/build.gradle
Original file line number Diff line number Diff line change
@@ -40,7 +40,7 @@ dependencies {
// reactor
compile 'io.projectreactor:reactor-core:3.1.2.RELEASE', optional

compile 'com.squareup.okhttp3:okhttp:3.9.0',optional
compile 'com.squareup.okhttp3:okhttp:3.9.0', optional

testCompile 'io.projectreactor:reactor-test:3.1.2.RELEASE'
testCompile 'io.projectreactor.ipc:reactor-netty:0.7.1.RELEASE'
@@ -53,7 +53,7 @@ dependencies {
// Eclipse still needs this (as of 4.7.1a)
testRuntime 'org.junit.platform:junit-platform-launcher:1.0.0'

testCompile "org.mockito:mockito-core:2.10.0"
testCompile "org.mockito:mockito-core:2.10.0"

testCompile 'org.hsqldb:hsqldb:2.3.5'

Original file line number Diff line number Diff line change
@@ -47,12 +47,12 @@ public class SimpleMeasureBenchmark {

public static void main(String[] args) throws RunnerException {
Options opt = new OptionsBuilder()
.include(SimpleMeasureBenchmark.class.getSimpleName())
.warmupIterations(20)
.measurementIterations(30)
.mode(Mode.Throughput)
.forks(1)
.build();
.include(SimpleMeasureBenchmark.class.getSimpleName())
.warmupIterations(20)
.measurementIterations(30)
.mode(Mode.Throughput)
.forks(1)
.build();

new Runner(opt).run();
}
Original file line number Diff line number Diff line change
@@ -27,8 +27,8 @@

public abstract class AbstractTimer extends AbstractMeter implements Timer {
protected final Clock clock;
private final HistogramConfig histogramConfig;
protected final TimeWindowLatencyHistogram histogram;
private final HistogramConfig histogramConfig;
private final TimeUnit baseTimeUnit;

protected AbstractTimer(Id id, Clock clock, HistogramConfig histogramConfig, PauseDetector pauseDetector, TimeUnit baseTimeUnit) {
Original file line number Diff line number Diff line change
@@ -18,6 +18,18 @@
import io.micrometer.core.instrument.step.StepLong;

public interface Clock {
Clock SYSTEM = new Clock() {
@Override
public long wallTime() {
return System.currentTimeMillis();
}

@Override
public long monotonicTime() {
return System.nanoTime();
}
};

/**
* Current wall time in milliseconds since the epoch. Typically equivalent to
* System.currentTimeMillis. Should not be used to determine durations. Used
@@ -28,7 +40,6 @@ public interface Clock {
*/
long wallTime();


/**
* Current time from a monotonic clock source. The value is only meaningful when compared with
* another snapshot to determine the elapsed time for an operation. The difference between two
@@ -38,16 +49,4 @@ public interface Clock {
* @return Monotonic time in nanoseconds
*/
long monotonicTime();

Clock SYSTEM = new Clock() {
@Override
public long wallTime() {
return System.currentTimeMillis();
}

@Override
public long monotonicTime() {
return System.nanoTime();
}
};
}
Original file line number Diff line number Diff line change
@@ -15,24 +15,23 @@
*/
package io.micrometer.core.instrument;

import java.util.concurrent.TimeUnit;

import io.micrometer.core.instrument.util.TimeUtils;

public final class CountAtValue {
import java.util.concurrent.TimeUnit;

public static CountAtValue of(long value, double count) {
return new CountAtValue(value, count);
}
public final class CountAtValue {

private final long value;
private final double count;

private CountAtValue(long value, double count) {
this.value = value;
this.count = count;
}

public static CountAtValue of(long value, double count) {
return new CountAtValue(value, count);
}

public long value() {
return value;
}
Original file line number Diff line number Diff line change
@@ -25,6 +25,10 @@
* Used to measure the rate of change based on calls to increment.
*/
public interface Counter extends Meter {
static Builder builder(String name) {
return new Builder(name);
}

/**
* Update the counter by one.
*/
@@ -54,15 +58,13 @@ default Type type() {
return Type.Counter;
}

static Builder builder(String name) {
return new Builder(name);
}

class Builder {
private final String name;
private final List<Tag> tags = new ArrayList<>();
@Nullable private String description;
@Nullable private String baseUnit;
@Nullable
private String description;
@Nullable
private String baseUnit;

private Builder(String name) {
this.name = name;
Original file line number Diff line number Diff line change
@@ -29,6 +29,10 @@
*/
public interface DistributionSummary extends Meter {

static Builder builder(String name) {
return new Builder(name);
}

/**
* Updates the statistics kept by the summary with the specified amount.
*
@@ -65,15 +69,21 @@ default double mean() {

HistogramSnapshot takeSnapshot(boolean supportsAggregablePercentiles);

static Builder builder(String name) {
return new Builder(name);
@Override
default Iterable<Measurement> measure() {
return Arrays.asList(
new Measurement(() -> (double) count(), Statistic.Count),
new Measurement(this::totalAmount, Statistic.Total)
);
}

class Builder {
private final String name;
private final List<Tag> tags = new ArrayList<>();
@Nullable private String description;
@Nullable private String baseUnit;
@Nullable
private String description;
@Nullable
private String baseUnit;
private HistogramConfig.Builder histogramConfigBuilder = HistogramConfig.builder();

private Builder(String name) {
@@ -176,12 +186,4 @@ public DistributionSummary register(MeterRegistry registry) {
}
}

@Override
default Iterable<Measurement> measure() {
return Arrays.asList(
new Measurement(() -> (double) count(), Statistic.Count),
new Measurement(this::totalAmount, Statistic.Total)
);
}

}
Original file line number Diff line number Diff line change
@@ -28,6 +28,10 @@
* @author Jon Schneider
*/
public interface FunctionCounter extends Meter {
static <T> Builder<T> builder(String name, T obj, ToDoubleFunction<T> f) {
return new Builder<>(name, obj, f);
}

/**
* The cumulative count since this counter was created.
*/
@@ -43,17 +47,15 @@ default Meter.Type type() {
return Meter.Type.Counter;
}

static <T> Builder<T> builder(String name, T obj, ToDoubleFunction<T> f) {
return new Builder<>(name, obj, f);
}

class Builder<T> {
private final String name;
private final T obj;
private final ToDoubleFunction<T> f;
private final List<Tag> tags = new ArrayList<>();
@Nullable private String description;
@Nullable private String baseUnit;
@Nullable
private String description;
@Nullable
private String baseUnit;

private Builder(String name, T obj, ToDoubleFunction<T> f) {
this.name = name;
Original file line number Diff line number Diff line change
@@ -25,6 +25,12 @@
import java.util.function.ToLongFunction;

public interface FunctionTimer extends Meter {
static <T> Builder<T> builder(String name, T obj, ToLongFunction<T> countFunction,
ToDoubleFunction<T> totalTimeFunction,
TimeUnit totalTimeFunctionUnits) {
return new Builder<>(name, obj, countFunction, totalTimeFunction, totalTimeFunctionUnits);
}

/**
* The total number of occurrences of the timed event.
*/
@@ -49,21 +55,17 @@ default Iterable<Measurement> measure() {
);
}

static <T> Builder<T> builder(String name, T obj, ToLongFunction<T> countFunction,
ToDoubleFunction<T> totalTimeFunction,
TimeUnit totalTimeFunctionUnits) {
return new Builder<>(name, obj, countFunction, totalTimeFunction, totalTimeFunctionUnits);
}

class Builder<T> {
private final String name;
private final T obj;
private final ToLongFunction<T> countFunction;
private final ToDoubleFunction<T> totalTimeFunction;
private final TimeUnit totalTimeFunctionUnits;
private final List<Tag> tags = new ArrayList<>();
@Nullable private String description;
@Nullable private String baseUnit;
@Nullable
private String description;
@Nullable
private String baseUnit;

private Builder(String name, T obj,
ToLongFunction<T> countFunction,
Original file line number Diff line number Diff line change
@@ -23,6 +23,10 @@
import java.util.function.ToDoubleFunction;

public interface Gauge extends Meter {
static <T> Builder<T> builder(String name, @Nullable T obj, ToDoubleFunction<T> f) {
return new Builder<>(name, obj, f);
}

/**
* Returns the current value. The act of observing the value by calling this method triggers sampling
* of the underlying number or user-defined function that defines the value for the gauge.
@@ -39,17 +43,16 @@ default Type type() {
return Type.Gauge;
}

static <T> Builder<T> builder(String name, @Nullable T obj, ToDoubleFunction<T> f) {
return new Builder<>(name, obj, f);
}

class Builder<T> {
private final String name;
@Nullable private final T obj;
@Nullable
private final T obj;
private final ToDoubleFunction<T> f;
private final List<Tag> tags = new ArrayList<>();
@Nullable private String description;
@Nullable private String baseUnit;
@Nullable
private String description;
@Nullable
private String baseUnit;

private Builder(String name, @Nullable T obj, ToDoubleFunction<T> f) {
this.name = name;
@@ -64,7 +67,7 @@ private Builder(String name, @Nullable T obj, ToDoubleFunction<T> f) {
public Builder tags(String... tags) {
return tags(Tags.zip(tags));
}

public Builder tags(Iterable<Tag> tags) {
tags.forEach(this.tags::add);
return this;
Original file line number Diff line number Diff line change
@@ -26,23 +26,11 @@ public final class HistogramSnapshot {
private static final ValueAtPercentile[] EMPTY_VALUES = new ValueAtPercentile[0];
private static final CountAtValue[] EMPTY_COUNTS = new CountAtValue[0];
private static final HistogramSnapshot EMPTY = new HistogramSnapshot(0, 0, 0, null, null);

public static HistogramSnapshot of(long count, double total, double max,
@Nullable ValueAtPercentile[] percentileValues,
@Nullable CountAtValue[] histogramCounts) {
return new HistogramSnapshot(count, total, max, percentileValues, histogramCounts);
}

public static HistogramSnapshot empty() {
return EMPTY;
}

private final long count;
private final double total;
private final double max;
private final ValueAtPercentile[] percentileValues;
private final CountAtValue[] histogramCounts;

private HistogramSnapshot(long count, double total, double max,
@Nullable ValueAtPercentile[] percentileValues,
@Nullable CountAtValue[] histogramCounts) {
@@ -53,6 +41,16 @@ private HistogramSnapshot(long count, double total, double max,
this.histogramCounts = histogramCounts != null ? histogramCounts : EMPTY_COUNTS;
}

public static HistogramSnapshot of(long count, double total, double max,
@Nullable ValueAtPercentile[] percentileValues,
@Nullable CountAtValue[] histogramCounts) {
return new HistogramSnapshot(count, total, max, percentileValues, histogramCounts);
}

public static HistogramSnapshot empty() {
return EMPTY;
}

public long count() {
return count;
}
Original file line number Diff line number Diff line change
@@ -48,7 +48,7 @@ public boolean equals(@Nullable Object o) {
if (o == null || getClass() != o.getClass()) return false;
Tag that = (Tag) o;
return Objects.equals(key, that.getKey()) &&
Objects.equals(value, that.getValue());
Objects.equals(value, that.getValue());
}

@Override
@@ -59,8 +59,8 @@ public int hashCode() {
@Override
public String toString() {
return "ImmutableTag{" +
"key='" + key + '\'' +
", value='" + value + '\'' +
'}';
"key='" + key + '\'' +
", value='" + value + '\'' +
'}';
}
}
Rate limit · GitHub

Access has been restricted

You have triggered a rate limit.

Please wait a few minutes before you try again;
in some cases this may take up to an hour.

0 comments on commit 71576d1

Please sign in to comment.