Search in sources :

Example 51 with Metadata

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

the class MetricRegistryImplTest method counterByMetadataReceivesExistingCounter.

@Test
public void counterByMetadataReceivesExistingCounter() {
    String name = nextName();
    Metadata metadata = withNameAnd(name).withType(MetricType.COUNTER).build();
    Counter counter = registry.counter(metadata);
    assertSame(counter, registry.counter(metadata));
    assertNotSame(counter, registry.counter(metadata, SOME_TAG));
}
Also used : Counter(org.eclipse.microprofile.metrics.Counter) Metadata(org.eclipse.microprofile.metrics.Metadata) Test(org.junit.Test)

Example 52 with Metadata

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

the class MetricRegistryImplTest method counterByMetadataCreatesNonExistingCounter.

@Test
public void counterByMetadataCreatesNonExistingCounter() {
    String name = nextName();
    Metadata metadata = withNameAnd(name).withType(MetricType.COUNTER).build();
    Counter counter = registry.counter(metadata);
    assertNotNull(counter);
    Metadata actualMetadata = registry.getMetadata(name);
    assertEquals(name, actualMetadata.getName());
    assertEquals(MetricType.COUNTER, actualMetadata.getTypeRaw());
    assertEquals(metadata, actualMetadata);
}
Also used : Counter(org.eclipse.microprofile.metrics.Counter) Metadata(org.eclipse.microprofile.metrics.Metadata) Test(org.junit.Test)

Example 53 with Metadata

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

the class MetricRegistryImplTest method counterByNameCreatesNonExistingCounter.

@Test
public void counterByNameCreatesNonExistingCounter() {
    String name = nextName();
    Counter counter = registry.counter(name);
    assertNotNull(counter);
    Metadata metadata = registry.getMetadata(name);
    assertEquals(name, metadata.getName());
    assertEquals(name, metadata.getDisplayName());
    assertEquals(MetricType.COUNTER, metadata.getTypeRaw());
}
Also used : Counter(org.eclipse.microprofile.metrics.Counter) Metadata(org.eclipse.microprofile.metrics.Metadata) Test(org.junit.Test)

Example 54 with Metadata

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

the class JsonExporterOptionsTest method gaugesThatThrowIllegalStateExceptionWhenReadDoExportMetadata.

@Test
public void gaugesThatThrowIllegalStateExceptionWhenReadDoExportMetadata() {
    Gauge<Long> gauge = () -> {
        throw new IllegalStateException("test");
    };
    MetricID metricID = new MetricID("test4");
    Metadata metadata = Metadata.builder().withName(metricID.getName()).withType(MetricType.GAUGE).build();
    assertOutputEquals("\n" + "{\n" + "    \"test4\": {\n" + "        \"unit\": \"none\",\n" + "        \"type\": \"gauge\"\n" + "    }\n" + "}", metricID, gauge, metadata);
}
Also used : MetricID(org.eclipse.microprofile.metrics.MetricID) Metadata(org.eclipse.microprofile.metrics.Metadata) Test(org.junit.Test)

Example 55 with Metadata

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

the class JsonExporterOptionsTest method multipleMetricOptionsAreGroupedByName.

@Test
public void multipleMetricOptionsAreGroupedByName() {
    Gauge<Long> fooVal = () -> 1L;
    MetricID fooValID = new MetricID("fooVal", new Tag("store", "webshop"));
    Metadata fooValMeta = Metadata.builder().withName("fooVal").withDescription("The average duration of foo requests during last 5 minutes").withUnit(MetricUnits.MILLISECONDS).withDisplayName("Duration of foo").withType(MetricType.GAUGE).build();
    Gauge<Long> barVal1 = () -> 2L;
    Gauge<Long> barVal2 = () -> 3L;
    MetricID barValID1 = new MetricID("barVal", new Tag("store", "webshop"), new Tag("component", "backend"));
    MetricID barValID2 = new MetricID("barVal", new Tag("store", "webshop"), new Tag("component", "frontend"));
    Metadata barValMeta = Metadata.builder().withName("barVal").withUnit(MetricUnits.MEGABYTES).withType(MetricType.GAUGE).build();
    export(fooValID, fooVal, fooValMeta);
    export(barValID1, barVal1, barValMeta);
    export(barValID2, barVal2, barValMeta);
    assertOutputEqualsFile("Options2.json");
}
Also used : MetricID(org.eclipse.microprofile.metrics.MetricID) Metadata(org.eclipse.microprofile.metrics.Metadata) Tag(org.eclipse.microprofile.metrics.Tag) Test(org.junit.Test)

Aggregations

Metadata (org.eclipse.microprofile.metrics.Metadata)65 MetricID (org.eclipse.microprofile.metrics.MetricID)31 Test (org.junit.Test)30 Tag (org.eclipse.microprofile.metrics.Tag)12 Counter (org.eclipse.microprofile.metrics.Counter)9 Metric (org.eclipse.microprofile.metrics.Metric)9 MetricRegistry (org.eclipse.microprofile.metrics.MetricRegistry)8 HashMap (java.util.HashMap)6 Map (java.util.Map)4 Histogram (org.eclipse.microprofile.metrics.Histogram)4 ArrayList (java.util.ArrayList)3 Meter (org.eclipse.microprofile.metrics.Meter)3 Gauge (org.eclipse.microprofile.metrics.annotation.Gauge)3 ObjectName (javax.management.ObjectName)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Gauge (org.eclipse.microprofile.metrics.Gauge)2 MetricType (org.eclipse.microprofile.metrics.MetricType)2 SimpleTimer (org.eclipse.microprofile.metrics.SimpleTimer)2 Snapshot (org.eclipse.microprofile.metrics.Snapshot)2