use of org.eclipse.microprofile.metrics.Tag in project Payara by payara.
the class JsonExporterGetTest method exportConcurrentGauge.
@Test
public void exportConcurrentGauge() {
ConcurrentGauge callCount = mock(ConcurrentGauge.class);
when(callCount.getCount()).thenReturn(48L);
when(callCount.getMin()).thenReturn(4L);
when(callCount.getMax()).thenReturn(50L);
ConcurrentGauge callCount2 = mock(ConcurrentGauge.class);
when(callCount2.getCount()).thenReturn(23L);
when(callCount2.getMin()).thenReturn(1L);
when(callCount2.getMax()).thenReturn(29L);
export(new MetricID("callCount"), callCount);
export(new MetricID("callCount", new Tag("component", "backend")), callCount2);
assertOutputEqualsFile("ConcurrentGauge.json");
}
use of org.eclipse.microprofile.metrics.Tag in project Payara by payara.
the class JsonExporterGetTest method exportMeter.
@Test
public void exportMeter() {
Meter requests = mock(Meter.class);
when(requests.getCount()).thenReturn(29382L);
when(requests.getMeanRate()).thenReturn(12.223d);
when(requests.getOneMinuteRate()).thenReturn(12.563d);
when(requests.getFiveMinuteRate()).thenReturn(12.364d);
when(requests.getFifteenMinuteRate()).thenReturn(12.126d);
// example uses same values for all three meters so we can get away with just one
// but conceptually those should be three different meter instances
export(new MetricID("requests"), requests);
export(new MetricID("requests", new Tag("servlet", "one")), requests);
export(new MetricID("requests", new Tag("servlet", "two")), requests);
assertOutputEqualsFile("Meter.json");
}
use of org.eclipse.microprofile.metrics.Tag in project Payara by payara.
the class OpenMetricsExporterTest method quantilesAreAppendedOtherTags.
@Test
public void quantilesAreAppendedOtherTags() {
Histogram histogram = mock(Histogram.class);
Snapshot snapshot = mock(Snapshot.class);
when(histogram.getSnapshot()).thenReturn(snapshot);
MetricID metricID = new MetricID("test6", new Tag("custom", "tag-value"));
Metadata metadata = Metadata.builder().withName(metricID.getName()).withUnit(MetricUnits.MILLISECONDS).build();
exporter.export(metricID, histogram, metadata);
String actualOutput = actual.getBuffer().toString();
assertTrue(actualOutput.contains("application_test6_seconds{custom=\"tag-value\",quantile=\"0.5\"} 0"));
}
use of org.eclipse.microprofile.metrics.Tag in project Payara by payara.
the class MetricRegistryImplTest method registerByMetadataAcceptsInstancesWithSameNameButDifferentTags.
@Test
public void registerByMetadataAcceptsInstancesWithSameNameButDifferentTags() {
EnumSet<MetricType> types = EnumSet.allOf(MetricType.class);
// obviously
types.remove(MetricType.INVALID);
// gauges cannot be created
types.remove(MetricType.GAUGE);
for (MetricType type : types) {
String name = nextName();
for (int i = 0; i < 10; i++) {
final int n = i;
MetadataBuilder metadata = withNameAnd(name).withType(type);
Runnable register = () -> registry.register(metadata.build(), null, new Tag("a", "b" + n));
// first time should work
register.run();
// works again as all metrics are reusable
register.run();
}
}
}
use of org.eclipse.microprofile.metrics.Tag in project Payara by payara.
the class MetricRegistryImplTest method registerByMetadataAllowsToRegisterMetricsOfSameNameWithDifferentTagsButSameType.
@Test
public void registerByMetadataAllowsToRegisterMetricsOfSameNameWithDifferentTagsButSameType() {
String name = nextName();
Tag ab = new Tag("a", "b");
Tag ac = new Tag("a", "c");
MetricID metricAb = new MetricID(name, ab);
MetricID metricAc = new MetricID(name, ac);
registry.register(withName(name), new TimerImpl(), ab);
registry.register(withName(name), new TimerImpl(), ac);
assertEquals(2, registry.getTimers().size());
Map<MetricID, Metric> metrics = registry.getMetrics((metricID, metric) -> metricID.getName().equals(name));
assertEquals(2, metrics.size());
assertTrue(metrics.containsKey(metricAb));
assertTrue(metrics.containsKey(metricAc));
assertEquals(new TreeSet<>(asList(metricAb, metricAc)), registry.getMetricIDs());
assertEquals(new TreeSet<>(asList(name)), registry.getNames());
assertEquals(1, registry.getTimers((id, metric) -> id.equals(metricAc)).size());
}
Aggregations