Skip to content

Commit

Permalink
Remove Vert.x dependency from MicrometerMetricsProvider (strimzi#9879)
Browse files Browse the repository at this point in the history
Signed-off-by: Jakub Scholz <[email protected]>
  • Loading branch information
scholzj authored Mar 27, 2024
1 parent 02f61d4 commit 179ad17
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import io.vertx.core.http.HttpServer;
import io.vertx.micrometer.MicrometerMetricsOptions;
import io.vertx.micrometer.VertxPrometheusOptions;
import io.vertx.micrometer.backends.BackendRegistries;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

Expand Down Expand Up @@ -90,7 +91,7 @@ public static void main(String[] args) {
shutdownHook.register(() -> ShutdownHook.shutdownVertx(vertx, SHUTDOWN_TIMEOUT));

// Setup Micrometer Metrics provider
MetricsProvider metricsProvider = new MicrometerMetricsProvider();
MetricsProvider metricsProvider = new MicrometerMetricsProvider(BackendRegistries.getDefaultNow());
KubernetesClient client = new OperatorKubernetesClientBuilder("strimzi-cluster-operator", strimziVersion).build();

maybeCreateClusterRoles(vertx, config, client)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import io.vertx.junit5.Checkpoint;
import io.vertx.junit5.VertxExtension;
import io.vertx.junit5.VertxTestContext;
import io.vertx.micrometer.backends.BackendRegistries;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -63,7 +64,7 @@ public static void after() {
void testWithLockCallableSuccessfulReleasesLock(VertxTestContext context) {
var resourceOperator = new DefaultWatchableStatusedResourceOperator<>(vertx, null, "TestResource");
@SuppressWarnings({ "unchecked", "rawtypes" })
var target = new DefaultOperator(vertx, "Test", resourceOperator, new MicrometerMetricsProvider(), null);
var target = new DefaultOperator(vertx, "Test", resourceOperator, new MicrometerMetricsProvider(BackendRegistries.getDefaultNow()), null);
Reconciliation reconciliation = new Reconciliation("test", "TestResource", "my-namespace", "my-resource");
String lockName = target.getLockName(reconciliation);

Expand Down Expand Up @@ -96,7 +97,7 @@ void testWithLockCallableSuccessfulReleasesLock(VertxTestContext context) {
void testWithLockCallableHandledExceptionReleasesLock(VertxTestContext context) {
var resourceOperator = new DefaultWatchableStatusedResourceOperator<>(vertx, null, "TestResource");
@SuppressWarnings({ "unchecked", "rawtypes" })
var target = new DefaultOperator(vertx, "Test", resourceOperator, new MicrometerMetricsProvider(), null);
var target = new DefaultOperator(vertx, "Test", resourceOperator, new MicrometerMetricsProvider(BackendRegistries.getDefaultNow()), null);
Reconciliation reconciliation = new Reconciliation("test", "TestResource", "my-namespace", "my-resource");
String lockName = target.getLockName(reconciliation);

Expand Down Expand Up @@ -131,7 +132,7 @@ void testWithLockCallableHandledExceptionReleasesLock(VertxTestContext context)
void testWithLockCallableUnhandledExceptionReleasesLock(VertxTestContext context) {
var resourceOperator = new DefaultWatchableStatusedResourceOperator<>(vertx, null, "TestResource");
@SuppressWarnings({ "unchecked", "rawtypes" })
var target = new DefaultOperator(vertx, "Test", resourceOperator, new MicrometerMetricsProvider(), null);
var target = new DefaultOperator(vertx, "Test", resourceOperator, new MicrometerMetricsProvider(BackendRegistries.getDefaultNow()), null);
Reconciliation reconciliation = new Reconciliation("test", "TestResource", "my-namespace", "my-resource");
String lockName = target.getLockName(reconciliation);

Expand Down Expand Up @@ -169,7 +170,7 @@ void testWithLockCallableUnhandledExceptionReleasesLock(VertxTestContext context
void testWithLockFailHandlerUnhandledExceptionReleasesLock(VertxTestContext context) {
var resourceOperator = new DefaultWatchableStatusedResourceOperator<>(vertx, null, "TestResource");
@SuppressWarnings({ "unchecked", "rawtypes" })
var target = new DefaultOperator(vertx, "Test", resourceOperator, new MicrometerMetricsProvider(), null);
var target = new DefaultOperator(vertx, "Test", resourceOperator, new MicrometerMetricsProvider(BackendRegistries.getDefaultNow()), null);
Reconciliation reconciliation = new Reconciliation("test", "TestResource", "my-namespace", "my-resource");
String lockName = target.getLockName(reconciliation);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import io.vertx.junit5.VertxTestContext;
import io.vertx.micrometer.MicrometerMetricsOptions;
import io.vertx.micrometer.VertxPrometheusOptions;
import io.vertx.micrometer.backends.BackendRegistries;
import org.hamcrest.CoreMatchers;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
Expand Down Expand Up @@ -143,7 +144,7 @@ public void testConnectorNotUpdatedWhenConfigUnchanged(VertxTestContext context)
KafkaConnector connector = createKafkaConnector(namespace, connectorName, false, config);
Crds.kafkaConnectorOperation(client).inNamespace(namespace).resource(connector).create();

MetricsProvider metrics = new MicrometerMetricsProvider();
MetricsProvider metrics = new MicrometerMetricsProvider(BackendRegistries.getDefaultNow());
ResourceOperatorSupplier ros = new ResourceOperatorSupplier(vertx, client,
new ZookeeperLeaderFinder(vertx,
// Retry up to 3 times (4 attempts), with overall max delay of 35000ms
Expand Down Expand Up @@ -213,7 +214,7 @@ public void testConnectorResourceNotReadyWhenConnectorFailed(VertxTestContext co
KafkaConnector connector = createKafkaConnector(namespace, connectorName, false, config);
Crds.kafkaConnectorOperation(client).inNamespace(namespace).resource(connector).create();

MetricsProvider metrics = new MicrometerMetricsProvider();
MetricsProvider metrics = new MicrometerMetricsProvider(BackendRegistries.getDefaultNow());
ResourceOperatorSupplier ros = new ResourceOperatorSupplier(vertx, client,
new ZookeeperLeaderFinder(vertx,
// Retry up to 3 times (4 attempts), with overall max delay of 35000ms
Expand Down Expand Up @@ -262,7 +263,7 @@ public void testConnectorResourceNotReadyWhenTaskFailed(VertxTestContext context
KafkaConnector connector = createKafkaConnector(namespace, connectorName, false, config);
Crds.kafkaConnectorOperation(client).inNamespace(namespace).resource(connector).create();

MetricsProvider metrics = new MicrometerMetricsProvider();
MetricsProvider metrics = new MicrometerMetricsProvider(BackendRegistries.getDefaultNow());
ResourceOperatorSupplier ros = new ResourceOperatorSupplier(vertx, client,
new ZookeeperLeaderFinder(vertx,
// Retry up to 3 times (4 attempts), with overall max delay of 35000ms
Expand Down Expand Up @@ -322,7 +323,7 @@ public void testConnectorIsAutoRestarted(VertxTestContext context) {
KafkaConnector connector = createKafkaConnector(namespace, connectorName, true, config);
Crds.kafkaConnectorOperation(client).inNamespace(namespace).resource(connector).create();

MetricsProvider metrics = new MicrometerMetricsProvider();
MetricsProvider metrics = new MicrometerMetricsProvider(BackendRegistries.getDefaultNow());
ResourceOperatorSupplier ros = new ResourceOperatorSupplier(vertx, client,
new ZookeeperLeaderFinder(vertx,
// Retry up to 3 times (4 attempts), with overall max delay of 35000ms
Expand Down Expand Up @@ -371,7 +372,7 @@ public void testTaskIsAutoRestarted(VertxTestContext context) {
KafkaConnector connector = createKafkaConnector(namespace, connectorName, true, config);
Crds.kafkaConnectorOperation(client).inNamespace(namespace).resource(connector).create();

MetricsProvider metrics = new MicrometerMetricsProvider();
MetricsProvider metrics = new MicrometerMetricsProvider(BackendRegistries.getDefaultNow());
ResourceOperatorSupplier ros = new ResourceOperatorSupplier(vertx, client,
new ZookeeperLeaderFinder(vertx,
// Retry up to 3 times (4 attempts), with overall max delay of 35000ms
Expand Down Expand Up @@ -501,7 +502,7 @@ private void assertConnectorIsAutoRestarted(VertxTestContext context, Kubernetes
JsonObject connectorStatus = new JsonObject(kafkaConnector.getStatus().getConnectorStatus());
assertThat(connectorStatus.getJsonObject("connector"), notNullValue());
assertThat(connectorStatus.getJsonObject("connector").getString("state"), is("RESTARTING"));
MetricsProvider metrics = new MicrometerMetricsProvider();
MetricsProvider metrics = new MicrometerMetricsProvider(BackendRegistries.getDefaultNow());
MeterRegistry registry = metrics.meterRegistry();
assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "auto.restarts").tag("kind", KafkaConnector.RESOURCE_KIND).counter().count(), CoreMatchers.is(1.0));
});
Expand All @@ -522,7 +523,7 @@ private void assertTaskIsAutoRestarted(VertxTestContext context, KubernetesClien
assertThat(connectorStatus.getJsonArray("tasks"), notNullValue());
assertThat(connectorStatus.getJsonArray("tasks").size(), is(1));
assertThat(connectorStatus.getJsonArray("tasks").getJsonObject(0).getString("state"), is("RESTARTING"));
MetricsProvider metrics = new MicrometerMetricsProvider();
MetricsProvider metrics = new MicrometerMetricsProvider(BackendRegistries.getDefaultNow());
MeterRegistry registry = metrics.meterRegistry();
assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "auto.restarts").tag("kind", KafkaConnector.RESOURCE_KIND).counter().count(), CoreMatchers.is(1.0));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import io.vertx.junit5.VertxTestContext;
import io.vertx.micrometer.MicrometerMetricsOptions;
import io.vertx.micrometer.VertxPrometheusOptions;
import io.vertx.micrometer.backends.BackendRegistries;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -486,7 +487,7 @@ public void testReconcileAllOverMultipleNamespaces(VertxTestContext context) {
* @return Clean MetricsProvider
*/
public MetricsProvider createCleanMetricsProvider() {
MetricsProvider metrics = new MicrometerMetricsProvider();
MetricsProvider metrics = new MicrometerMetricsProvider(BackendRegistries.getDefaultNow());
MeterRegistry registry = metrics.meterRegistry();

registry.forEachMeter(registry::remove);
Expand Down
5 changes: 0 additions & 5 deletions operator-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,6 @@
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-micrometer-metrics</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>io.strimzi</groupId>
<artifactId>mockkube</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Tags;
import io.micrometer.core.instrument.Timer;
import io.vertx.micrometer.backends.BackendRegistries;

import java.time.Duration;
import java.util.concurrent.atomic.AtomicInteger;
Expand All @@ -20,13 +19,6 @@
public class MicrometerMetricsProvider implements MetricsProvider {
protected final MeterRegistry metrics;

/**
* Constructor of the Micrometer metrics provider which uses the Vert.x provided metrics registry
*/
public MicrometerMetricsProvider() {
this.metrics = BackendRegistries.getDefaultNow();
}

/**
* Constructor of the Micrometer metrics provider.
*
Expand Down

0 comments on commit 179ad17

Please sign in to comment.