Search in sources :

Example 31 with Tag

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");
}
Also used : MetricID(org.eclipse.microprofile.metrics.MetricID) Counter(org.eclipse.microprofile.metrics.Counter) Tag(org.eclipse.microprofile.metrics.Tag) Test(org.junit.Test)

Example 32 with Tag

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");
}
Also used : MetricID(org.eclipse.microprofile.metrics.MetricID) Tag(org.eclipse.microprofile.metrics.Tag) Test(org.junit.Test)

Example 33 with Tag

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");
}
Also used : Snapshot(org.eclipse.microprofile.metrics.Snapshot) Histogram(org.eclipse.microprofile.metrics.Histogram) MetricID(org.eclipse.microprofile.metrics.MetricID) Tag(org.eclipse.microprofile.metrics.Tag) Test(org.junit.Test)

Example 34 with Tag

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;
}
Also used : Tag(org.eclipse.microprofile.metrics.Tag) JsonArrayBuilder(javax.json.JsonArrayBuilder) JsonObjectBuilder(javax.json.JsonObjectBuilder)

Example 35 with Tag

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());
}
Also used : MetricID(org.eclipse.microprofile.metrics.MetricID) Counter(org.eclipse.microprofile.metrics.Counter) Tag(org.eclipse.microprofile.metrics.Tag) Test(org.junit.Test)

Aggregations

Tag (org.eclipse.microprofile.metrics.Tag)36 MetricID (org.eclipse.microprofile.metrics.MetricID)25 Test (org.junit.Test)23 Metadata (org.eclipse.microprofile.metrics.Metadata)12 Counter (org.eclipse.microprofile.metrics.Counter)7 Metric (org.eclipse.microprofile.metrics.Metric)5 Snapshot (org.eclipse.microprofile.metrics.Snapshot)5 Histogram (org.eclipse.microprofile.metrics.Histogram)4 ArrayList (java.util.ArrayList)2 InjectionPoint (javax.enterprise.inject.spi.InjectionPoint)2 JsonObjectBuilder (javax.json.JsonObjectBuilder)2 ConcurrentGauge (org.eclipse.microprofile.metrics.ConcurrentGauge)2 Gauge (org.eclipse.microprofile.metrics.Gauge)2 Meter (org.eclipse.microprofile.metrics.Meter)2 SimpleTimer (org.eclipse.microprofile.metrics.SimpleTimer)2 Timer (org.eclipse.microprofile.metrics.Timer)2 TimerImpl (fish.payara.microprofile.metrics.impl.TimerImpl)1 ExtendedMetadata (io.smallrye.metrics.ExtendedMetadata)1 BigDecimal (java.math.BigDecimal)1 BigInteger (java.math.BigInteger)1