Skip to content

Commit

Permalink
[#3166] Use Quarkus Micrometer extension
Browse files Browse the repository at this point in the history
Replaced the VertxBasedHealthCheckServer with an adapter that bridges
the existing checks that are registered via the HealthCheckProvider
interface to the Microprofile Health based Quarkus SmallRye Health
extension's health check endpoints.

Fixes #3166

Signed-off-by: Kai Hudalla <kai.hudalla@bosch.io>
  • Loading branch information
sophokles73 committed Apr 1, 2022
1 parent bf3d850 commit 82cd6df
Show file tree
Hide file tree
Showing 66 changed files with 719 additions and 1,014 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executors;

import javax.inject.Inject;
Expand Down Expand Up @@ -118,15 +117,27 @@ public abstract class AbstractProtocolAdapterApplication<C extends ProtocolAdapt

private static final Logger LOG = LoggerFactory.getLogger(AbstractProtocolAdapterApplication.class);

/**
* The OpenTracing tracer to use.
*/
@Inject
protected Tracer tracer;

/**
* The factory for creating samplers for tracking the sending of AMQP messages.
*/
@Inject
protected SendMessageSampler.Factory messageSamplerFactory;

/**
* The adapter's configuration properties.
*/
@Inject
protected C protocolAdapterProperties;

/**
* The configuration to use for Kafka client metrics.
*/
@Inject
protected KafkaMetricsOptions kafkaMetricsOptions;

Expand Down Expand Up @@ -286,8 +297,6 @@ protected void doStart() {

LOG.info("deploying {} {} instances ...", appConfig.getMaxInstances(), getComponentName());

final CompletableFuture<Void> startup = new CompletableFuture<>();

final Future<String> adapterTracker = vertx.deployVerticle(
this::adapter,
new DeploymentOptions().setInstances(appConfig.getMaxInstances()));
Expand All @@ -296,11 +305,8 @@ protected void doStart() {
new WrappedLifecycleComponentVerticle(notificationReceiver()));

CompositeFuture.all(adapterTracker, notificationReceiverTracker)
.compose(s -> healthCheckServer.start())
.onSuccess(ok -> startup.complete(null))
.onFailure(startup::completeExceptionally);
startup.join();

.mapEmpty()
.onComplete(deploymentCheck);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion adapters/amqp-vertx-quarkus/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<ports>
<port>8080</port>
<port>8443</port>
<port>${vertx.health.port}</port>
<port>${health.check.port}</port>
</ports>
</build>
</image>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.eclipse.hono.util.Constants;

import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.config.MeterFilter;
import io.vertx.core.Vertx;

/**
Expand All @@ -37,14 +38,18 @@ AmqpAdapterProperties adapterProperties(final AmqpAdapterOptions adapterOptions)
return new AmqpAdapterProperties(adapterOptions);
}

@Produces
@Singleton
MeterFilter commonTags() {
return MeterFilter.commonTags(MetricsTags.forProtocolAdapter(Constants.PROTOCOL_ADAPTER_TYPE_AMQP));
}

@Singleton
@Produces
MicrometerBasedAmqpAdapterMetrics metrics(
final Vertx vertx,
final MeterRegistry registry,
final AmqpAdapterProperties adapterProperties) {
// define tags before the first metric gets created in the MicrometerBasedAmqpAdapterMetrics constructor
registry.config().commonTags(MetricsTags.forProtocolAdapter(Constants.PROTOCOL_ADAPTER_TYPE_AMQP));
final var metrics = new MicrometerBasedAmqpAdapterMetrics(registry, vertx);
metrics.setProtocolAdapterProperties(adapterProperties);
return metrics;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
# this needs to be configured at build time in order for native images to be able to log at TRACE level
quarkus.log.min-level=TRACE
quarkus.vertx.prefer-native-transport=true
quarkus.vertx.resolver.cache-max-time-to-live=0
${quarkus.application.properties}

2 changes: 1 addition & 1 deletion adapters/coap-vertx-quarkus/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<ports>
<port>5683/udp</port>
<port>5684/udp</port>
<port>${vertx.health.port}</port>
<port>${health.check.port}</port>
</ports>
</build>
</image>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.eclipse.hono.util.Constants;

import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.config.MeterFilter;
import io.vertx.core.Vertx;

/**
Expand All @@ -37,14 +38,18 @@ CoapAdapterProperties adapterProperties(final CoapAdapterOptions adapterOptions)
return new CoapAdapterProperties(adapterOptions);
}

@Produces
@Singleton
MeterFilter commonTags() {
return MeterFilter.commonTags(MetricsTags.forProtocolAdapter(Constants.PROTOCOL_ADAPTER_TYPE_COAP));
}

@Singleton
@Produces
MicrometerBasedCoapAdapterMetrics metrics(
final Vertx vertx,
final MeterRegistry registry,
final CoapAdapterProperties adapterProperties) {
// define tags before the first metric gets created in the MicrometerBasedCoapAdapterMetrics constructor
registry.config().commonTags(MetricsTags.forProtocolAdapter(Constants.PROTOCOL_ADAPTER_TYPE_COAP));
final var metrics = new MicrometerBasedCoapAdapterMetrics(registry, vertx);
metrics.setProtocolAdapterProperties(adapterProperties);
return metrics;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
# this needs to be configured at build time in order for native images to be able to log at TRACE level
quarkus.log.min-level=TRACE
quarkus.vertx.prefer-native-transport=true
quarkus.vertx.resolver.cache-max-time-to-live=0
${quarkus.application.properties}

2 changes: 1 addition & 1 deletion adapters/http-vertx-quarkus/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<ports>
<port>8080</port>
<port>8443</port>
<port>${vertx.health.port}</port>
<port>${health.check.port}</port>
</ports>
</build>
</image>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.eclipse.hono.util.Constants;

import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.config.MeterFilter;
import io.vertx.core.Vertx;

/**
Expand All @@ -37,14 +38,18 @@ HttpProtocolAdapterProperties adapterProperties(final HttpProtocolAdapterOptions
return new HttpProtocolAdapterProperties(adapterOptions);
}

@Produces
@Singleton
MeterFilter commonTags() {
return MeterFilter.commonTags(MetricsTags.forProtocolAdapter(Constants.PROTOCOL_ADAPTER_TYPE_HTTP));
}

@Singleton
@Produces
MicrometerBasedHttpAdapterMetrics metrics(
final Vertx vertx,
final MeterRegistry registry,
final HttpProtocolAdapterProperties adapterProperties) {
// define tags before the first metric gets created in the MicrometerBasedHttpAdapterMetrics constructor
registry.config().commonTags(MetricsTags.forProtocolAdapter(Constants.PROTOCOL_ADAPTER_TYPE_HTTP));
final var metrics = new MicrometerBasedHttpAdapterMetrics(registry, vertx);
metrics.setProtocolAdapterProperties(adapterProperties);
return metrics;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
# this needs to be configured at build time in order for native images to be able to log at TRACE level
quarkus.log.min-level=TRACE
quarkus.vertx.prefer-native-transport=true
quarkus.vertx.resolver.cache-max-time-to-live=0
${quarkus.application.properties}

2 changes: 1 addition & 1 deletion adapters/lora-vertx-quarkus/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<ports>
<port>8080</port>
<port>8443</port>
<port>${vertx.health.port}</port>
<port>${health.check.port}</port>
</ports>
</build>
</image>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.eclipse.hono.util.Constants;

import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.config.MeterFilter;
import io.smallrye.config.ConfigMapping;
import io.vertx.core.Vertx;

Expand All @@ -39,14 +40,18 @@ HttpProtocolAdapterProperties adapterProperties(@ConfigMapping(prefix = "hono.lo
return new HttpProtocolAdapterProperties(adapterOptions);
}

@Produces
@Singleton
MeterFilter commonTags() {
return MeterFilter.commonTags(MetricsTags.forProtocolAdapter(Constants.PROTOCOL_ADAPTER_TYPE_LORA));
}

@Singleton
@Produces
MicrometerBasedHttpAdapterMetrics metrics(
final Vertx vertx,
final MeterRegistry registry,
final HttpProtocolAdapterProperties adapterProperties) {
// define tags before the first metric gets created in the MicrometerBasedHttpAdapterMetrics constructor
registry.config().commonTags(MetricsTags.forProtocolAdapter(Constants.PROTOCOL_ADAPTER_TYPE_LORA));
final var metrics = new MicrometerBasedHttpAdapterMetrics(registry, vertx);
metrics.setProtocolAdapterProperties(adapterProperties);
return metrics;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
# this needs to be configured at build time in order for native images to be able to log at TRACE level
quarkus.log.min-level=TRACE
quarkus.vertx.prefer-native-transport=true
quarkus.vertx.resolver.cache-max-time-to-live=0
${quarkus.application.properties}

2 changes: 1 addition & 1 deletion adapters/mqtt-vertx-quarkus/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<ports>
<port>1883</port>
<port>8883</port>
<port>${vertx.health.port}</port>
<port>${health.check.port}</port>
</ports>
</build>
</image>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.eclipse.hono.util.Constants;

import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.config.MeterFilter;
import io.vertx.core.Vertx;

/**
Expand All @@ -37,14 +38,18 @@ MqttProtocolAdapterProperties adapterProperties(final MqttProtocolAdapterOptions
return new MqttProtocolAdapterProperties(adapterOptions);
}

@Produces
@Singleton
MeterFilter commonTags() {
return MeterFilter.commonTags(MetricsTags.forProtocolAdapter(Constants.PROTOCOL_ADAPTER_TYPE_MQTT));
}

@Singleton
@Produces
MicrometerBasedMqttAdapterMetrics metrics(
final Vertx vertx,
final MeterRegistry registry,
final MqttProtocolAdapterProperties adapterProperties) {
// define tags before the first metric gets created in the MicrometerBasedMqttAdapterMetrics constructor
registry.config().commonTags(MetricsTags.forProtocolAdapter(Constants.PROTOCOL_ADAPTER_TYPE_MQTT));
final var metrics = new MicrometerBasedMqttAdapterMetrics(registry, vertx);
metrics.setProtocolAdapterProperties(adapterProperties);
return metrics;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
# this needs to be configured at build time in order for native images to be able to log at TRACE level
quarkus.log.min-level=TRACE
quarkus.vertx.prefer-native-transport=true
quarkus.vertx.resolver.cache-max-time-to-live=0
${quarkus.application.properties}

46 changes: 22 additions & 24 deletions adapters/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-vertx</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-micrometer</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-health</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jackson</artifactId>
Expand All @@ -83,12 +91,6 @@
<groupId>org.jboss.logging</groupId>
<artifactId>commons-logging-jboss-logging</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<scope>compile</scope>
<optional>true</optional>
</dependency>

<!-- Testing -->
<dependency>
Expand Down Expand Up @@ -129,6 +131,12 @@
</dependencies>

<build>
<resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down Expand Up @@ -170,12 +178,8 @@
<configuration>
<properties>
<property>
<name>hono.metrics</name>
<value>${hono.metrics}</value>
</property>
<property>
<name>hono.tracing</name>
<value>${hono.tracing}</value>
<name>quarkus.jaeger.metrics.enabled</name>
<value>${jaeger.metrics.enabled}</value>
</property>
</properties>
</configuration>
Expand Down Expand Up @@ -343,20 +347,17 @@

<profile>
<id>metrics-prometheus</id>
<dependencies>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
</dependencies>
<activation>
<property>
<name>metrics-prometheus</name>
</property>
</activation>
<properties>
<hono.metrics>prometheus</hono.metrics>
</properties>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-micrometer-registry-prometheus</artifactId>
</dependency>
</dependencies>
</profile>

<profile>
Expand All @@ -366,9 +367,6 @@
<name>jaeger</name>
</property>
</activation>
<properties>
<hono.tracing>jaeger</hono.tracing>
</properties>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
Expand Down
2 changes: 1 addition & 1 deletion adapters/sigfox-vertx/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<ports>
<port>8080</port>
<port>8443</port>
<port>${vertx.health.port}</port>
<port>${health.check.port}</port>
</ports>
</build>
</image>
Expand Down
Loading

0 comments on commit 82cd6df

Please sign in to comment.