Skip to content

Commit

Permalink
Merge pull request #42661 from brunobat/bump-micrometer-1-13
Browse files Browse the repository at this point in the history
Bump Micrometer to 1.13
  • Loading branch information
brunobat authored Aug 26, 2024
2 parents 4784ee0 + bfaee7b commit 50d4c38
Show file tree
Hide file tree
Showing 21 changed files with 270 additions and 76 deletions.
4 changes: 2 additions & 2 deletions bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
<opentelemetry-alpha.version>2.5.0-alpha</opentelemetry-alpha.version>
<opentelemetry-semconv.version>1.26.0-alpha</opentelemetry-semconv.version>
<quarkus-http.version>5.3.1</quarkus-http.version>
<micrometer.version>1.12.5</micrometer.version><!-- keep in sync with hdrhistogram -->
<hdrhistogram.version>2.1.12</hdrhistogram.version><!-- keep in sync with micrometer -->
<micrometer.version>1.13.3</micrometer.version><!-- keep in sync with hdrhistogram -->
<hdrhistogram.version>2.2.2</hdrhistogram.version><!-- keep in sync with micrometer -->
<google-auth.version>0.22.0</google-auth.version>
<graphql-java.version>22.1</graphql-java.version> <!-- keep in sync with smallrye-graphql -->
<microprofile-config-api.version>3.1</microprofile-config-api.version>
Expand Down
2 changes: 2 additions & 0 deletions docs/src/main/asciidoc/telemetry-micrometer-tutorial.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ include::{includes}/devtools/create-app.adoc[]
This command generates a Maven project, that imports the `micrometer-registry-prometheus` extension as a dependency.
This extension will load the core `micrometer` extension as well as additional library dependencies required to support prometheus.

NOTE: To maintain backwards compatibility, the extension uses the Prometheus client v0.x from Micrometer 1.13+, instead of their default v1.x client.

== Create a REST endpoint

Let's first add a simple endpoint that calculates prime numbers.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<artifactId>micrometer-registry-prometheus-simpleclient</artifactId>
</dependency>

</dependencies>
Expand Down
2 changes: 1 addition & 1 deletion extensions/micrometer-registry-prometheus/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<artifactId>micrometer-registry-prometheus-simpleclient</artifactId>
</dependency>

</dependencies>
Expand Down
2 changes: 1 addition & 1 deletion extensions/micrometer/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@

<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<artifactId>micrometer-registry-prometheus-simpleclient</artifactId>
<scope>test</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import io.quarkus.deployment.annotations.Record;
import io.quarkus.deployment.builditem.CombinedIndexBuildItem;
import io.quarkus.deployment.builditem.ShutdownContextBuildItem;
import io.quarkus.deployment.builditem.SystemPropertyBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import io.quarkus.deployment.metrics.MetricsCapabilityBuildItem;
import io.quarkus.deployment.metrics.MetricsFactoryConsumerBuildItem;
Expand Down Expand Up @@ -207,8 +208,18 @@ void configureRegistry(MicrometerRecorder recorder,
MicrometerConfig config,
List<MicrometerRegistryProviderBuildItem> providerClassItems,
List<MetricsFactoryConsumerBuildItem> metricsFactoryConsumerBuildItems,
List<MicrometerRegistryProviderBuildItem> providerClasses,
ShutdownContextBuildItem shutdownContextBuildItem) {
ShutdownContextBuildItem shutdownContextBuildItem,
BuildProducer<SystemPropertyBuildItem> systemProperty) {

// Avoid users from receiving:
// [io.mic.cor.ins.com.CompositeMeterRegistry] (main) A MeterFilter is being configured after a Meter has been
// registered to this registry...
// It's unavoidable because of how Quarkus startup works and users cannot do anything about it.
// see: https://github.com/micrometer-metrics/micrometer/issues/4920#issuecomment-2298348202
systemProperty.produce(
new SystemPropertyBuildItem(
"quarkus.log.category.\"io.micrometer.core.instrument.composite.CompositeMeterRegistry\".level",
"ERROR"));

Set<Class<? extends MeterRegistry>> typeClasses = new HashSet<>();
for (MicrometerRegistryProviderBuildItem item : providerClassItems) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,23 @@
import jakarta.inject.Inject;

import org.hamcrest.Matchers;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.micrometer.common.docs.KeyName;
import io.micrometer.core.instrument.Gauge;
import io.micrometer.core.instrument.Meter;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Metrics;
import io.micrometer.core.instrument.Tag;
import io.micrometer.core.instrument.Tags;
import io.micrometer.core.instrument.binder.MeterBinder;
import io.micrometer.core.instrument.binder.netty4.NettyAllocatorMetrics;
import io.micrometer.core.instrument.binder.netty4.NettyEventExecutorMetrics;
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
import io.netty.buffer.PooledByteBufAllocator;
import io.netty.buffer.UnpooledByteBufAllocator;
import io.netty.channel.EventLoopGroup;
Expand All @@ -53,8 +56,17 @@ public class NettyMetricsTest {
@Any
Instance<MeterBinder> binders;

@Inject
MeterRegistry registry;
final static SimpleMeterRegistry registry = new SimpleMeterRegistry();

@BeforeAll
static void setRegistry() {
Metrics.addRegistry(registry);
}

@AfterAll()
static void removeRegistry() {
Metrics.removeRegistry(registry);
}

@Inject
Vertx vertx;
Expand Down Expand Up @@ -228,4 +240,4 @@ private void checkMetrics(List<Meter> meters, EventExecutor executor, int expect
Assertions.assertEquals(expected, mvInt);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@

import jakarta.inject.Inject;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnOs;
import org.junit.jupiter.api.condition.OS;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.micrometer.core.instrument.Counter;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Metrics;
import io.micrometer.core.instrument.search.MeterNotFoundException;
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
import io.quarkus.redis.datasource.RedisDataSource;
import io.quarkus.test.QuarkusUnitTest;
import io.vertx.redis.client.Command;
Expand All @@ -27,15 +30,24 @@ public class RedisClientMetricsTest {
@RegisterExtension
static final QuarkusUnitTest config = new QuarkusUnitTest();

final static SimpleMeterRegistry registry = new SimpleMeterRegistry();

@BeforeAll
static void setRegistry() {
Metrics.addRegistry(registry);
}

@AfterAll()
static void removeRegistry() {
Metrics.removeRegistry(registry);
}

@Inject
RedisDataSource ds;

@Inject
Redis redis;

@Inject
MeterRegistry registry;

@Test
void testCommands() {
double count = 0.0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,19 @@
import jakarta.inject.Inject;

import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnOs;
import org.junit.jupiter.api.condition.OS;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.mockito.Mockito;

import io.micrometer.core.instrument.Counter;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Metrics;
import io.micrometer.core.instrument.Tag;
import io.micrometer.core.instrument.Timer;
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
import io.quarkus.micrometer.runtime.binder.stork.StorkObservationCollectorBean;
import io.quarkus.micrometer.test.GreetingResource;
import io.quarkus.micrometer.test.MockServiceSelectorConfiguration;
Expand Down Expand Up @@ -50,8 +53,17 @@ public class StorkMetricsLoadBalancerFailTest {
MockServiceSelectorProviderLoader.class, GreetingResource.class,
GreetingResource.GreetingRestClient.class, Util.class));

@Inject
MeterRegistry registry;
final static SimpleMeterRegistry registry = new SimpleMeterRegistry();

@BeforeAll
static void setRegistry() {
Metrics.addRegistry(registry);
}

@AfterAll()
static void removeRegistry() {
Metrics.removeRegistry(registry);
}

@Inject
MockServiceSelectorProvider provider;
Expand Down Expand Up @@ -91,15 +103,25 @@ private static void assertStorkMetrics(String serviceName) {
}

private void assertStorkMetricsInMicrometerRegistry(String serviceName) {
Counter instanceCounter = registry.counter("stork.service-discovery.instances.count", "service-name", serviceName);
Timer serviceDiscoveryDuration = registry.timer("stork.service-discovery.duration", "service-name", serviceName);
Timer serviceSelectionDuration = registry.timer("stork.service-selection.duration", "service-name", serviceName);
Counter serviceDiscoveryFailures = registry.counter("stork.service-discovery.failures", "service-name", serviceName);
Counter loadBalancerFailures = registry.counter("stork.service-selection.failures", "service-name", serviceName);
Counter instanceCounter = registry.find("stork.service-discovery.instances.count").tag("service-name", serviceName)
.counter();
Timer serviceDiscoveryDuration = registry.find("stork.service-discovery.duration").tag("service-name", serviceName)
.timer();
Timer serviceSelectionDuration = registry.find("stork.service-selection.duration").tag("service-name", serviceName)
.timer();
Counter serviceDiscoveryFailures = registry.find("stork.service-discovery.failures").tag("service-name", serviceName)
.counter();
Counter loadBalancerFailures = registry.find("stork.service-selection.failures").tag("service-name", serviceName)
.counter();

Util.assertTags(Tag.of("service-name", serviceName), instanceCounter, serviceDiscoveryDuration,
serviceSelectionDuration);

Assertions.assertThat(instanceCounter).isNotNull();
Assertions.assertThat(serviceDiscoveryDuration).isNotNull();
Assertions.assertThat(serviceSelectionDuration).isNotNull();
Assertions.assertThat(serviceDiscoveryFailures).isNotNull();
Assertions.assertThat(loadBalancerFailures).isNotNull();
Assertions.assertThat(instanceCounter.count()).isEqualTo(1);
Assertions.assertThat(loadBalancerFailures.count()).isEqualTo(1);
Assertions.assertThat(serviceDiscoveryFailures.count()).isEqualTo(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,25 @@
package io.quarkus.micrometer.deployment.binder;

import static io.restassured.RestAssured.when;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;

import java.util.concurrent.TimeUnit;

import jakarta.inject.Inject;

import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnOs;
import org.junit.jupiter.api.condition.OS;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.mockito.Mockito;

import io.micrometer.core.instrument.Counter;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Metrics;
import io.micrometer.core.instrument.Tag;
import io.micrometer.core.instrument.Timer;
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
import io.quarkus.micrometer.runtime.binder.stork.StorkObservationCollectorBean;
import io.quarkus.micrometer.test.GreetingResource;
import io.quarkus.micrometer.test.MockServiceDiscoveryConfiguration;
Expand Down Expand Up @@ -48,8 +50,17 @@ public class StorkMetricsServiceDiscoveryFailTest {
MockServiceDiscoveryProviderLoader.class, GreetingResource.class,
GreetingResource.GreetingRestClient.class, Util.class));

@Inject
MeterRegistry registry;
final static SimpleMeterRegistry registry = new SimpleMeterRegistry();

@BeforeAll
static void setRegistry() {
Metrics.addRegistry(registry);
}

@AfterAll()
static void removeRegistry() {
Metrics.removeRegistry(registry);
}

@Inject
MockServiceDiscoveryProvider provider;
Expand All @@ -73,15 +84,25 @@ public void shouldGetStorkMetricsWhenServiceDiscoveryFails() {
}

private void assertStorkMetricsInMicrometerRegistry(String serviceName) {
Counter instanceCounter = registry.counter("stork.service-discovery.instances.count", "service-name", serviceName);
Timer serviceDiscoveryDuration = registry.timer("stork.service-discovery.duration", "service-name", serviceName);
Timer serviceSelectionDuration = registry.timer("stork.service-selection.duration", "service-name", serviceName);
Counter serviceDiscoveryFailures = registry.counter("stork.service-discovery.failures", "service-name", serviceName);
Counter loadBalancerFailures = registry.counter("stork.service-selection.failures", "service-name", serviceName);
Counter instanceCounter = registry.find("stork.service-discovery.instances.count").tags("service-name", serviceName)
.counter();
Timer serviceDiscoveryDuration = registry.find("stork.service-discovery.duration").tags("service-name", serviceName)
.timer();
Timer serviceSelectionDuration = registry.find("stork.service-selection.duration").tags("service-name", serviceName)
.timer();
Counter serviceDiscoveryFailures = registry.find("stork.service-discovery.failures").tags("service-name", serviceName)
.counter();
Counter loadBalancerFailures = registry.find("stork.service-selection.failures").tags("service-name", serviceName)
.counter();

Util.assertTags(Tag.of("service-name", serviceName), instanceCounter, serviceDiscoveryDuration,
serviceSelectionDuration);

Assertions.assertThat(instanceCounter).isNotNull();
Assertions.assertThat(serviceDiscoveryDuration).isNotNull();
Assertions.assertThat(serviceSelectionDuration).isNotNull();
Assertions.assertThat(serviceDiscoveryFailures).isNotNull();
Assertions.assertThat(loadBalancerFailures).isNotNull();
Assertions.assertThat(instanceCounter.count()).isEqualTo(0);
Assertions.assertThat(loadBalancerFailures.count()).isEqualTo(0);
Assertions.assertThat(serviceDiscoveryFailures.count()).isEqualTo(1);
Expand Down
Loading

0 comments on commit 50d4c38

Please sign in to comment.