Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
izeye authored Sep 11, 2024
1 parent 9991df4 commit b410174
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
* should be passed as {@code 0.1}.
* @return service level objectives to calculate
* @see io.micrometer.core.instrument.Timer.Builder#serviceLevelObjectives(java.time.Duration...)
* @since 1.14.0
*/
double[] serviceLevelObjectives() default {};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,17 @@
import io.micrometer.core.instrument.distribution.pause.PauseDetector;
import io.micrometer.core.instrument.search.MeterNotFoundException;
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
import io.micrometer.core.instrument.util.TimeUtils;
import org.aspectj.lang.ProceedingJoinPoint;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;
import org.springframework.aop.aspectj.annotation.AspectJProxyFactory;

import javax.annotation.Nonnull;
import java.util.Arrays;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
import java.util.concurrent.TimeUnit;
import java.util.function.Predicate;

import static java.util.concurrent.CompletableFuture.supplyAsync;
Expand Down Expand Up @@ -109,16 +110,15 @@ void timeMethodWithSloTimer() {

service.sloCall();

assertThat(Arrays
.stream(registry.get("sloCall")
.tag("class", getClass().getName() + "$TimedService")
.tag("method", "sloCall")
.tag("extra", "tag")
.timer()
.takeSnapshot()
.histogramCounts())
.mapToDouble(CountAtBucket::bucket)
.toArray()).isEqualTo(new double[] { Math.pow(10, 9) * 0.1, Math.pow(10, 9) * 0.5 });
assertThat(registry.get("sloCall")
.tag("class", getClass().getName() + "$TimedService")
.tag("method", "sloCall")
.tag("extra", "tag")
.timer()
.takeSnapshot()
.histogramCounts()).extracting(CountAtBucket::bucket)
.containsExactly(TimeUtils.secondsToUnit(0.1, TimeUnit.NANOSECONDS),
TimeUtils.secondsToUnit(0.5, TimeUnit.NANOSECONDS));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import io.micrometer.core.instrument.binder.jersey.server.resources.TimedResource;
import io.micrometer.core.instrument.distribution.CountAtBucket;
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
import io.micrometer.core.instrument.util.TimeUtils;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.test.JerseyTest;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -95,17 +96,13 @@ void resourcesWithAnnotationAreTimed() {
}

@Test
void sloTaskTimerSupported() throws InterruptedException, ExecutionException, TimeoutException {
void sloTimerSupported() {
target("timed-slo").request().get();

CountAtBucket[] slos = registry.get("timedSlo")
.tags(tagsFrom("/timed-slo", 200))
.timer()
.takeSnapshot()
.histogramCounts();
assertThat(slos.length).isEqualTo(2);
assertThat(slos[0].bucket()).isEqualTo(Math.pow(10, 9) * 0.1);
assertThat(slos[1].bucket()).isEqualTo(Math.pow(10, 9) * 0.5);
assertThat(registry.get("timedSlo").tags(tagsFrom("/timed-slo", 200)).timer().takeSnapshot().histogramCounts())
.extracting(CountAtBucket::bucket)
.containsExactly(TimeUtils.secondsToUnit(0.1, TimeUnit.NANOSECONDS),
TimeUtils.secondsToUnit(0.5, TimeUnit.NANOSECONDS));
}

@Test
Expand Down

0 comments on commit b410174

Please sign in to comment.