use of io.quarkus.smallrye.metrics.deployment.spi.MetricBuildItem in project quarkus by quarkusio.
the class MetricsFromExtensionTestCase method buildCustomizer.
protected static Consumer<BuildChainBuilder> buildCustomizer() {
return new Consumer<BuildChainBuilder>() {
// This represents the extension.
@Override
public void accept(BuildChainBuilder builder) {
builder.addBuildStep(context -> {
BeanArchiveIndexBuildItem indexBuildItem = context.consume(BeanArchiveIndexBuildItem.class);
for (ClassInfo clazz : indexBuildItem.getIndex().getKnownClasses()) {
for (MethodInfo method : clazz.methods()) {
if (method.name().startsWith("countMePlease")) {
Metadata metricMetadata = Metadata.builder().withType(MetricType.COUNTER).withName(clazz.name().toString() + "." + method.name()).build();
MetricBuildItem buildItem = new MetricBuildItem.Builder().metadata(metricMetadata).enabled(true).build();
context.produce(buildItem);
} else if (method.name().startsWith("countMeInBaseScope")) {
Metadata metricMetadata = Metadata.builder().withType(MetricType.COUNTER).withName(clazz.name().toString() + "." + method.name()).build();
MetricBuildItem buildItem = new MetricBuildItem.Builder().metadata(metricMetadata).registryType(MetricRegistry.Type.BASE).enabled(true).build();
context.produce(buildItem);
}
}
}
}).consumes(BeanArchiveIndexBuildItem.class).produces(MetricBuildItem.class).build();
}
};
}
use of io.quarkus.smallrye.metrics.deployment.spi.MetricBuildItem in project quarkus by quarkusio.
the class SmallRyeMetricsProcessor method extensionMetrics.
/**
* Register metrics required by other Quarkus extensions.
*/
@BuildStep
@Record(STATIC_INIT)
void extensionMetrics(SmallRyeMetricsRecorder recorder, List<MetricBuildItem> additionalMetrics, List<MetricsFactoryConsumerBuildItem> metricsFactoryConsumerBuildItems, BuildProducer<UnremovableBeanBuildItem> unremovableBeans) {
if (metrics.extensionsEnabled) {
if (!additionalMetrics.isEmpty()) {
unremovableBeans.produce(new UnremovableBeanBuildItem(new UnremovableBeanBuildItem.BeanClassNameExclusion(MetricRegistry.class.getName())));
unremovableBeans.produce(new UnremovableBeanBuildItem(new UnremovableBeanBuildItem.BeanClassNameExclusion(MetricRegistries.class.getName())));
}
for (MetricBuildItem additionalMetric : additionalMetrics) {
if (additionalMetric.isEnabled()) {
TagHolder[] tags = Arrays.stream(additionalMetric.getTags()).map(TagHolder::from).toArray(TagHolder[]::new);
recorder.registerMetric(additionalMetric.getRegistryType(), MetadataHolder.from(additionalMetric.getMetadata()), tags, additionalMetric.getImplementor());
}
}
for (MetricsFactoryConsumerBuildItem item : metricsFactoryConsumerBuildItems) {
if (item.executionTime() == STATIC_INIT) {
recorder.registerMetrics(item.getConsumer());
}
}
}
}
Aggregations