Skip to content

Commit

Permalink
Added the metrics with tags testcase
Browse files Browse the repository at this point in the history
  • Loading branch information
Dhrubajyoti Sadhu committed Aug 14, 2023
1 parent c5b17ea commit 4244a44
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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<Meter> 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");
Expand Down

0 comments on commit 4244a44

Please sign in to comment.