Skip to content

Commit

Permalink
Merge branch '1.4.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Schneider committed Apr 14, 2020
2 parents 0dc111d + f8fc920 commit 4c22298
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 218 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.micrometer.core.instrument.Measurement;
import io.micrometer.core.instrument.Statistic;
import io.micrometer.core.instrument.distribution.DistributionStatisticConfig;
import io.micrometer.core.instrument.distribution.TimeWindowMax;

import java.util.Arrays;

Expand All @@ -32,7 +33,7 @@
public class StepDistributionSummary extends AbstractDistributionSummary {
private final StepLong count;
private final StepDouble total;
private final StepDoubleMax max;
private final TimeWindowMax max;

/**
* Create a new {@code StepDistributionSummary}.
Expand All @@ -44,13 +45,12 @@ public class StepDistributionSummary extends AbstractDistributionSummary {
* @param stepMillis step in milliseconds
* @param supportsAggregablePercentiles whether it supports aggregable percentiles
*/
@SuppressWarnings("ConstantConditions")
public StepDistributionSummary(Id id, Clock clock, DistributionStatisticConfig distributionStatisticConfig, double scale,
long stepMillis, boolean supportsAggregablePercentiles) {
super(id, clock, distributionStatisticConfig, scale, supportsAggregablePercentiles);
this.count = new StepLong(clock, stepMillis);
this.total = new StepDouble(clock, stepMillis);
this.max = new StepDoubleMax(clock, stepMillis);
this.max = new TimeWindowMax(clock, distributionStatisticConfig);
}

@Override
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import io.micrometer.core.instrument.AbstractTimer;
import io.micrometer.core.instrument.Clock;
import io.micrometer.core.instrument.distribution.DistributionStatisticConfig;
import io.micrometer.core.instrument.distribution.TimeWindowMax;
import io.micrometer.core.instrument.distribution.pause.PauseDetector;
import io.micrometer.core.instrument.util.TimeUtils;

Expand All @@ -29,7 +30,7 @@
public class StepTimer extends AbstractTimer {
private final StepLong count;
private final StepLong total;
private final StepLongMax max;
private final TimeWindowMax max;

/**
* Create a new {@code StepTimer}.
Expand All @@ -50,7 +51,7 @@ public StepTimer(final Id id, final Clock clock, final DistributionStatisticConf

count = new StepLong(clock, stepDurationMillis);
total = new StepLong(clock, stepDurationMillis);
max = new StepLongMax(clock, stepDurationMillis);
max = new TimeWindowMax(clock, distributionStatisticConfig);
}

@Override
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,15 @@
import org.junit.jupiter.api.Test;

import java.time.Duration;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

import static java.time.Duration.ofMillis;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.SoftAssertions.assertSoftly;

/**
* Tests for {@link StepMeterRegistry}.
Expand Down Expand Up @@ -66,8 +71,8 @@ void slasOnlyNoPercentileHistogram() {
DistributionSummary summary = DistributionSummary.builder("my.summary").sla(1.0, 2).register(registry);
summary.record(1);

Timer timer = Timer.builder("my.timer").sla(Duration.ofMillis(1)).register(registry);
timer.record(1, TimeUnit.MILLISECONDS);
Timer timer = Timer.builder("my.timer").sla(ofMillis(1)).register(registry);
timer.record(1, MILLISECONDS);

Gauge summaryHist1 = registry.get("my.summary.histogram").tags("le", "1").gauge();
Gauge summaryHist2 = registry.get("my.summary.histogram").tags("le", "2").gauge();
Expand All @@ -92,59 +97,65 @@ void publishOneLastTimeOnClose() {
assertThat(publishes.get()).isEqualTo(1);
}

@Issue("#1796")
@Issue("#1993")
@Test
void timerMaxValueFromLastStep() {
Timer timer = Timer.builder("my.timer").register(registry);
void timerMaxValueDecays() {
Timer timerStep1Length2 = Timer.builder("timer1x2")
.distributionStatisticBufferLength(2)
.distributionStatisticExpiry(config.step())
.register(registry);

timer.record(Duration.ofMillis(20));
timer.record(Duration.ofMillis(10));
Timer timerStep2Length2 = Timer.builder("timer2x2")
.distributionStatisticBufferLength(2)
.distributionStatisticExpiry(config.step().multipliedBy(2))
.register(registry);

clock.add(config.step().minusMillis(2));
assertThat(timer.max(TimeUnit.MILLISECONDS)).isEqualTo(0L);
Timer timerStep1Length6 = Timer.builder("timer1x6")
.distributionStatisticBufferLength(6)
.distributionStatisticExpiry(config.step())
.register(registry);

clock.add(Duration.ofMillis(1));
assertThat(timer.max(TimeUnit.MILLISECONDS)).isEqualTo(20L);
List<Timer> timers = Arrays.asList(timerStep1Length2, timerStep2Length2, timerStep1Length6);

clock.add(Duration.ofMillis(1));
timer.record(Duration.ofMillis(10));
timer.record(Duration.ofMillis(5));
timers.forEach(t -> t.record(ofMillis(15)));

clock.add(config.step().minusMillis(2));
assertThat(timer.max(TimeUnit.MILLISECONDS)).isEqualTo(20L);

clock.add(Duration.ofMillis(1));
assertThat(timer.max(TimeUnit.MILLISECONDS)).isEqualTo(10L);
assertSoftly(softly -> {
softly.assertThat(timerStep1Length2.max(MILLISECONDS)).isEqualTo(15L);
softly.assertThat(timerStep2Length2.max(MILLISECONDS)).isEqualTo(15L);
softly.assertThat(timerStep1Length6.max(MILLISECONDS)).isEqualTo(15L);
});

clock.add(config.step().plus(Duration.ofMillis(1)));
clock.add(config.step());
assertThat(timer.max(TimeUnit.MILLISECONDS)).isEqualTo(0L);
}

@Test
void distributionSummaryMaxValueFromLastStep() {
DistributionSummary distributionSummary = DistributionSummary.builder("my.distribution.summary").register(registry);

distributionSummary.record(20);
distributionSummary.record(10);
timers.forEach(t -> t.record(ofMillis(10)));

clock.add(config.step().minusMillis(2));
assertThat(distributionSummary.max()).isEqualTo(0L);
assertSoftly(softly -> {
softly.assertThat(timerStep1Length2.max(MILLISECONDS)).isEqualTo(10L);
softly.assertThat(timerStep2Length2.max(MILLISECONDS)).isEqualTo(15L);
softly.assertThat(timerStep1Length6.max(MILLISECONDS)).isEqualTo(15L);
});

clock.add(Duration.ofMillis(1));
assertThat(distributionSummary.max()).isEqualTo(20L);

clock.add(Duration.ofMillis(1));
distributionSummary.record(10);
distributionSummary.record(5);

clock.add(config.step().minusMillis(2));
assertThat(distributionSummary.max()).isEqualTo(20L);
clock.add(config.step());
timers.forEach(t -> t.record(ofMillis(5)));

clock.add(Duration.ofMillis(1));
assertThat(distributionSummary.max()).isEqualTo(10L);
assertSoftly(softly -> {
softly.assertThat(timerStep1Length2.max(MILLISECONDS)).isEqualTo(10L);
softly.assertThat(timerStep2Length2.max(MILLISECONDS)).isEqualTo(15L);
softly.assertThat(timerStep1Length6.max(MILLISECONDS)).isEqualTo(15L);
});

clock.add(config.step());
assertThat(distributionSummary.max()).isEqualTo(0L);
assertSoftly(softly -> {
softly.assertThat(timerStep1Length2.max(MILLISECONDS)).isEqualTo(5L);
softly.assertThat(timerStep2Length2.max(MILLISECONDS)).isEqualTo(10L);
softly.assertThat(timerStep1Length6.max(MILLISECONDS)).isEqualTo(15L);
});

clock.add(config.step().multipliedBy(5));
assertSoftly(softly -> {
softly.assertThat(timerStep1Length2.max(MILLISECONDS)).isEqualTo(0L);
softly.assertThat(timerStep2Length2.max(MILLISECONDS)).isEqualTo(0L);
softly.assertThat(timerStep1Length6.max(MILLISECONDS)).isEqualTo(0L);
});
}

}

0 comments on commit 4c22298

Please sign in to comment.