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 4244a44 commit 7ce9fad
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 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); //counter.Type_Anonymous.calls
incrementWithTags(buildMetricPath(COUNTER, newMetricBasePath, result), methodName); //counter.Type_Anonymous.success
incrementWithTags(buildMetricPath(COUNTER, newMetricBasePath, "calls"), methodName);
incrementWithTags(buildMetricPath(COUNTER, newMetricBasePath, result), methodName);
submitWithTags(buildMetricPath(TIMER, newMetricBasePath, "duration"),
stopwatch.elapsed(TimeUnit.MILLISECONDS), methodName); //timer.Type_Anonymous.duration
stopwatch.elapsed(TimeUnit.MILLISECONDS), methodName);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@

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;
Expand All @@ -36,6 +34,7 @@
import io.micrometer.core.instrument.Meter;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.cumulative.CumulativeCounter;
import io.micrometer.core.instrument.cumulative.CumulativeTimer;
import io.micrometer.core.instrument.search.RequiredSearch;
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;

Expand Down Expand Up @@ -121,9 +120,16 @@ 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));

meters = meterRegistry.get("counter.Type_Anonymous.calls").meters();
assertThat(meters.size(), is(1));
assertThat(((CumulativeCounter) ((ArrayList) meters).get(0)).count(), is(1.0));

meters = meterRegistry.get("timer.Type_Anonymous.duration").meters();
assertThat(meters.size(), is(1));
assertThat(((CumulativeTimer) ((ArrayList) meters).get(0)).count(), is(1L));
}

@Test
Expand Down

0 comments on commit 7ce9fad

Please sign in to comment.