Search in sources :

Example 6 with MetricsProvider

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

the class ConnectorMockTest method setup.

@SuppressWarnings({ "checkstyle:MethodLength" })
@BeforeEach
public void setup(VertxTestContext testContext) {
    vertx = Vertx.vertx();
    // Configure the Kubernetes Mock
    mockKube = new MockKube2.MockKube2Builder(client).withKafkaConnectCrd().withKafkaConnectorCrd().withDeploymentController().build();
    mockKube.start();
    PlatformFeaturesAvailability pfa = new PlatformFeaturesAvailability(false, KubernetesVersion.V1_18);
    setupMockConnectAPI();
    metricsProvider = ResourceUtils.metricsProvider();
    ResourceOperatorSupplier ros = new ResourceOperatorSupplier(vertx, client, new ZookeeperLeaderFinder(vertx, // Retry up to 3 times (4 attempts), with overall max delay of 35000ms
    () -> new BackOff(5_000, 2, 4)), new DefaultAdminClientProvider(), new DefaultZookeeperScalerProvider(), metricsProvider, pfa, 10_000);
    ClusterOperatorConfig config = ClusterOperatorConfig.fromMap(map(ClusterOperatorConfig.STRIMZI_KAFKA_IMAGES, KafkaVersionTestUtils.getKafkaImagesEnvVarString(), ClusterOperatorConfig.STRIMZI_KAFKA_CONNECT_IMAGES, KafkaVersionTestUtils.getKafkaConnectImagesEnvVarString(), ClusterOperatorConfig.STRIMZI_KAFKA_MIRROR_MAKER_2_IMAGES, KafkaVersionTestUtils.getKafkaMirrorMaker2ImagesEnvVarString(), ClusterOperatorConfig.STRIMZI_FULL_RECONCILIATION_INTERVAL_MS, Long.toString(Long.MAX_VALUE)), KafkaVersionTestUtils.getKafkaVersionLookup());
    kafkaConnectOperator = spy(new KafkaConnectAssemblyOperator(vertx, pfa, ros, config, x -> api));
    Checkpoint async = testContext.checkpoint();
    // Fail test if watcher closes for any reason
    kafkaConnectOperator.createWatch(NAMESPACE, e -> testContext.failNow(e)).onComplete(testContext.succeeding()).compose(watch -> {
        connectWatch = watch;
        return AbstractConnectOperator.createConnectorWatch(kafkaConnectOperator, NAMESPACE, null);
    }).compose(watch -> {
        connectorWatch = watch;
        // async.flag();
        return Future.succeededFuture();
    }).onComplete(testContext.succeeding(v -> async.flag()));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) BeforeEach(org.junit.jupiter.api.BeforeEach) ConnectorPluginBuilder(io.strimzi.api.kafka.model.connect.ConnectorPluginBuilder) OrderedProperties(io.strimzi.operator.common.model.OrderedProperties) LabelSelector(io.fabric8.kubernetes.api.model.LabelSelector) TestUtils.waitFor(io.strimzi.test.TestUtils.waitFor) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Annotations(io.strimzi.operator.common.Annotations) TimeoutException(java.util.concurrent.TimeoutException) Disabled(org.junit.jupiter.api.Disabled) KafkaConnector(io.strimzi.api.kafka.model.KafkaConnector) Collections.singletonList(java.util.Collections.singletonList) Resource(io.fabric8.kubernetes.client.dsl.Resource) DefaultAdminClientProvider(io.strimzi.operator.common.DefaultAdminClientProvider) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) EnableKubernetesMockClient(io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient) Map(java.util.Map) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) JsonObject(io.vertx.core.json.JsonObject) ResourceUtils(io.strimzi.operator.cluster.ResourceUtils) MockKube2(io.strimzi.test.mockkube2.MockKube2) Tags(io.micrometer.core.instrument.Tags) KafkaConnect(io.strimzi.api.kafka.model.KafkaConnect) Gauge(io.micrometer.core.instrument.Gauge) ConnectTimeoutException(io.netty.channel.ConnectTimeoutException) Predicate(java.util.function.Predicate) MetricsProvider(io.strimzi.operator.common.MetricsProvider) Mockito.atLeastOnce(org.mockito.Mockito.atLeastOnce) KafkaConnectBuilder(io.strimzi.api.kafka.model.KafkaConnectBuilder) VertxExtension(io.vertx.junit5.VertxExtension) Future(io.vertx.core.Future) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) Objects(java.util.Objects) KafkaConnectCluster(io.strimzi.operator.cluster.model.KafkaConnectCluster) List(java.util.List) Labels(io.strimzi.operator.common.model.Labels) Logger(org.apache.logging.log4j.Logger) Optional(java.util.Optional) Checkpoint(io.vertx.junit5.Checkpoint) Condition(io.strimzi.api.kafka.model.status.Condition) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) ClusterOperatorConfig(io.strimzi.operator.cluster.ClusterOperatorConfig) CustomResource(io.fabric8.kubernetes.client.CustomResource) Mockito.mock(org.mockito.Mockito.mock) VertxTestContext(io.vertx.junit5.VertxTestContext) Assertions.fail(org.junit.jupiter.api.Assertions.fail) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BackOff(io.strimzi.operator.common.BackOff) Watch(io.fabric8.kubernetes.client.Watch) HashMap(java.util.HashMap) Crds(io.strimzi.api.kafka.Crds) Mockito.spy(org.mockito.Mockito.spy) KafkaVersionTestUtils(io.strimzi.operator.cluster.KafkaVersionTestUtils) ZookeeperLeaderFinder(io.strimzi.operator.cluster.operator.resource.ZookeeperLeaderFinder) TestUtils(io.strimzi.test.TestUtils) Status(io.strimzi.api.kafka.model.status.Status) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) KafkaConnectorBuilder(io.strimzi.api.kafka.model.KafkaConnectorBuilder) TestUtils.map(io.strimzi.test.TestUtils.map) Collections.emptyMap(java.util.Collections.emptyMap) Matchers.empty(org.hamcrest.Matchers.empty) Promise(io.vertx.core.Promise) KubernetesVersion(io.strimzi.operator.KubernetesVersion) Vertx(io.vertx.core.Vertx) ConnectorPlugin(io.strimzi.api.kafka.model.connect.ConnectorPlugin) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) TimeUnit(java.util.concurrent.TimeUnit) Reconciliation(io.strimzi.operator.common.Reconciliation) AfterEach(org.junit.jupiter.api.AfterEach) Mockito.never(org.mockito.Mockito.never) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) DefaultZookeeperScalerProvider(io.strimzi.operator.cluster.operator.resource.DefaultZookeeperScalerProvider) LogManager(org.apache.logging.log4j.LogManager) Collections(java.util.Collections) KafkaConnectResources(io.strimzi.api.kafka.model.KafkaConnectResources) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) Checkpoint(io.vertx.junit5.Checkpoint) MockKube2(io.strimzi.test.mockkube2.MockKube2) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) ClusterOperatorConfig(io.strimzi.operator.cluster.ClusterOperatorConfig) ZookeeperLeaderFinder(io.strimzi.operator.cluster.operator.resource.ZookeeperLeaderFinder) DefaultZookeeperScalerProvider(io.strimzi.operator.cluster.operator.resource.DefaultZookeeperScalerProvider) BackOff(io.strimzi.operator.common.BackOff) DefaultAdminClientProvider(io.strimzi.operator.common.DefaultAdminClientProvider) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 7 with MetricsProvider

use of io.strimzi.operator.common.MetricsProvider 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 8 with MetricsProvider

use of io.strimzi.operator.common.MetricsProvider 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)8 MetricsProvider (io.strimzi.operator.common.MetricsProvider)8 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)4 EnableKubernetesMockClient (io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient)4 Tags (io.micrometer.core.instrument.Tags)4 Crds (io.strimzi.api.kafka.Crds)4 KafkaConnector (io.strimzi.api.kafka.model.KafkaConnector)4 KafkaConnectorBuilder (io.strimzi.api.kafka.model.KafkaConnectorBuilder)4 KubernetesVersion (io.strimzi.operator.KubernetesVersion)4 PlatformFeaturesAvailability (io.strimzi.operator.PlatformFeaturesAvailability)4 ClusterOperatorConfig (io.strimzi.operator.cluster.ClusterOperatorConfig)4 KafkaVersionTestUtils (io.strimzi.operator.cluster.KafkaVersionTestUtils)4 DefaultZookeeperScalerProvider (io.strimzi.operator.cluster.operator.resource.DefaultZookeeperScalerProvider)4 ResourceOperatorSupplier (io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier)4 ZookeeperLeaderFinder (io.strimzi.operator.cluster.operator.resource.ZookeeperLeaderFinder)4 BackOff (io.strimzi.operator.common.BackOff)4 DefaultAdminClientProvider (io.strimzi.operator.common.DefaultAdminClientProvider)4 MicrometerMetricsProvider (io.strimzi.operator.common.MicrometerMetricsProvider)4 Reconciliation (io.strimzi.operator.common.Reconciliation)4 MockKube2 (io.strimzi.test.mockkube2.MockKube2)3