Search in sources :

Example 1 with MicrometerMetricsProvider

use of io.strimzi.operator.common.MicrometerMetricsProvider in project strimzi by strimzi.

the class KafkaConnectorIT method test.

@Test
public void test(VertxTestContext context) {
    KafkaConnectApiImpl connectClient = new KafkaConnectApiImpl(vertx);
    KubernetesClient client = new MockKube().withCustomResourceDefinition(Crds.kafkaConnector(), KafkaConnector.class, KafkaConnectorList.class).end().build();
    PlatformFeaturesAvailability pfa = new PlatformFeaturesAvailability(false, KubernetesVersion.V1_20);
    String namespace = "ns";
    String connectorName = "my-connector";
    LinkedHashMap<String, Object> config = new LinkedHashMap<>();
    config.put(TestingConnector.START_TIME_MS, 1_000);
    config.put(TestingConnector.STOP_TIME_MS, 0);
    config.put(TestingConnector.TASK_START_TIME_MS, 1_000);
    config.put(TestingConnector.TASK_STOP_TIME_MS, 0);
    config.put(TestingConnector.TASK_POLL_TIME_MS, 1_000);
    config.put(TestingConnector.TASK_POLL_RECORDS, 100);
    config.put(TestingConnector.NUM_PARTITIONS, 1);
    config.put(TestingConnector.TOPIC_NAME, "my-topic");
    KafkaConnector connector = createKafkaConnector(namespace, connectorName, config);
    Crds.kafkaConnectorOperation(client).inNamespace(namespace).create(connector);
    // Intercept status updates at CrdOperator level
    // This is to bridge limitations between MockKube and the CrdOperator, as there are currently no Fabric8 APIs for status update
    CrdOperator connectCrdOperator = mock(CrdOperator.class);
    when(connectCrdOperator.updateStatusAsync(any(), any())).thenAnswer(invocation -> {
        try {
            return Future.succeededFuture(Crds.kafkaConnectorOperation(client).inNamespace(namespace).withName(connectorName).patch((KafkaConnector) invocation.getArgument(1)));
        } catch (Exception e) {
            return Future.failedFuture(e);
        }
    });
    when(connectCrdOperator.getAsync(any(), any())).thenAnswer(invocationOnMock -> {
        try {
            return Future.succeededFuture(Crds.kafkaConnectorOperation(client).inNamespace(namespace).withName(connectorName).get());
        } catch (Exception e) {
            return Future.failedFuture(e);
        }
    });
    MetricsProvider metrics = new MicrometerMetricsProvider();
    KafkaConnectAssemblyOperator operator = new KafkaConnectAssemblyOperator(vertx, pfa, new ResourceOperatorSupplier(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, connectCrdOperator, null, null, null, null, null, null, metrics, null, null), ClusterOperatorConfig.fromMap(Collections.emptyMap(), KafkaVersionTestUtils.getKafkaVersionLookup()), connect -> new KafkaConnectApiImpl(vertx), connectCluster.getPort(2)) {
    };
    Checkpoint async = context.checkpoint();
    operator.reconcileConnectorAndHandleResult(new Reconciliation("test", "KafkaConnect", namespace, "bogus"), "localhost", connectClient, true, connectorName, connector).onComplete(context.succeeding(v -> assertConnectorIsRunning(context, client, namespace, connectorName))).compose(v -> {
        config.remove(TestingConnector.START_TIME_MS, 1_000);
        config.put(TestingConnector.START_TIME_MS, 1_000);
        Crds.kafkaConnectorOperation(client).inNamespace(namespace).withName(connectorName).patch(createKafkaConnector(namespace, connectorName, config));
        return operator.reconcileConnectorAndHandleResult(new Reconciliation("test", "KafkaConnect", namespace, "bogus"), "localhost", connectClient, true, connectorName, connector);
    }).onComplete(context.succeeding(v -> context.verify(() -> {
        assertConnectorIsRunning(context, client, namespace, connectorName);
        // Assert metrics from Connector Operator
        MeterRegistry registry = metrics.meterRegistry();
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations").tag("kind", KafkaConnector.RESOURCE_KIND).counter().count(), CoreMatchers.is(2.0));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations.successful").tag("kind", KafkaConnector.RESOURCE_KIND).counter().count(), CoreMatchers.is(2.0));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations.duration").tag("kind", KafkaConnector.RESOURCE_KIND).timer().count(), CoreMatchers.is(2L));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations.duration").tag("kind", KafkaConnector.RESOURCE_KIND).timer().totalTime(TimeUnit.MILLISECONDS), greaterThan(0.0));
        async.flag();
    })));
}
Also used : VertxTestContext(io.vertx.junit5.VertxTestContext) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) KafkaConnectorList(io.strimzi.api.kafka.KafkaConnectorList) CoreMatchers(org.hamcrest.CoreMatchers) BeforeEach(org.junit.jupiter.api.BeforeEach) HashMap(java.util.HashMap) Crds(io.strimzi.api.kafka.Crds) KafkaConnector(io.strimzi.api.kafka.model.KafkaConnector) MockKube(io.strimzi.test.mockkube.MockKube) AfterAll(org.junit.jupiter.api.AfterAll) LinkedHashMap(java.util.LinkedHashMap) CoreMatchers.instanceOf(org.hamcrest.CoreMatchers.instanceOf) MicrometerMetricsOptions(io.vertx.micrometer.MicrometerMetricsOptions) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) KafkaVersionTestUtils(io.strimzi.operator.cluster.KafkaVersionTestUtils) BeforeAll(org.junit.jupiter.api.BeforeAll) CrdOperator(io.strimzi.operator.common.operator.resource.CrdOperator) Map(java.util.Map) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) StrimziKafkaCluster(io.strimzi.test.container.StrimziKafkaCluster) KafkaConnectorBuilder(io.strimzi.api.kafka.model.KafkaConnectorBuilder) AbstractOperator(io.strimzi.operator.common.AbstractOperator) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) KubernetesVersion(io.strimzi.operator.KubernetesVersion) MetricsProvider(io.strimzi.operator.common.MetricsProvider) MicrometerMetricsProvider(io.strimzi.operator.common.MicrometerMetricsProvider) Vertx(io.vertx.core.Vertx) VertxOptions(io.vertx.core.VertxOptions) IOException(java.io.IOException) VertxPrometheusOptions(io.vertx.micrometer.VertxPrometheusOptions) Mockito.when(org.mockito.Mockito.when) VertxExtension(io.vertx.junit5.VertxExtension) Future(io.vertx.core.Future) Test(org.junit.jupiter.api.Test) TimeUnit(java.util.concurrent.TimeUnit) Reconciliation(io.strimzi.operator.common.Reconciliation) AfterEach(org.junit.jupiter.api.AfterEach) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) Checkpoint(io.vertx.junit5.Checkpoint) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) Matchers.is(org.hamcrest.Matchers.is) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) Collections(java.util.Collections) ClusterOperatorConfig(io.strimzi.operator.cluster.ClusterOperatorConfig) Mockito.mock(org.mockito.Mockito.mock) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) IOException(java.io.IOException) LinkedHashMap(java.util.LinkedHashMap) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) MockKube(io.strimzi.test.mockkube.MockKube) Checkpoint(io.vertx.junit5.Checkpoint) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) CrdOperator(io.strimzi.operator.common.operator.resource.CrdOperator) Reconciliation(io.strimzi.operator.common.Reconciliation) MicrometerMetricsProvider(io.strimzi.operator.common.MicrometerMetricsProvider) KafkaConnector(io.strimzi.api.kafka.model.KafkaConnector) MetricsProvider(io.strimzi.operator.common.MetricsProvider) MicrometerMetricsProvider(io.strimzi.operator.common.MicrometerMetricsProvider) Test(org.junit.jupiter.api.Test)

Example 2 with MicrometerMetricsProvider

use of io.strimzi.operator.common.MicrometerMetricsProvider in project strimzi-kafka-operator by strimzi.

the class KafkaConnectorIT method test.

@Test
public void test(VertxTestContext context) {
    KafkaConnectApiImpl connectClient = new KafkaConnectApiImpl(vertx);
    KubernetesClient client = new MockKube().withCustomResourceDefinition(Crds.kafkaConnector(), KafkaConnector.class, KafkaConnectorList.class).end().build();
    PlatformFeaturesAvailability pfa = new PlatformFeaturesAvailability(false, KubernetesVersion.V1_20);
    String namespace = "ns";
    String connectorName = "my-connector";
    LinkedHashMap<String, Object> config = new LinkedHashMap<>();
    config.put(TestingConnector.START_TIME_MS, 1_000);
    config.put(TestingConnector.STOP_TIME_MS, 0);
    config.put(TestingConnector.TASK_START_TIME_MS, 1_000);
    config.put(TestingConnector.TASK_STOP_TIME_MS, 0);
    config.put(TestingConnector.TASK_POLL_TIME_MS, 1_000);
    config.put(TestingConnector.TASK_POLL_RECORDS, 100);
    config.put(TestingConnector.NUM_PARTITIONS, 1);
    config.put(TestingConnector.TOPIC_NAME, "my-topic");
    KafkaConnector connector = createKafkaConnector(namespace, connectorName, config);
    Crds.kafkaConnectorOperation(client).inNamespace(namespace).create(connector);
    // Intercept status updates at CrdOperator level
    // This is to bridge limitations between MockKube and the CrdOperator, as there are currently no Fabric8 APIs for status update
    CrdOperator connectCrdOperator = mock(CrdOperator.class);
    when(connectCrdOperator.updateStatusAsync(any(), any())).thenAnswer(invocation -> {
        try {
            return Future.succeededFuture(Crds.kafkaConnectorOperation(client).inNamespace(namespace).withName(connectorName).patch((KafkaConnector) invocation.getArgument(1)));
        } catch (Exception e) {
            return Future.failedFuture(e);
        }
    });
    when(connectCrdOperator.getAsync(any(), any())).thenAnswer(invocationOnMock -> {
        try {
            return Future.succeededFuture(Crds.kafkaConnectorOperation(client).inNamespace(namespace).withName(connectorName).get());
        } catch (Exception e) {
            return Future.failedFuture(e);
        }
    });
    MetricsProvider metrics = new MicrometerMetricsProvider();
    KafkaConnectAssemblyOperator operator = new KafkaConnectAssemblyOperator(vertx, pfa, new ResourceOperatorSupplier(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, connectCrdOperator, null, null, null, null, null, null, metrics, null, null), ClusterOperatorConfig.fromMap(Collections.emptyMap(), KafkaVersionTestUtils.getKafkaVersionLookup()), connect -> new KafkaConnectApiImpl(vertx), connectCluster.getPort(2)) {
    };
    Checkpoint async = context.checkpoint();
    operator.reconcileConnectorAndHandleResult(new Reconciliation("test", "KafkaConnect", namespace, "bogus"), "localhost", connectClient, true, connectorName, connector).onComplete(context.succeeding(v -> assertConnectorIsRunning(context, client, namespace, connectorName))).compose(v -> {
        config.remove(TestingConnector.START_TIME_MS, 1_000);
        config.put(TestingConnector.START_TIME_MS, 1_000);
        Crds.kafkaConnectorOperation(client).inNamespace(namespace).withName(connectorName).patch(createKafkaConnector(namespace, connectorName, config));
        return operator.reconcileConnectorAndHandleResult(new Reconciliation("test", "KafkaConnect", namespace, "bogus"), "localhost", connectClient, true, connectorName, connector);
    }).onComplete(context.succeeding(v -> context.verify(() -> {
        assertConnectorIsRunning(context, client, namespace, connectorName);
        // Assert metrics from Connector Operator
        MeterRegistry registry = metrics.meterRegistry();
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations").tag("kind", KafkaConnector.RESOURCE_KIND).counter().count(), CoreMatchers.is(2.0));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations.successful").tag("kind", KafkaConnector.RESOURCE_KIND).counter().count(), CoreMatchers.is(2.0));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations.duration").tag("kind", KafkaConnector.RESOURCE_KIND).timer().count(), CoreMatchers.is(2L));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations.duration").tag("kind", KafkaConnector.RESOURCE_KIND).timer().totalTime(TimeUnit.MILLISECONDS), greaterThan(0.0));
        async.flag();
    })));
}
Also used : VertxTestContext(io.vertx.junit5.VertxTestContext) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) KafkaConnectorList(io.strimzi.api.kafka.KafkaConnectorList) CoreMatchers(org.hamcrest.CoreMatchers) BeforeEach(org.junit.jupiter.api.BeforeEach) HashMap(java.util.HashMap) Crds(io.strimzi.api.kafka.Crds) KafkaConnector(io.strimzi.api.kafka.model.KafkaConnector) MockKube(io.strimzi.test.mockkube.MockKube) AfterAll(org.junit.jupiter.api.AfterAll) LinkedHashMap(java.util.LinkedHashMap) CoreMatchers.instanceOf(org.hamcrest.CoreMatchers.instanceOf) MicrometerMetricsOptions(io.vertx.micrometer.MicrometerMetricsOptions) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) KafkaVersionTestUtils(io.strimzi.operator.cluster.KafkaVersionTestUtils) BeforeAll(org.junit.jupiter.api.BeforeAll) CrdOperator(io.strimzi.operator.common.operator.resource.CrdOperator) Map(java.util.Map) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) StrimziKafkaCluster(io.strimzi.test.container.StrimziKafkaCluster) KafkaConnectorBuilder(io.strimzi.api.kafka.model.KafkaConnectorBuilder) AbstractOperator(io.strimzi.operator.common.AbstractOperator) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) KubernetesVersion(io.strimzi.operator.KubernetesVersion) MetricsProvider(io.strimzi.operator.common.MetricsProvider) MicrometerMetricsProvider(io.strimzi.operator.common.MicrometerMetricsProvider) Vertx(io.vertx.core.Vertx) VertxOptions(io.vertx.core.VertxOptions) IOException(java.io.IOException) VertxPrometheusOptions(io.vertx.micrometer.VertxPrometheusOptions) Mockito.when(org.mockito.Mockito.when) VertxExtension(io.vertx.junit5.VertxExtension) Future(io.vertx.core.Future) Test(org.junit.jupiter.api.Test) TimeUnit(java.util.concurrent.TimeUnit) Reconciliation(io.strimzi.operator.common.Reconciliation) AfterEach(org.junit.jupiter.api.AfterEach) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) Checkpoint(io.vertx.junit5.Checkpoint) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) Matchers.is(org.hamcrest.Matchers.is) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) Collections(java.util.Collections) ClusterOperatorConfig(io.strimzi.operator.cluster.ClusterOperatorConfig) Mockito.mock(org.mockito.Mockito.mock) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) IOException(java.io.IOException) LinkedHashMap(java.util.LinkedHashMap) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) MockKube(io.strimzi.test.mockkube.MockKube) Checkpoint(io.vertx.junit5.Checkpoint) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) CrdOperator(io.strimzi.operator.common.operator.resource.CrdOperator) Reconciliation(io.strimzi.operator.common.Reconciliation) MicrometerMetricsProvider(io.strimzi.operator.common.MicrometerMetricsProvider) KafkaConnector(io.strimzi.api.kafka.model.KafkaConnector) MetricsProvider(io.strimzi.operator.common.MetricsProvider) MicrometerMetricsProvider(io.strimzi.operator.common.MicrometerMetricsProvider) Test(org.junit.jupiter.api.Test)

Example 3 with MicrometerMetricsProvider

use of io.strimzi.operator.common.MicrometerMetricsProvider in project strimzi by strimzi.

the class TopicOperatorTest method createCleanMetricsProvider.

/**
 * Created new MetricsProvider and makes sure it doesn't contain any metrics from previous tests.
 *
 * @return  Clean MetricsProvider
 */
public MetricsProvider createCleanMetricsProvider() {
    MetricsProvider metrics = new MicrometerMetricsProvider();
    MeterRegistry registry = metrics.meterRegistry();
    registry.forEachMeter(meter -> {
        registry.remove(meter);
    });
    return metrics;
}
Also used : MicrometerMetricsProvider(io.strimzi.operator.common.MicrometerMetricsProvider) MetricsProvider(io.strimzi.operator.common.MetricsProvider) MicrometerMetricsProvider(io.strimzi.operator.common.MicrometerMetricsProvider) MeterRegistry(io.micrometer.core.instrument.MeterRegistry)

Example 4 with MicrometerMetricsProvider

use of io.strimzi.operator.common.MicrometerMetricsProvider in project strimzi-kafka-operator by strimzi.

the class TopicOperatorTest method createCleanMetricsProvider.

/**
 * Created new MetricsProvider and makes sure it doesn't contain any metrics from previous tests.
 *
 * @return  Clean MetricsProvider
 */
public MetricsProvider createCleanMetricsProvider() {
    MetricsProvider metrics = new MicrometerMetricsProvider();
    MeterRegistry registry = metrics.meterRegistry();
    registry.forEachMeter(meter -> {
        registry.remove(meter);
    });
    return metrics;
}
Also used : MicrometerMetricsProvider(io.strimzi.operator.common.MicrometerMetricsProvider) MetricsProvider(io.strimzi.operator.common.MetricsProvider) MicrometerMetricsProvider(io.strimzi.operator.common.MicrometerMetricsProvider) MeterRegistry(io.micrometer.core.instrument.MeterRegistry)

Aggregations

MeterRegistry (io.micrometer.core.instrument.MeterRegistry)4 MetricsProvider (io.strimzi.operator.common.MetricsProvider)4 MicrometerMetricsProvider (io.strimzi.operator.common.MicrometerMetricsProvider)4 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)2 Crds (io.strimzi.api.kafka.Crds)2 KafkaConnectorList (io.strimzi.api.kafka.KafkaConnectorList)2 KafkaConnector (io.strimzi.api.kafka.model.KafkaConnector)2 KafkaConnectorBuilder (io.strimzi.api.kafka.model.KafkaConnectorBuilder)2 KubernetesVersion (io.strimzi.operator.KubernetesVersion)2 PlatformFeaturesAvailability (io.strimzi.operator.PlatformFeaturesAvailability)2 ClusterOperatorConfig (io.strimzi.operator.cluster.ClusterOperatorConfig)2 KafkaVersionTestUtils (io.strimzi.operator.cluster.KafkaVersionTestUtils)2 ResourceOperatorSupplier (io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier)2 AbstractOperator (io.strimzi.operator.common.AbstractOperator)2 Reconciliation (io.strimzi.operator.common.Reconciliation)2 CrdOperator (io.strimzi.operator.common.operator.resource.CrdOperator)2 StrimziKafkaCluster (io.strimzi.test.container.StrimziKafkaCluster)2 MockKube (io.strimzi.test.mockkube.MockKube)2 Future (io.vertx.core.Future)2 Vertx (io.vertx.core.Vertx)2