use of org.eclipse.microprofile.metrics.Tag in project wildfly by wildfly.
the class MicroProfileVendorMetricRegistry method registerMetric.
@Override
public void registerMetric(org.wildfly.extension.metrics.Metric metric, MetricMetadata metadata) {
final Metric mpMetric;
if (metadata.getType() == COUNTER) {
mpMetric = new Counter() {
@Override
public void inc() {
}
@Override
public void inc(long n) {
}
@Override
public long getCount() {
OptionalDouble value = metric.getValue();
if (!value.isPresent()) {
// RuntimeException, after logging at DEBUG. That's what we want.
throw LOGGER.metricUnavailable();
}
return (long) value.getAsDouble();
}
};
} else {
mpMetric = new Gauge<Number>() {
@Override
public Double getValue() {
OptionalDouble value = metric.getValue();
if (!value.isPresent()) {
// RuntimeException, after logging at DEBUG. That's what we want.
throw LOGGER.metricUnavailable();
}
return value.getAsDouble();
}
};
}
lock.writeLock().lock();
try {
synchronized (vendorRegistry) {
// TODO does the writeLock eliminate the need for this synchronized?
final Metadata mpMetadata;
Metadata existingMetadata = vendorRegistry.getMetadata().get(metadata.getMetricName());
if (existingMetadata != null) {
mpMetadata = existingMetadata;
} else {
mpMetadata = new ExtendedMetadata(metadata.getMetricName(), metadata.getMetricName(), metadata.getDescription(), metadata.getType() == COUNTER ? MetricType.COUNTER : MetricType.GAUGE, metricUnit(metadata.getMeasurementUnit()), null, false, // so that the name of the metric does not change ("vendor_" will not be prepended to it).
Optional.of(false));
}
Tag[] mpTags = toMicroProfileMetricsTags(metadata.getTags());
vendorRegistry.register(mpMetadata, mpMetric, mpTags);
}
} finally {
lock.writeLock().unlock();
}
}
use of org.eclipse.microprofile.metrics.Tag in project Payara by payara.
the class TestUtils method parseMetricID.
/**
* Parses text form of a {@link MetricID} back to object.
*
* This supports both the result of calling {@link MetricID#toString()} as well as a simplified more user friendly form illustrated in the examples below:
*
* <pre>
* my-metric-name
* my-metric-name[tag=value,tag=value]
* </pre>
*
* @param metric text form of a {@link MetricID}
* @return
*/
public static MetricID parseMetricID(String metric) {
int startOfTags = metric.indexOf('[');
if (startOfTags < 0) {
// no tags, must be simple format
return new MetricID(metric);
}
int endOfTags = metric.indexOf(']');
String[] tagNameValues = metric.substring(startOfTags + 1, endOfTags).split(",");
Tag[] tags = new Tag[tagNameValues.length];
for (int i = 0; i < tagNameValues.length; i++) {
String tag = tagNameValues[i];
int endOfName = tag.indexOf('=');
String value = tag.substring(endOfName + 1);
if (value.startsWith("\"") && value.endsWith("\"")) {
value = value.substring(1, value.length() - 1);
}
tags[i] = new Tag(tag.substring(0, endOfName), value);
}
if (metric.startsWith("MetricID{")) {
int startOfName = metric.indexOf('\'');
return new MetricID(metric.substring(startOfName + 1, metric.indexOf('\'', startOfName + 1)), tags);
}
return new MetricID(metric.substring(0, startOfTags), tags);
}
use of org.eclipse.microprofile.metrics.Tag in project Payara by payara.
the class MethodFaultToleranceMetrics method withMethodTag.
private MetricID withMethodTag(String metric, Tag[] tags) {
Tag method = new Tag("method", canonicalMethodName);
if (tags.length == 0) {
return new MetricID(metric, method);
}
Tag[] newTags = new Tag[tags.length + 1];
newTags[0] = method;
arraycopy(tags, 0, newTags, 1, tags.length);
return new MetricID(metric, newTags);
}
use of org.eclipse.microprofile.metrics.Tag in project Payara by payara.
the class MethodFaultToleranceMetrics method registerPermutations.
private static void registerPermutations(String[][] tags, Consumer<Tag[]> register) {
if (tags.length == 0) {
register.accept(NO_TAGS);
return;
}
if (tags.length == 1) {
String[] tag1 = tags[0];
for (int i = 1; i < tag1.length; i++) {
register.accept(new Tag[] { new Tag(tag1[0], tag1[i]) });
}
return;
}
if (tags.length == 2) {
String[] tag1 = tags[0];
String[] tag2 = tags[1];
for (int i = 1; i < tag1.length; i++) {
for (int j = 1; j < tag2.length; j++) {
register.accept(new Tag[] { new Tag(tag1[0], tag1[i]), new Tag(tag2[0], tag2[j]) });
}
}
return;
}
throw new UnsupportedOperationException("Only 0 to 2 tags supported but got: " + tags.length);
}
use of org.eclipse.microprofile.metrics.Tag in project Payara by payara.
the class BulkheadMetricTckTest method bulkheadMetricHistogramTest.
/**
* Scenario is equivalent to the TCK test of same name but not 100% identical
*/
@Test(timeout = 3000)
public void bulkheadMetricHistogramTest() {
callMethodWithNewThreadAndWaitFor(commonWaiter);
callMethodWithNewThreadAndWaitFor(commonWaiter);
waitUntilPermitsAquired(2, 0);
assertFurtherThreadThrowsBulkheadException(1);
waitSome(100);
commonWaiter.complete(null);
waitUntilPermitsAquired(0, 0);
Histogram executionTimes = registry.getHistogram(new MetricID("ft.bulkhead.runningDuration", new Tag("method", "fish.payara.microprofile.faulttolerance.policy.BulkheadMetricTckTest.bulkheadMetricHistogramTest_Method")));
Snapshot snap = executionTimes.getSnapshot();
assertNotNull(executionTimes);
assertEquals(2, executionTimes.getCount());
assertApproxMillis(100, Math.round(snap.getMedian()));
assertApproxMillis(100, Math.round(snap.getMean()));
// Now let's put some quick results through the bulkhead
callMethodDirectly(null);
callMethodDirectly(null);
assertEquals(4, executionTimes.getCount());
snap = executionTimes.getSnapshot();
assertApproxMillis(50, Math.round(snap.getMean()));
}
Aggregations