use of org.eclipse.microprofile.metrics.MetricID 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.MetricID 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.MetricID 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()));
}
use of org.eclipse.microprofile.metrics.MetricID in project Payara by payara.
the class AbstractInterceptor method apply.
protected static <E extends Member & AnnotatedElement, M extends Metric> M apply(E element, Class<?> bean, AnnotationReader<?> reader, Class<M> metricType, BiFunction<MetricID, Class<M>, M> loader) {
MetricID metricID = reader.metricID(bean, element);
M metric = loader.apply(metricID, metricType);
if (metric == null) {
throw new IllegalStateException("No " + metricType.getSimpleName() + " with ID [" + metricID + "] found in application registry");
}
return metric;
}
use of org.eclipse.microprofile.metrics.MetricID in project Payara by payara.
the class MetricsServiceImpl method processMetadataToAnnotations.
private static void processMetadataToAnnotations(MetricsContextImpl context, MonitoringDataCollector collector) {
RegisteredMetric metric = context.pollNewlyRegistered();
while (metric != null) {
MetricID metricID = metric.id;
Type scope = metric.scope;
MetricRegistry registry = context.getRegistry(scope);
MonitoringDataCollector metricCollector = tagCollector(context.getName(), metricID, collector);
Metadata metadata = registry.getMetadata(metricID.getName());
String suffix = "Count";
String property = "Count";
boolean isGauge = metadata.getTypeRaw() == MetricType.GAUGE;
if (isGauge) {
suffix = getMetricUnitSuffix(metadata.unit());
property = "Value";
}
// Note that by convention an annotation with value 0 done before the series collected any value is considered permanent
metricCollector.annotate(toName(metricID, suffix), 0, false, metadataToAnnotations(context.getName(), scope, metadata, property));
metric = context.pollNewlyRegistered();
}
}
Aggregations