Search in sources :

Example 1 with MetricBuildItem

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();
        }
    };
}
Also used : Metadata(org.eclipse.microprofile.metrics.Metadata) MetricType(org.eclipse.microprofile.metrics.MetricType) Matchers(org.hamcrest.Matchers) ClassInfo(org.jboss.jandex.ClassInfo) QuarkusUnitTest(io.quarkus.test.QuarkusUnitTest) Consumer(java.util.function.Consumer) Test(org.junit.jupiter.api.Test) MethodInfo(org.jboss.jandex.MethodInfo) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) BuildChainBuilder(io.quarkus.builder.BuildChainBuilder) MetricBuildItem(io.quarkus.smallrye.metrics.deployment.spi.MetricBuildItem) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) MetricRegistry(org.eclipse.microprofile.metrics.MetricRegistry) BeanArchiveIndexBuildItem(io.quarkus.arc.deployment.BeanArchiveIndexBuildItem) RestAssured(io.restassured.RestAssured) Consumer(java.util.function.Consumer) BuildChainBuilder(io.quarkus.builder.BuildChainBuilder) BuildChainBuilder(io.quarkus.builder.BuildChainBuilder) Metadata(org.eclipse.microprofile.metrics.Metadata) MethodInfo(org.jboss.jandex.MethodInfo) MetricBuildItem(io.quarkus.smallrye.metrics.deployment.spi.MetricBuildItem) BeanArchiveIndexBuildItem(io.quarkus.arc.deployment.BeanArchiveIndexBuildItem) ClassInfo(org.jboss.jandex.ClassInfo)

Example 2 with MetricBuildItem

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());
            }
        }
    }
}
Also used : MetricRegistries(io.smallrye.metrics.MetricRegistries) MetricsFactoryConsumerBuildItem(io.quarkus.deployment.metrics.MetricsFactoryConsumerBuildItem) TagHolder(io.quarkus.smallrye.metrics.runtime.TagHolder) MetricRegistry(org.eclipse.microprofile.metrics.MetricRegistry) UnremovableBeanBuildItem(io.quarkus.arc.deployment.UnremovableBeanBuildItem) MetricBuildItem(io.quarkus.smallrye.metrics.deployment.spi.MetricBuildItem) BuildStep(io.quarkus.deployment.annotations.BuildStep) Record(io.quarkus.deployment.annotations.Record)

Aggregations

MetricBuildItem (io.quarkus.smallrye.metrics.deployment.spi.MetricBuildItem)2 MetricRegistry (org.eclipse.microprofile.metrics.MetricRegistry)2 BeanArchiveIndexBuildItem (io.quarkus.arc.deployment.BeanArchiveIndexBuildItem)1 UnremovableBeanBuildItem (io.quarkus.arc.deployment.UnremovableBeanBuildItem)1 BuildChainBuilder (io.quarkus.builder.BuildChainBuilder)1 BuildStep (io.quarkus.deployment.annotations.BuildStep)1 Record (io.quarkus.deployment.annotations.Record)1 MetricsFactoryConsumerBuildItem (io.quarkus.deployment.metrics.MetricsFactoryConsumerBuildItem)1 TagHolder (io.quarkus.smallrye.metrics.runtime.TagHolder)1 QuarkusUnitTest (io.quarkus.test.QuarkusUnitTest)1 RestAssured (io.restassured.RestAssured)1 MetricRegistries (io.smallrye.metrics.MetricRegistries)1 Consumer (java.util.function.Consumer)1 Metadata (org.eclipse.microprofile.metrics.Metadata)1 MetricType (org.eclipse.microprofile.metrics.MetricType)1 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)1 Matchers (org.hamcrest.Matchers)1 ClassInfo (org.jboss.jandex.ClassInfo)1 MethodInfo (org.jboss.jandex.MethodInfo)1 Test (org.junit.jupiter.api.Test)1