Aggregate max statistics in metrics endpoint with Double#max
See gh-11852
This commit is contained in:
committed by
Andy Wilkinson
parent
ba54cbddf6
commit
92287f75f7
@@ -18,6 +18,7 @@ package org.springframework.boot.actuate.metrics;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import io.micrometer.core.instrument.MeterRegistry;
|
||||
@@ -129,6 +130,31 @@ public class MetricsEndpointTests {
|
||||
assertThat(response).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void maxAggregation() {
|
||||
SimpleMeterRegistry reg = new SimpleMeterRegistry();
|
||||
reg.timer("timer", "k", "v1").record(1, TimeUnit.SECONDS);
|
||||
reg.timer("timer", "k", "v2").record(2, TimeUnit.SECONDS);
|
||||
|
||||
assertMetricHasStatisticEqualTo(reg, "timer", Statistic.MAX, 2.0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void countAggregation() {
|
||||
SimpleMeterRegistry reg = new SimpleMeterRegistry();
|
||||
reg.counter("counter", "k", "v1").increment();
|
||||
reg.counter("counter", "k", "v2").increment();
|
||||
|
||||
assertMetricHasStatisticEqualTo(reg, "counter", Statistic.COUNT, 2.0);
|
||||
}
|
||||
|
||||
private void assertMetricHasStatisticEqualTo(MeterRegistry registry, String metricName, Statistic stat, Double value) {
|
||||
MetricsEndpoint endpoint = new MetricsEndpoint(registry);
|
||||
assertThat(endpoint.metric(metricName, Collections.emptyList()).getMeasurements()
|
||||
.stream().filter(s -> s.getStatistic().equals(stat)).findAny())
|
||||
.hasValueSatisfying(s -> assertThat(s.getValue()).isEqualTo(value));
|
||||
}
|
||||
|
||||
private Optional<Double> getCount(MetricsEndpoint.MetricResponse response) {
|
||||
return response.getMeasurements().stream()
|
||||
.filter((ms) -> ms.getStatistic().equals(Statistic.COUNT)).findAny()
|
||||
|
||||
Reference in New Issue
Block a user