use of org.eclipse.microprofile.metrics.Metadata in project Payara by payara.
the class AnnotationReaderGetOrRegisterTest method gaugeFromMetdadata.
@Test
@Gauge(tags = { "a=b", "c=d" }, unit = MetricUnits.HOURS, description = "description")
public void gaugeFromMetdadata() {
Metadata annoated = AnnotationReader.GAUGE.metadata(getClass(), TestUtils.getTestMethod());
String name = getClass().getCanonicalName() + ".gaugeFromMetdadata";
Metadata expected = Metadata.builder(annoated).withName(name).build();
org.eclipse.microprofile.metrics.Gauge<Long> gauge = () -> 1L;
registry.register(expected, gauge, new Tag("a", "b"), new Tag("c", "d"));
InjectionPoint point = testMethodAsInjectionPoint();
org.eclipse.microprofile.metrics.Gauge<?> gauge2 = AnnotationReader.GAUGE.getOrRegister(point, org.eclipse.microprofile.metrics.Gauge.class, registry);
assertNotNull(gauge2);
assertSame(gauge, gauge2);
}
use of org.eclipse.microprofile.metrics.Metadata in project Payara by payara.
the class JsonExporterOptionsTest method singleMetricOption.
@Test
public void singleMetricOption() {
Gauge<Long> fooVal = () -> 1L;
MetricID fooValID = new MetricID("fooVal", new Tag("store", "webshop"));
Metadata fooValMeta = Metadata.builder().withName("fooVal").withDescription("The size of foo after each request").withUnit(MetricUnits.MILLISECONDS).withDisplayName("Size of foo").withType(MetricType.GAUGE).build();
export(fooValID, fooVal, fooValMeta);
assertOutputEqualsFile("Options1.json");
}
use of org.eclipse.microprofile.metrics.Metadata in project Payara by payara.
the class JsonExporterOptionsTest method gaugesWithNonNumberValuesDoExportMetadata.
@Test
public void gaugesWithNonNumberValuesDoExportMetadata() {
Gauge<String> gauge = () -> "hello world";
MetricID metricID = new MetricID("test3");
Metadata metadata = Metadata.builder().withName(metricID.getName()).withType(MetricType.GAUGE).build();
assertOutputEquals("\n" + "{\n" + " \"test3\": {\n" + " \"unit\": \"none\",\n" + " \"type\": \"gauge\"\n" + " }\n" + "}", metricID, gauge, metadata);
}
use of org.eclipse.microprofile.metrics.Metadata in project Payara by payara.
the class MetricRegistryImpl method findMetricOrCreate.
private <T extends Metric> T findMetricOrCreate(String name, MetricType metricType, T metric, Tag... tags) {
checkNameIsNotNullOrEmpty(name);
Metadata metadata = Metadata.builder().withName(name).withType(metricType).withDisplayName("").build();
return findMetricOrCreate(metadata, true, metric, tags);
}
use of org.eclipse.microprofile.metrics.Metadata in project wildfly-swarm by wildfly-swarm.
the class MetricsInterceptor method metrics.
@AroundConstruct
private Object metrics(InvocationContext context) throws Exception {
Class<?> bean = context.getConstructor().getDeclaringClass();
LOGGER.infof("MetricsInterceptor, bean=%s\n", bean);
// Registers the bean constructor metrics
registerMetrics(bean, context.getConstructor());
// Registers the methods metrics over the bean type hierarchy
Class<?> type = bean;
do {
// TODO: discover annotations declared on implemented interfaces
for (Method method : type.getDeclaredMethods()) {
if (!method.isSynthetic() && !Modifier.isPrivate(method.getModifiers())) {
registerMetrics(bean, method);
}
}
type = type.getSuperclass();
} while (!Object.class.equals(type));
Object target = context.proceed();
// Registers the gauges over the bean type hierarchy after the target is constructed as it is required for the gauge invocations
type = bean;
do {
// TODO: discover annotations declared on implemented interfaces
for (Method method : type.getDeclaredMethods()) {
MetricResolver.Of<Gauge> gauge = resolver.gauge(bean, method);
if (gauge.isPresent()) {
Gauge g = gauge.metricAnnotation();
Metadata metadata = getMetadata(gauge.metricName(), g.unit(), g.description(), g.displayName(), MetricType.GAUGE, g.tags());
registry.register(metadata, new ForwardingGauge(method, context.getTarget()));
}
}
type = type.getSuperclass();
} while (!Object.class.equals(type));
return target;
}
Aggregations