forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Micrometer + Vert.x 4.0.3 + quarkusio#15734
- Loading branch information
Showing
38 changed files
with
1,358 additions
and
822 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
...deployment/src/main/java/io/quarkus/micrometer/deployment/binder/HttpBinderProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
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.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; | ||
|
||
/** | ||
* 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 = 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()); | ||
} | ||
} |
45 changes: 0 additions & 45 deletions
45
...deployment/src/main/java/io/quarkus/micrometer/deployment/binder/RestClientProcessor.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.