mirror of
https://github.com/aljazceru/lnd-manageJ.git
synced 2026-01-31 03:34:36 +01:00
add class to timer names
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user