add class to timer names

This commit is contained in:
Carsten Otto
2021-11-30 08:57:40 +01:00
parent 83c49e78c2
commit 3087adcd85
4 changed files with 7 additions and 7 deletions

View File

@@ -35,7 +35,7 @@ public class GrpcBase {
<X> Optional<X> get(String name, Supplier<X> supplier) {
try {
return Optional.ofNullable(metrics.timer(name).timeSupplier(supplier));
return Optional.ofNullable(metrics.timer(getClass(), name).timeSupplier(supplier));
} catch (StatusRuntimeException exception) {
logger.warn("Exception while connecting to lnd: ", exception);
return Optional.empty();

View File

@@ -33,7 +33,7 @@ class GrpcBaseTest {
void setUp() {
Timer timer = mock(Timer.class);
lenient().when(timer.timeSupplier(any())).then(invocation -> ((Supplier<?>) invocation.getArgument(0)).get());
lenient().when(metrics.timer(anyString())).thenReturn(timer);
lenient().when(metrics.timer(any(), anyString())).thenReturn(timer);
}
@Test
@@ -44,7 +44,7 @@ class GrpcBaseTest {
@Test
void get_uses_timer() {
grpcBase.get("name", () -> "x");
verify(metrics).timer("name");
verify(metrics).timer(grpcBase.getClass(), "name");
}
@Test

View File

@@ -37,7 +37,7 @@ public class Metrics {
meters.computeIfAbsent(name, registry::meter).mark();
}
public Timer timer(String name) {
return timers.computeIfAbsent(name, registry::timer);
public Timer timer(Class<?> callingClass, String name) {
return timers.computeIfAbsent(MetricRegistry.name(callingClass, name), registry::timer);
}
}

View File

@@ -17,8 +17,8 @@ class MetricsTest {
@Test
void timer() {
String name = "timer.name";
metrics.timer(name).time(this::sleep);
assertThat(metrics.timer(name).getCount()).isEqualTo(1);
metrics.timer(String.class, name).time(this::sleep);
assertThat(metrics.timer(String.class, name).getCount()).isEqualTo(1);
}
@Test