From 4244a4464f41ab260ca5372173cd3ad94e01779c Mon Sep 17 00:00:00 2001 From: Dhrubajyoti Sadhu Date: Tue, 15 Aug 2023 00:12:55 +0100 Subject: [PATCH] Added the metrics with tags testcase --- .../waggledance/metrics/MonitoredAspect.java | 6 +++--- .../metrics/MonitoredAspectTest.java | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/waggle-dance-core/src/main/java/com/hotels/bdp/waggledance/metrics/MonitoredAspect.java b/waggle-dance-core/src/main/java/com/hotels/bdp/waggledance/metrics/MonitoredAspect.java index 6efc96656..18b5c5e5f 100644 --- a/waggle-dance-core/src/main/java/com/hotels/bdp/waggledance/metrics/MonitoredAspect.java +++ b/waggle-dance-core/src/main/java/com/hotels/bdp/waggledance/metrics/MonitoredAspect.java @@ -73,10 +73,10 @@ public Object monitor(ProceedingJoinPoint pjp, Monitored monitored) throws Throw stopwatch.elapsed(TimeUnit.MILLISECONDS)); // Sends metrics with Tags: federation_namespace and method_name - incrementWithTags(buildMetricPath(COUNTER, newMetricBasePath, "calls"), methodName); - incrementWithTags(buildMetricPath(COUNTER, newMetricBasePath, result), methodName); + incrementWithTags(buildMetricPath(COUNTER, newMetricBasePath, "calls"), methodName); //counter.Type_Anonymous.calls + incrementWithTags(buildMetricPath(COUNTER, newMetricBasePath, result), methodName); //counter.Type_Anonymous.success submitWithTags(buildMetricPath(TIMER, newMetricBasePath, "duration"), - stopwatch.elapsed(TimeUnit.MILLISECONDS), methodName); + stopwatch.elapsed(TimeUnit.MILLISECONDS), methodName); //timer.Type_Anonymous.duration } } diff --git a/waggle-dance-core/src/test/java/com/hotels/bdp/waggledance/metrics/MonitoredAspectTest.java b/waggle-dance-core/src/test/java/com/hotels/bdp/waggledance/metrics/MonitoredAspectTest.java index 1f0de31d5..2de6bab94 100644 --- a/waggle-dance-core/src/test/java/com/hotels/bdp/waggledance/metrics/MonitoredAspectTest.java +++ b/waggle-dance-core/src/test/java/com/hotels/bdp/waggledance/metrics/MonitoredAspectTest.java @@ -20,6 +20,11 @@ import static org.mockito.Mockito.reset; import static org.mockito.Mockito.when; +import java.util.ArrayList; +import java.util.Collection; +import io.micrometer.core.instrument.Tag; +import io.micrometer.core.instrument.Tags; + import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.Signature; import org.junit.Before; @@ -28,7 +33,9 @@ import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; +import io.micrometer.core.instrument.Meter; import io.micrometer.core.instrument.MeterRegistry; +import io.micrometer.core.instrument.cumulative.CumulativeCounter; import io.micrometer.core.instrument.search.RequiredSearch; import io.micrometer.core.instrument.simple.SimpleMeterRegistry; @@ -109,6 +116,16 @@ public void monitorSuccesses() throws Throwable { assertThat(rs.timer().count(), is(1L)); } + @Test + public void monitorSuccessWithTags() throws Throwable { + aspect.monitor(pjp, monitored); + + Collection meters = meterRegistry.get("counter.Type_Anonymous.success").meters(); + + assertThat(meters.size(), is(1)); + assertThat(((CumulativeCounter) ((ArrayList) meters).get(0)).count(), is(1.0)); + } + @Test public void monitorFailuresForSpecificMetastore() throws Throwable { CurrentMonitoredMetaStoreHolder.monitorMetastore("metastoreName");