use of org.eclipse.microprofile.metrics.Tag in project Payara by payara.
the class JsonExporterGetTest method exportCounter.
@Test
public void exportCounter() {
Counter hitCount = mock(Counter.class);
when(hitCount.getCount()).thenReturn(45L);
Counter hitCount2 = mock(Counter.class);
when(hitCount2.getCount()).thenReturn(3L);
Counter hitCount3 = mock(Counter.class);
when(hitCount3.getCount()).thenReturn(4L);
export(new MetricID("hitCount"), hitCount);
export(new MetricID("hitCount", new Tag("servlet", "two")), hitCount2);
export(new MetricID("hitCount", new Tag("store", "webshop"), new Tag("servlet", "three")), hitCount3);
assertOutputEqualsFile("Counter.json");
}
use of org.eclipse.microprofile.metrics.Tag in project Payara by payara.
the class JsonExporterGetTest method exportGauge.
@Test
public void exportGauge() {
Gauge<Double> responsePercentage1 = () -> 48.45632d;
Gauge<Double> responsePercentage2 = () -> 26.23654d;
Gauge<Double> responsePercentage3 = () -> 29.24554d;
export(new MetricID("responsePercentage"), responsePercentage1);
export(new MetricID("responsePercentage", new Tag("servlet", "two")), responsePercentage2);
export(new MetricID("responsePercentage", new Tag("store", "webshop"), new Tag("servlet", "three")), responsePercentage3);
assertOutputEqualsFile("Gauge.json");
}
use of org.eclipse.microprofile.metrics.Tag in project Payara by payara.
the class JsonExporterGetTest method exportHistogram.
@Test
public void exportHistogram() {
Histogram histogram = mock(Histogram.class);
when(histogram.getCount()).thenReturn(2L);
when(histogram.getSum()).thenReturn(42L);
Snapshot snapshot = mock(Snapshot.class);
when(histogram.getSnapshot()).thenReturn(snapshot);
when(snapshot.getMin()).thenReturn(-1624L);
when(snapshot.getMax()).thenReturn(26L);
when(snapshot.getMean()).thenReturn(-799.0d);
when(snapshot.getStdDev()).thenReturn(825d);
when(snapshot.getMedian()).thenReturn(26d);
when(snapshot.get75thPercentile()).thenReturn(26d);
when(snapshot.get95thPercentile()).thenReturn(26d);
when(snapshot.get98thPercentile()).thenReturn(26d);
when(snapshot.get99thPercentile()).thenReturn(26d);
when(snapshot.get999thPercentile()).thenReturn(26d);
// example uses same values for both histograms so we can get away with just one
// but conceptually those should be two different histogram instances
export(new MetricID("daily_value_changes"), histogram);
export(new MetricID("daily_value_changes", new Tag("servlet", "two")), histogram);
assertOutputEqualsFile("Histogram.json");
}
use of org.eclipse.microprofile.metrics.Tag in project Payara by payara.
the class JsonExporter method completeGroup.
private void completeGroup(MetricID current, Metadata metadata) {
if (mode == Mode.GET && groupObj != null) {
JsonObjectBuilder target = scopeObj != null ? scopeObj : documentObj;
target.add(exportedBefore.getName(), groupObj);
groupObj = null;
}
if (mode == Mode.OPTIONS) {
if (isNameChange(current)) {
exportMetadata();
}
List<Tag> tags = tagsAlphabeticallySorted(current);
if (!tags.isEmpty()) {
JsonArrayBuilder currentTags = Json.createArrayBuilder();
for (Tag tag : tags) {
currentTags.add(tagAsString(tag));
}
if (tagsArray == null) {
tagsArray = Json.createArrayBuilder();
}
tagsArray.add(currentTags.build());
}
}
exportedBefore = current;
exportedBeforeMetadata = metadata;
}
use of org.eclipse.microprofile.metrics.Tag in project Payara by payara.
the class BulkheadMetricTckTest method bulkheadMetricAsyncTest.
/**
* Scenario is equivalent to the TCK test of same name but not 100% identical
*/
@Test(timeout = 3000)
public void bulkheadMetricAsyncTest() {
callMethodWithNewThreadAndWaitFor(commonWaiter);
callMethodWithNewThreadAndWaitFor(commonWaiter);
waitUntilPermitsAquired(2, 0);
callMethodWithNewThreadAndWaitFor(commonWaiter);
callMethodWithNewThreadAndWaitFor(commonWaiter);
waitUntilPermitsAquired(2, 2);
assertFurtherThreadThrowsBulkheadException(1);
commonWaiter.complete(null);
waitUntilPermitsAquired(0, 0);
String methodName = "fish.payara.microprofile.faulttolerance.policy.BulkheadMetricTckTest.bulkheadMetricAsyncTest_Method";
Counter successfulInvocations = registry.getCounter(new MetricID("ft.invocations.total", new Tag("method", methodName), new Tag("fallback", "notDefined"), new Tag("result", "valueReturned")));
Counter failedInvocations = registry.getCounter(new MetricID("ft.invocations.total", new Tag("method", methodName), new Tag("fallback", "notDefined"), new Tag("result", "exceptionThrown")));
assertEquals(4, successfulInvocations.getCount());
assertEquals(1, failedInvocations.getCount());
}
Aggregations