Search in sources :

Example 31 with MetricID

use of org.eclipse.microprofile.metrics.MetricID in project Payara by payara.

the class OpenMetricsExporterTest method eachTypeAndHelpLineOccursOnlyOnceForEachOpenMetricsName.

/*
     * Below tests are no examples from the specification
     */
@Test
public void eachTypeAndHelpLineOccursOnlyOnceForEachOpenMetricsName() {
    Gauge<Long> g1 = () -> 1L;
    MetricID g1ID = new MetricID("common", new Tag("a", "b"));
    Gauge<Long> g2 = () -> 2L;
    MetricID g2ID = new MetricID("common", new Tag("some", "other"));
    Metadata metadata = Metadata.builder().withName("common").withDescription("description").build();
    exporter.export(g1ID, g1, metadata);
    exporter.export(g2ID, g2, metadata);
    assertEquals("# TYPE application_common gauge\n" + "# HELP application_common description\n" + "application_common{a=\"b\"} 1\n" + "application_common{some=\"other\"} 2\n", actual.getBuffer().toString());
}
Also used : MetricID(org.eclipse.microprofile.metrics.MetricID) Metadata(org.eclipse.microprofile.metrics.Metadata) Tag(org.eclipse.microprofile.metrics.Tag) Test(org.junit.Test)

Example 32 with MetricID

use of org.eclipse.microprofile.metrics.MetricID in project Payara by payara.

the class OpenMetricsExporterTest method gaugesWithNonNumberValuesAreNotExported.

@Test
public void gaugesWithNonNumberValuesAreNotExported() {
    Gauge<String> gauge = () -> "hello world";
    MetricID metricID = new MetricID("test3");
    Metadata metadata = Metadata.builder().withName(metricID.getName()).build();
    assertOutputEquals("", metricID, gauge, metadata);
}
Also used : MetricID(org.eclipse.microprofile.metrics.MetricID) Metadata(org.eclipse.microprofile.metrics.Metadata) Test(org.junit.Test)

Example 33 with MetricID

use of org.eclipse.microprofile.metrics.MetricID in project Payara by payara.

the class OpenMetricsExporterTest method exportTags.

@Test
@SuppressWarnings("unchecked")
public void exportTags() {
    Gauge<Long> fooVal = mock(Gauge.class);
    when(fooVal.getValue()).thenReturn(12345L);
    MetricID fooValID = new MetricID("fooVal", new Tag("store", "webshop"));
    Metadata fooValMetadata = Metadata.builder().withName(fooValID.getName()).withDescription("The average duration of foo requests during last 5 minutes").withUnit(MetricUnits.MILLISECONDS).build();
    MetricExporter base = exporter.in(Type.BASE);
    base.export(fooValID, fooVal, fooValMetadata);
    Gauge<Long> barVal = mock(Gauge.class);
    when(barVal.getValue()).thenReturn(42L);
    MetricID barValID = new MetricID("barVal", new Tag("component", "backend"), new Tag("store", "webshop"));
    Metadata barValMetadata = Metadata.builder().withName(barValID.getName()).withUnit(MetricUnits.KILOBYTES).build();
    base.export(barValID, barVal, barValMetadata);
    Gauge<Long> barVal2 = mock(Gauge.class);
    when(barVal2.getValue()).thenReturn(63L);
    MetricID barVal2ID = new MetricID("barVal", new Tag("component", "frontend"), new Tag("store", "webshop"));
    base.export(barVal2ID, barVal2, barValMetadata);
    assertOutputEqualsFile("GaugeTags.txt");
}
Also used : MetricID(org.eclipse.microprofile.metrics.MetricID) Metadata(org.eclipse.microprofile.metrics.Metadata) Tag(org.eclipse.microprofile.metrics.Tag) Test(org.junit.Test)

Example 34 with MetricID

use of org.eclipse.microprofile.metrics.MetricID in project Payara by payara.

the class OpenMetricsExporterTest method exportGauge.

@Test
public void exportGauge() {
    @SuppressWarnings("unchecked") Gauge<Long> gauge = mock(Gauge.class);
    when(gauge.getValue()).thenReturn(80L);
    MetricID metricID = new MetricID("cost");
    Metadata metadata = Metadata.builder().withName(metricID.getName()).withDescription("The running cost of the server in dollars.").withUnit("dollars").build();
    assertOutputEqualsFile("Gauge.txt", metricID, gauge, metadata);
}
Also used : MetricID(org.eclipse.microprofile.metrics.MetricID) Metadata(org.eclipse.microprofile.metrics.Metadata) Test(org.junit.Test)

Example 35 with MetricID

use of org.eclipse.microprofile.metrics.MetricID in project Payara by payara.

the class AnnotationReaderGetOrRegisterTest method assertGetsOrRegisters.

private <T extends Metric, A extends Annotation> void assertGetsOrRegisters(AnnotationReader<A> reader, Class<T> metric, int expectedTags) {
    InjectionPoint point = testMethodAsInjectionPoint();
    T c1 = reader.getOrRegister(point, metric, registry);
    assertNotNull(c1);
    T c2 = reader.getOrRegister(point, metric, registry);
    assertNotNull(c2);
    assertSame(c1, c2);
    Set<MetricID> metricIDs = registry.getMetricIDs();
    assertEquals(1, metricIDs.size());
    MetricID metricID = metricIDs.iterator().next();
    assertEquals(expectedTags, metricID.getTagsAsArray().length);
    if (expectedTags == 2) {
        assertArrayEquals(new Tag[] { new Tag("a", "b"), new Tag("c", "d") }, metricID.getTagsAsArray());
    }
    Metadata metadata = registry.getMetadata(metricID.getName());
    assertNotNull(metadata);
    A annotation = null;
    try {
        annotation = reader.annotation(point);
    } catch (IllegalArgumentException ex) {
        // with no annotation, done
        return;
    }
    assertEquals(reader.type(), metadata.getTypeRaw());
    String displayName = reader.displayName(annotation);
    if (displayName.isEmpty()) {
        assertEquals(metricID.getName(), metadata.getDisplayName());
    } else {
        assertEquals(displayName, metadata.getDisplayName());
    }
    String description = reader.description(annotation);
    if (description.isEmpty()) {
        assertFalse(metadata.description().isPresent());
    } else {
        assertEquals(description, metadata.getDescription());
    }
    String unit = reader.unit(annotation);
    if (unit.isEmpty()) {
        assertFalse(metadata.unit().isPresent());
    } else {
        assertEquals(unit, metadata.getUnit());
    }
}
Also used : MetricID(org.eclipse.microprofile.metrics.MetricID) InjectionPoint(javax.enterprise.inject.spi.InjectionPoint) Metadata(org.eclipse.microprofile.metrics.Metadata) Tag(org.eclipse.microprofile.metrics.Tag)

Aggregations

MetricID (org.eclipse.microprofile.metrics.MetricID)53 Test (org.junit.Test)41 Metadata (org.eclipse.microprofile.metrics.Metadata)31 Tag (org.eclipse.microprofile.metrics.Tag)25 Counter (org.eclipse.microprofile.metrics.Counter)10 Metric (org.eclipse.microprofile.metrics.Metric)6 SimpleTimer (org.eclipse.microprofile.metrics.SimpleTimer)6 Snapshot (org.eclipse.microprofile.metrics.Snapshot)6 Histogram (org.eclipse.microprofile.metrics.Histogram)5 ConcurrentGauge (org.eclipse.microprofile.metrics.ConcurrentGauge)4 Timer (org.eclipse.microprofile.metrics.Timer)4 Gauge (org.eclipse.microprofile.metrics.Gauge)3 MonitoringDataCollector (fish.payara.monitoring.collect.MonitoringDataCollector)2 ArrayList (java.util.ArrayList)2 Meter (org.eclipse.microprofile.metrics.Meter)2 NoSuchRegistryException (fish.payara.microprofile.metrics.exception.NoSuchRegistryException)1 TimerImpl (fish.payara.microprofile.metrics.impl.TimerImpl)1 MBeanMetadata (fish.payara.microprofile.metrics.jmx.MBeanMetadata)1 FileNotFoundException (java.io.FileNotFoundException)1 Collections.emptyMap (java.util.Collections.emptyMap)1