Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix FunctionCounter in SingleIndicator.Builder.count() #2438

Merged
merged 1 commit into from Feb 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -40,7 +40,10 @@
import static io.micrometer.health.QueryUtils.SUM_OR_NAN;

/**
* Service level objective.
*
* @author Jon Schneider
* @author Johnny Lim
* @since 1.6.0
*/
public abstract class ServiceLevelObjective {
Expand Down Expand Up @@ -240,7 +243,7 @@ public final NumericQuery count(Function<Search, Search> search) {
} else if (m instanceof FunctionTimer) {
return ((FunctionTimer) m).count();
} else if (m instanceof FunctionCounter) {
((FunctionCounter) m).count();
return ((FunctionCounter) m).count();
} else if (m instanceof LongTaskTimer) {
return (double) ((LongTaskTimer) m).activeTasks();
}
Expand Down
Expand Up @@ -15,6 +15,7 @@
*/
package io.micrometer.health;

import io.micrometer.core.instrument.FunctionCounter;
import io.micrometer.core.instrument.MockClock;
import io.micrometer.core.instrument.Timer;
import io.micrometer.core.instrument.util.TimeUtils;
Expand All @@ -27,12 +28,20 @@
import static io.micrometer.core.instrument.MockClock.clock;
import static org.assertj.core.api.Assertions.assertThat;

/**
* Tests for queries.
*
* @author Jon Schneider
* @author Johnny Lim
*/
class QueryTest {
HealthMeterRegistry registry = HealthMeterRegistry
.builder(HealthConfig.DEFAULT)
// just so my.timer doesn't get filtered out eagerly
.serviceLevelObjectives(ServiceLevelObjective.build("timer")
.count(s -> s.name("my.timer")).isGreaterThan(0))
.serviceLevelObjectives(ServiceLevelObjective.build("function.counter")
.count(s -> s.name("my.function.counter")).isGreaterThan(0))
.clock(new MockClock())
.build();

Expand All @@ -44,6 +53,8 @@ void before() {
t2.record(2, TimeUnit.SECONDS);
t2.record(2, TimeUnit.SECONDS);

FunctionCounter.builder("my.function.counter", 1d, Number::doubleValue).register(registry);

clock(registry).addSeconds(10);
registry.tick();
}
Expand All @@ -58,6 +69,15 @@ void count() {
).isEqualTo(3);
}

@Test
void countWhenMeterIsFunctionCounter() {
assertThat(
ServiceLevelObjective.build("function.counter.objective")
.count(s -> s.name("my.function.counter"))
.getValue(registry)
).isEqualTo(1);
}

@Test
void max() {
assertThat(
Expand Down