Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Toggle HTTP metrics; Trim URI config patterns; Refactor #15734

Merged
merged 3 commits into from
Mar 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions extensions/micrometer/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-client-deployment</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jackson-deployment</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import java.util.Set;
import java.util.function.BooleanSupplier;

import javax.inject.Singleton;

import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationTarget;
import org.jboss.jandex.ClassInfo;
Expand All @@ -25,7 +23,6 @@
import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
import io.quarkus.arc.deployment.AnnotationsTransformerBuildItem;
import io.quarkus.arc.deployment.BeanContainerBuildItem;
import io.quarkus.arc.deployment.SyntheticBeanBuildItem;
import io.quarkus.arc.deployment.UnremovableBeanBuildItem;
import io.quarkus.arc.processor.AnnotationsTransformer;
import io.quarkus.arc.processor.DotNames;
Expand All @@ -50,11 +47,7 @@
import io.quarkus.micrometer.runtime.MicrometerRecorder;
import io.quarkus.micrometer.runtime.MicrometerTimed;
import io.quarkus.micrometer.runtime.MicrometerTimedInterceptor;
import io.quarkus.micrometer.runtime.binder.HttpBinderConfiguration;
import io.quarkus.micrometer.runtime.config.MicrometerConfig;
import io.quarkus.micrometer.runtime.config.runtime.HttpClientConfig;
import io.quarkus.micrometer.runtime.config.runtime.HttpServerConfig;
import io.quarkus.micrometer.runtime.config.runtime.VertxConfig;
import io.quarkus.runtime.RuntimeValue;
import io.quarkus.runtime.metrics.MetricsFactory;
import io.quarkus.vertx.http.deployment.NonApplicationRootPathBuildItem;
Expand All @@ -72,39 +65,14 @@ public class MicrometerProcessor {
private static final DotName TIMED_BINDING = DotName.createSimple(MicrometerTimed.class.getName());
private static final DotName TIMED_INTERCEPTOR = DotName.createSimple(MicrometerTimedInterceptor.class.getName());

static class MicrometerEnabled implements BooleanSupplier {
public static class MicrometerEnabled implements BooleanSupplier {
MicrometerConfig mConfig;

public boolean getAsBoolean() {
return mConfig.enabled;
}
}

public static class HttpBinderEnabled implements BooleanSupplier {
MicrometerConfig mConfig;

public boolean getAsBoolean() {
return mConfig.checkBinderEnabledWithDefault(mConfig.binder.httpServer) ||
mConfig.checkBinderEnabledWithDefault(mConfig.binder.httpClient);
}
}

public static class HttpServerBinderEnabled implements BooleanSupplier {
MicrometerConfig mConfig;

public boolean getAsBoolean() {
return mConfig.checkBinderEnabledWithDefault(mConfig.binder.httpServer);
}
}

public static class HttpClientBinderEnabled implements BooleanSupplier {
MicrometerConfig mConfig;

public boolean getAsBoolean() {
return mConfig.checkBinderEnabledWithDefault(mConfig.binder.httpClient);
}
}

MicrometerConfig mConfig;

@BuildStep(onlyIf = MicrometerEnabled.class)
Expand Down Expand Up @@ -219,24 +187,6 @@ void processAnnotatedMetrics(BuildProducer<AnnotationsTransformerBuildItem> anno
annotationsTransformers.produce(createAnnotationTransformer(TIMED_ANNOTATION, TIMED_BINDING));
}

@BuildStep(onlyIf = { MicrometerEnabled.class })
@Record(ExecutionTime.RUNTIME_INIT)
SyntheticBeanBuildItem enableHttpBinders(MicrometerRecorder recorder,
HttpServerConfig serverConfig,
HttpClientConfig clientConfig,
VertxConfig vertxConfig) {
return SyntheticBeanBuildItem
.configure(HttpBinderConfiguration.class)
.scope(Singleton.class)
.setRuntimeInit()
.unremovable()
.runtimeValue(recorder.configureHttpMetrics(
mConfig.checkBinderEnabledWithDefault(mConfig.binder.httpServer),
mConfig.checkBinderEnabledWithDefault(mConfig.binder.httpClient),
serverConfig, clientConfig, vertxConfig))
.done();
}

@BuildStep(onlyIf = MicrometerEnabled.class)
@Record(ExecutionTime.STATIC_INIT)
RootMeterRegistryBuildItem createRootRegistry(MicrometerRecorder recorder,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
package io.quarkus.micrometer.deployment.binder;

import java.util.function.BooleanSupplier;

import javax.inject.Singleton;

import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
import io.quarkus.arc.deployment.SyntheticBeanBuildItem;
import io.quarkus.deployment.Capabilities;
import io.quarkus.deployment.Capability;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.annotations.ExecutionTime;
import io.quarkus.deployment.annotations.Record;
import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import io.quarkus.micrometer.deployment.MicrometerProcessor;
import io.quarkus.micrometer.runtime.MicrometerRecorder;
import io.quarkus.micrometer.runtime.binder.HttpBinderConfiguration;
import io.quarkus.micrometer.runtime.binder.vertx.VertxMeterFilter;
import io.quarkus.micrometer.runtime.config.MicrometerConfig;
import io.quarkus.micrometer.runtime.config.runtime.HttpClientConfig;
import io.quarkus.micrometer.runtime.config.runtime.HttpServerConfig;
import io.quarkus.micrometer.runtime.config.runtime.VertxConfig;
import io.quarkus.resteasy.common.spi.ResteasyJaxrsProviderBuildItem;
import io.quarkus.resteasy.reactive.spi.CustomContainerRequestFilterBuildItem;
import io.quarkus.vertx.http.deployment.FilterBuildItem;

/**
* Avoid directly referencing optional dependencies
*/
public class HttpBinderProcessor {
// Common MeterFilter (uri variation limiter)
static final String HTTP_METER_FILTER_CONFIGURATION = "io.quarkus.micrometer.runtime.binder.HttpMeterFilterProvider";

// avoid imports due to related deps not being there
static final String RESTEASY_CONTAINER_FILTER_CLASS_NAME = "io.quarkus.micrometer.runtime.binder.vertx.VertxMeterBinderRestEasyContainerFilter";
static final String QUARKUS_REST_CONTAINER_FILTER_CLASS_NAME = "io.quarkus.micrometer.runtime.binder.vertx.VertxMeterBinderQuarkusRestContainerFilter";

// Rest client listener SPI
private static final String REST_CLIENT_LISTENER_CLASS_NAME = "org.eclipse.microprofile.rest.client.spi.RestClientListener";
private static final Class<?> REST_CLIENT_LISTENER_CLASS = MicrometerRecorder
.getClassForName(REST_CLIENT_LISTENER_CLASS_NAME);

// Rest Client listener
private static final String REST_CLIENT_METRICS_LISTENER = "io.quarkus.micrometer.runtime.binder.RestClientMetricsListener";

static class HttpServerBinderEnabled implements BooleanSupplier {
MicrometerConfig mConfig;

public boolean getAsBoolean() {
return mConfig.checkBinderEnabledWithDefault(mConfig.binder.vertx)
&& mConfig.checkBinderEnabledWithDefault(mConfig.binder.httpServer);
}
}

static class HttpClientBinderEnabled implements BooleanSupplier {
MicrometerConfig mConfig;

public boolean getAsBoolean() {
return REST_CLIENT_LISTENER_CLASS != null
&& mConfig.checkBinderEnabledWithDefault(mConfig.binder.httpClient);
}
}

@BuildStep(onlyIf = { MicrometerProcessor.MicrometerEnabled.class })
@Record(ExecutionTime.RUNTIME_INIT)
SyntheticBeanBuildItem enableHttpBinders(MicrometerRecorder recorder,
MicrometerConfig buildTimeConfig,
HttpServerConfig serverConfig,
HttpClientConfig clientConfig,
VertxConfig vertxConfig,
BuildProducer<AdditionalBeanBuildItem> additionalBeans) {

boolean clientEnabled = buildTimeConfig.checkBinderEnabledWithDefault(buildTimeConfig.binder.httpClient);
boolean serverEnabled = buildTimeConfig.checkBinderEnabledWithDefault(buildTimeConfig.binder.httpServer);

if (clientEnabled || serverEnabled) {
// Protect from uri tag flood
createAdditionalBean(additionalBeans, HTTP_METER_FILTER_CONFIGURATION);
}

// Other things use this bean to test whether or not http server/client metrics are enabled
return SyntheticBeanBuildItem
.configure(HttpBinderConfiguration.class)
.scope(Singleton.class)
.setRuntimeInit()
.unremovable()
.runtimeValue(recorder.configureHttpMetrics(serverEnabled, clientEnabled,
serverConfig, clientConfig, vertxConfig))
.done();
}

@BuildStep(onlyIf = { VertxBinderProcessor.VertxBinderEnabled.class, HttpServerBinderEnabled.class })
FilterBuildItem addVertxMeterFilter() {
return new FilterBuildItem(new VertxMeterFilter(), Integer.MAX_VALUE);
}

@BuildStep(onlyIf = { VertxBinderProcessor.VertxBinderEnabled.class, HttpServerBinderEnabled.class })
void enableHttpServerSupport(Capabilities capabilities,
BuildProducer<ResteasyJaxrsProviderBuildItem> resteasyJaxrsProviders,
BuildProducer<CustomContainerRequestFilterBuildItem> customContainerRequestFilter,
BuildProducer<AdditionalBeanBuildItem> additionalBeans) {

if (capabilities.isPresent(Capability.RESTEASY)) {
resteasyJaxrsProviders.produce(new ResteasyJaxrsProviderBuildItem(RESTEASY_CONTAINER_FILTER_CLASS_NAME));
createAdditionalBean(additionalBeans, RESTEASY_CONTAINER_FILTER_CLASS_NAME);
} else if (capabilities.isPresent(Capability.RESTEASY_REACTIVE)) {
customContainerRequestFilter
.produce(new CustomContainerRequestFilterBuildItem(QUARKUS_REST_CONTAINER_FILTER_CLASS_NAME));
createAdditionalBean(additionalBeans, QUARKUS_REST_CONTAINER_FILTER_CLASS_NAME);
}
}

@BuildStep(onlyIf = { HttpClientBinderEnabled.class })
void registerRestClientListener(BuildProducer<NativeImageResourceBuildItem> resource,
BuildProducer<ReflectiveClassBuildItem> reflectiveClass) {
resource.produce(new NativeImageResourceBuildItem(
"META-INF/services/org.eclipse.microprofile.rest.client.spi.RestClientListener"));
reflectiveClass
.produce(new ReflectiveClassBuildItem(true, true, REST_CLIENT_METRICS_LISTENER));
}

private void createAdditionalBean(BuildProducer<AdditionalBeanBuildItem> additionalBeans, String className) {
additionalBeans.produce(AdditionalBeanBuildItem.builder()
.addBeanClass(className)
.setUnremovable().build());
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,20 @@

import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
import io.quarkus.arc.deployment.SyntheticBeansRuntimeInitBuildItem;
import io.quarkus.deployment.Capabilities;
import io.quarkus.deployment.Capability;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.annotations.Consume;
import io.quarkus.deployment.annotations.ExecutionTime;
import io.quarkus.deployment.annotations.Record;
import io.quarkus.micrometer.deployment.MicrometerProcessor;
import io.quarkus.micrometer.runtime.MicrometerRecorder;
import io.quarkus.micrometer.runtime.binder.vertx.VertxMeterBinderAdapter;
import io.quarkus.micrometer.runtime.binder.vertx.VertxMeterBinderRecorder;
import io.quarkus.micrometer.runtime.binder.vertx.VertxMeterFilter;
import io.quarkus.micrometer.runtime.config.MicrometerConfig;
import io.quarkus.micrometer.runtime.config.runtime.VertxConfig;
import io.quarkus.resteasy.common.spi.ResteasyJaxrsProviderBuildItem;
import io.quarkus.resteasy.reactive.spi.CustomContainerRequestFilterBuildItem;
import io.quarkus.vertx.core.deployment.VertxOptionsConsumerBuildItem;
import io.quarkus.vertx.http.deployment.FilterBuildItem;

/**
* Add support for the Vert.x and other http instrumentation.
* Note that various bits of support may not be present at deploy time,
* e.g. Vert.x can be present while resteasy is not.
* Add support for Vert.x instrumentation.
* HTTP instrumentation is dependent on Vert.x, but has been pulled out into its own processor
*
* Avoid referencing classes that in turn import optional dependencies.
*/
Expand All @@ -44,32 +35,6 @@ public boolean getAsBoolean() {
}
}

// avoid imports due to related deps not being there
static final String RESTEASY_CONTAINER_FILTER_CLASS_NAME = "io.quarkus.micrometer.runtime.binder.vertx.VertxMeterBinderRestEasyContainerFilter";
static final String QUARKUS_REST_CONTAINER_FILTER_CLASS_NAME = "io.quarkus.micrometer.runtime.binder.vertx.VertxMeterBinderQuarkusRestContainerFilter";

@BuildStep(onlyIf = { VertxBinderEnabled.class, MicrometerProcessor.HttpServerBinderEnabled.class })
void enableJaxRsSupport(Capabilities capabilities,
BuildProducer<ResteasyJaxrsProviderBuildItem> resteasyJaxrsProviders,
BuildProducer<CustomContainerRequestFilterBuildItem> customContainerRequestFilter,
BuildProducer<AdditionalBeanBuildItem> additionalBeans) {

if (capabilities.isPresent(Capability.RESTEASY)) {
resteasyJaxrsProviders.produce(new ResteasyJaxrsProviderBuildItem(RESTEASY_CONTAINER_FILTER_CLASS_NAME));
turnVertxBinderFilterIntoBean(additionalBeans, RESTEASY_CONTAINER_FILTER_CLASS_NAME);
} else if (capabilities.isPresent(Capability.RESTEASY_REACTIVE)) {
customContainerRequestFilter
.produce(new CustomContainerRequestFilterBuildItem(QUARKUS_REST_CONTAINER_FILTER_CLASS_NAME));
turnVertxBinderFilterIntoBean(additionalBeans, QUARKUS_REST_CONTAINER_FILTER_CLASS_NAME);
}
}

private void turnVertxBinderFilterIntoBean(BuildProducer<AdditionalBeanBuildItem> additionalBeans, String className) {
additionalBeans.produce(AdditionalBeanBuildItem.builder()
.addBeanClass(className)
.setUnremovable().build());
}

@BuildStep(onlyIf = VertxBinderEnabled.class)
AdditionalBeanBuildItem createVertxAdapters() {
// Add Vertx meter adapters
Expand All @@ -78,11 +43,6 @@ AdditionalBeanBuildItem createVertxAdapters() {
.setUnremovable().build();
}

@BuildStep(onlyIf = { VertxBinderEnabled.class, MicrometerProcessor.HttpServerBinderEnabled.class })
FilterBuildItem addVertxMeterFilter() {
return new FilterBuildItem(new VertxMeterFilter(), Integer.MAX_VALUE);
}

@BuildStep(onlyIf = VertxBinderEnabled.class)
@Record(value = ExecutionTime.STATIC_INIT)
VertxOptionsConsumerBuildItem build(VertxMeterBinderRecorder recorder) {
Expand Down
Loading