Search in sources :

Example 11 with AbstractWatchableStatusedResourceOperator

use of io.strimzi.operator.common.operator.resource.AbstractWatchableStatusedResourceOperator in project strimzi by strimzi.

the class OperatorMetricsTest method failingReconcile.

public void failingReconcile(VertxTestContext context, Labels selectorLabels) {
    MetricsProvider metrics = createCleanMetricsProvider();
    AbstractWatchableStatusedResourceOperator resourceOperator = resourceOperatorWithExistingResourceWithSelectorLabel(selectorLabels);
    AbstractOperator operator = new AbstractOperator(vertx, "TestResource", resourceOperator, metrics, selectorLabels) {

        @Override
        protected Future createOrUpdate(Reconciliation reconciliation, CustomResource resource) {
            return Future.failedFuture(new RuntimeException("Test error"));
        }

        @Override
        public Set<Condition> validate(Reconciliation reconciliation, CustomResource resource) {
            // Do nothing
            return emptySet();
        }

        @Override
        protected Future<Boolean> delete(Reconciliation reconciliation) {
            return null;
        }

        @Override
        protected Status createStatus() {
            return new Status() {
            };
        }
    };
    Checkpoint async = context.checkpoint();
    operator.reconcile(new Reconciliation("test", "TestResource", "my-namespace", "my-resource")).onComplete(context.failing(v -> context.verify(() -> {
        MeterRegistry registry = metrics.meterRegistry();
        Tag selectorTag = Tag.of("selector", selectorLabels != null ? selectorLabels.toSelectorString() : "");
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations").meter().getId().getTags().get(2), is(selectorTag));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations").tag("kind", "TestResource").counter().count(), is(1.0));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations.failed").meter().getId().getTags().get(2), is(selectorTag));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations.failed").tag("kind", "TestResource").counter().count(), is(1.0));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations.duration").meter().getId().getTags().get(2), is(selectorTag));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations.duration").tag("kind", "TestResource").timer().count(), is(1L));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations.duration").tag("kind", "TestResource").timer().totalTime(TimeUnit.MILLISECONDS), greaterThan(0.0));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "resource.state").tag("kind", "TestResource").tag("name", "my-resource").tag("resource-namespace", "my-namespace").tag("reason", "Test error").gauge().value(), is(0.0));
        async.flag();
    })));
}
Also used : Condition(io.strimzi.api.kafka.model.status.Condition) Status(io.strimzi.api.kafka.model.status.Status) VertxTestContext(io.vertx.junit5.VertxTestContext) CoreMatchers.is(org.hamcrest.CoreMatchers.is) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) MixedOperation(io.fabric8.kubernetes.client.dsl.MixedOperation) AfterAll(org.junit.jupiter.api.AfterAll) HashSet(java.util.HashSet) MicrometerMetricsOptions(io.vertx.micrometer.MicrometerMetricsOptions) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) BeforeAll(org.junit.jupiter.api.BeforeAll) Status(io.strimzi.api.kafka.model.status.Status) Collections.singletonMap(java.util.Collections.singletonMap) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Version(io.fabric8.kubernetes.model.annotation.Version) Tag(io.micrometer.core.instrument.Tag) Collections.emptyMap(java.util.Collections.emptyMap) MeterNotFoundException(io.micrometer.core.instrument.search.MeterNotFoundException) Collections.emptySet(java.util.Collections.emptySet) Promise(io.vertx.core.Promise) Vertx(io.vertx.core.Vertx) VertxOptions(io.vertx.core.VertxOptions) Set(java.util.Set) VertxPrometheusOptions(io.vertx.micrometer.VertxPrometheusOptions) VertxExtension(io.vertx.junit5.VertxExtension) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Spec(io.strimzi.api.kafka.model.Spec) Future(io.vertx.core.Future) Test(org.junit.jupiter.api.Test) TimeUnit(java.util.concurrent.TimeUnit) NamespaceAndName(io.strimzi.operator.common.model.NamespaceAndName) Labels(io.strimzi.operator.common.model.Labels) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) AbstractWatchableStatusedResourceOperator(io.strimzi.operator.common.operator.resource.AbstractWatchableStatusedResourceOperator) Group(io.fabric8.kubernetes.model.annotation.Group) Checkpoint(io.vertx.junit5.Checkpoint) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) Condition(io.strimzi.api.kafka.model.status.Condition) Collections(java.util.Collections) CustomResource(io.fabric8.kubernetes.client.CustomResource) CustomResource(io.fabric8.kubernetes.client.CustomResource) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Checkpoint(io.vertx.junit5.Checkpoint) AbstractWatchableStatusedResourceOperator(io.strimzi.operator.common.operator.resource.AbstractWatchableStatusedResourceOperator) Tag(io.micrometer.core.instrument.Tag)

Example 12 with AbstractWatchableStatusedResourceOperator

use of io.strimzi.operator.common.operator.resource.AbstractWatchableStatusedResourceOperator in project strimzi by strimzi.

the class OperatorMetricsTest method testReconcileAllOverMultipleNamespaces.

@Test
public void testReconcileAllOverMultipleNamespaces(VertxTestContext context) {
    MetricsProvider metrics = createCleanMetricsProvider();
    Set<NamespaceAndName> resources = new HashSet<>(3);
    resources.add(new NamespaceAndName("my-namespace", "avfc"));
    resources.add(new NamespaceAndName("my-namespace", "vtid"));
    resources.add(new NamespaceAndName("my-namespace2", "utv"));
    Set<NamespaceAndName> updatedResources = new HashSet<>(2);
    updatedResources.add(new NamespaceAndName("my-namespace", "avfc"));
    updatedResources.add(new NamespaceAndName("my-namespace", "vtid"));
    AbstractWatchableStatusedResourceOperator resourceOperator = resourceOperatorWithExistingResourceWithoutSelectorLabel();
    AbstractOperator operator = new ReconcileAllMockOperator(vertx, "TestResource", resourceOperator, metrics, null);
    Promise<Void> reconcileAllPromise = Promise.promise();
    ((ReconcileAllMockOperator) operator).setResources(resources);
    operator.reconcileAll("test", "*", reconcileAllPromise);
    Checkpoint async = context.checkpoint();
    reconcileAllPromise.future().onComplete(context.succeeding(v -> context.verify(() -> {
        MeterRegistry registry = metrics.meterRegistry();
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations.periodical").tag("kind", "TestResource").counter().count(), is(1.0));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations").tag("kind", "TestResource").tag("namespace", "my-namespace").counter().count(), is(2.0));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations").tag("kind", "TestResource").tag("namespace", "my-namespace2").counter().count(), is(1.0));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations.successful").tag("kind", "TestResource").tag("namespace", "my-namespace").counter().count(), is(2.0));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations.successful").tag("kind", "TestResource").tag("namespace", "my-namespace2").counter().count(), is(1.0));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations.duration").tag("kind", "TestResource").tag("namespace", "my-namespace").timer().count(), is(2L));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations.duration").tag("kind", "TestResource").tag("namespace", "my-namespace2").timer().count(), is(1L));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations.duration").tag("kind", "TestResource").tag("namespace", "my-namespace").timer().totalTime(TimeUnit.MILLISECONDS), greaterThan(0.0));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations.duration").tag("kind", "TestResource").tag("namespace", "my-namespace2").timer().totalTime(TimeUnit.MILLISECONDS), greaterThan(0.0));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "resources").tag("kind", "TestResource").tag("namespace", "my-namespace").gauge().value(), is(2.0));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "resources").tag("kind", "TestResource").tag("namespace", "my-namespace2").gauge().value(), is(1.0));
        for (NamespaceAndName resource : resources) {
            assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "resource.state").tag("kind", "TestResource").tag("name", resource.getName()).tag("resource-namespace", resource.getNamespace()).gauge().value(), is(1.0));
        }
    }))).compose(ignore -> {
        // Reconcile again with resource in my-namespace2 deleted
        Promise<Void> secondReconcileAllPromise = Promise.promise();
        ((ReconcileAllMockOperator) operator).setResources(updatedResources);
        operator.reconcileAll("test", "*", secondReconcileAllPromise);
        return secondReconcileAllPromise.future();
    }).onComplete(context.succeeding(v -> context.verify(() -> {
        MeterRegistry registry = metrics.meterRegistry();
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations.periodical").tag("kind", "TestResource").counter().count(), is(2.0));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations").tag("kind", "TestResource").tag("namespace", "my-namespace").counter().count(), is(4.0));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations").tag("kind", "TestResource").tag("namespace", "my-namespace2").counter().count(), is(1.0));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations.successful").tag("kind", "TestResource").tag("namespace", "my-namespace").counter().count(), is(4.0));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations.successful").tag("kind", "TestResource").tag("namespace", "my-namespace2").counter().count(), is(1.0));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations.duration").tag("kind", "TestResource").tag("namespace", "my-namespace").timer().count(), is(4L));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations.duration").tag("kind", "TestResource").tag("namespace", "my-namespace2").timer().count(), is(1L));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations.duration").tag("kind", "TestResource").tag("namespace", "my-namespace").timer().totalTime(TimeUnit.MILLISECONDS), greaterThan(0.0));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations.duration").tag("kind", "TestResource").tag("namespace", "my-namespace2").timer().totalTime(TimeUnit.MILLISECONDS), greaterThan(0.0));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "resources").tag("kind", "TestResource").tag("namespace", "my-namespace").gauge().value(), is(2.0));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "resources").tag("kind", "TestResource").tag("namespace", "my-namespace2").gauge().value(), is(0.0));
        for (NamespaceAndName resource : updatedResources) {
            assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "resource.state").tag("kind", "TestResource").tag("name", resource.getName()).tag("resource-namespace", resource.getNamespace()).gauge().value(), is(1.0));
        }
        async.flag();
    })));
}
Also used : VertxTestContext(io.vertx.junit5.VertxTestContext) CoreMatchers.is(org.hamcrest.CoreMatchers.is) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) MixedOperation(io.fabric8.kubernetes.client.dsl.MixedOperation) AfterAll(org.junit.jupiter.api.AfterAll) HashSet(java.util.HashSet) MicrometerMetricsOptions(io.vertx.micrometer.MicrometerMetricsOptions) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) BeforeAll(org.junit.jupiter.api.BeforeAll) Status(io.strimzi.api.kafka.model.status.Status) Collections.singletonMap(java.util.Collections.singletonMap) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Version(io.fabric8.kubernetes.model.annotation.Version) Tag(io.micrometer.core.instrument.Tag) Collections.emptyMap(java.util.Collections.emptyMap) MeterNotFoundException(io.micrometer.core.instrument.search.MeterNotFoundException) Collections.emptySet(java.util.Collections.emptySet) Promise(io.vertx.core.Promise) Vertx(io.vertx.core.Vertx) VertxOptions(io.vertx.core.VertxOptions) Set(java.util.Set) VertxPrometheusOptions(io.vertx.micrometer.VertxPrometheusOptions) VertxExtension(io.vertx.junit5.VertxExtension) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Spec(io.strimzi.api.kafka.model.Spec) Future(io.vertx.core.Future) Test(org.junit.jupiter.api.Test) TimeUnit(java.util.concurrent.TimeUnit) NamespaceAndName(io.strimzi.operator.common.model.NamespaceAndName) Labels(io.strimzi.operator.common.model.Labels) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) AbstractWatchableStatusedResourceOperator(io.strimzi.operator.common.operator.resource.AbstractWatchableStatusedResourceOperator) Group(io.fabric8.kubernetes.model.annotation.Group) Checkpoint(io.vertx.junit5.Checkpoint) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) Condition(io.strimzi.api.kafka.model.status.Condition) Collections(java.util.Collections) CustomResource(io.fabric8.kubernetes.client.CustomResource) NamespaceAndName(io.strimzi.operator.common.model.NamespaceAndName) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Promise(io.vertx.core.Promise) Checkpoint(io.vertx.junit5.Checkpoint) AbstractWatchableStatusedResourceOperator(io.strimzi.operator.common.operator.resource.AbstractWatchableStatusedResourceOperator) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 13 with AbstractWatchableStatusedResourceOperator

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

the class OperatorMetricsTest method testDeleteCountsReconcile.

@Test
public void testDeleteCountsReconcile(VertxTestContext context) {
    MetricsProvider metrics = createCleanMetricsProvider();
    AbstractWatchableStatusedResourceOperator resourceOperator = new AbstractWatchableStatusedResourceOperator(vertx, null, "TestResource") {

        @Override
        protected MixedOperation operation() {
            return null;
        }

        @Override
        public HasMetadata get(String namespace, String name) {
            return null;
        }

        @Override
        public Future updateStatusAsync(Reconciliation reconciliation, HasMetadata resource) {
            return null;
        }
    };
    AbstractOperator operator = new AbstractOperator(vertx, "TestResource", resourceOperator, metrics, null) {

        @Override
        protected Future createOrUpdate(Reconciliation reconciliation, CustomResource resource) {
            return null;
        }

        @Override
        public Set<Condition> validate(Reconciliation reconciliation, CustomResource resource) {
            // Do nothing
            return emptySet();
        }

        @Override
        protected Future<Boolean> delete(Reconciliation reconciliation) {
            return Future.succeededFuture(Boolean.TRUE);
        }

        @Override
        protected Status createStatus() {
            return new Status() {
            };
        }
    };
    Checkpoint async = context.checkpoint();
    operator.reconcile(new Reconciliation("test", "TestResource", "my-namespace", "my-resource")).onComplete(context.succeeding(v -> context.verify(() -> {
        MeterRegistry registry = metrics.meterRegistry();
        Tag selectorTag = Tag.of("selector", "");
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations").meter().getId().getTags().get(2), is(selectorTag));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations").tag("kind", "TestResource").counter().count(), is(1.0));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations.successful").meter().getId().getTags().get(2), is(selectorTag));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations.successful").tag("kind", "TestResource").counter().count(), is(1.0));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations.duration").meter().getId().getTags().get(2), is(selectorTag));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations.duration").tag("kind", "TestResource").timer().count(), is(1L));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations.duration").tag("kind", "TestResource").timer().totalTime(TimeUnit.MILLISECONDS), greaterThan(0.0));
        assertThrows(MeterNotFoundException.class, () -> {
            registry.get(AbstractOperator.METRICS_PREFIX + "resource.state").tag("kind", "TestResource").tag("name", "my-resource").tag("resource-namespace", "my-namespace").gauge();
        });
        async.flag();
    })));
}
Also used : Condition(io.strimzi.api.kafka.model.status.Condition) Status(io.strimzi.api.kafka.model.status.Status) VertxTestContext(io.vertx.junit5.VertxTestContext) CoreMatchers.is(org.hamcrest.CoreMatchers.is) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) MixedOperation(io.fabric8.kubernetes.client.dsl.MixedOperation) AfterAll(org.junit.jupiter.api.AfterAll) HashSet(java.util.HashSet) MicrometerMetricsOptions(io.vertx.micrometer.MicrometerMetricsOptions) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) BeforeAll(org.junit.jupiter.api.BeforeAll) Status(io.strimzi.api.kafka.model.status.Status) Collections.singletonMap(java.util.Collections.singletonMap) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Version(io.fabric8.kubernetes.model.annotation.Version) Tag(io.micrometer.core.instrument.Tag) Collections.emptyMap(java.util.Collections.emptyMap) MeterNotFoundException(io.micrometer.core.instrument.search.MeterNotFoundException) Collections.emptySet(java.util.Collections.emptySet) Promise(io.vertx.core.Promise) Vertx(io.vertx.core.Vertx) VertxOptions(io.vertx.core.VertxOptions) Set(java.util.Set) VertxPrometheusOptions(io.vertx.micrometer.VertxPrometheusOptions) VertxExtension(io.vertx.junit5.VertxExtension) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Spec(io.strimzi.api.kafka.model.Spec) Future(io.vertx.core.Future) Test(org.junit.jupiter.api.Test) TimeUnit(java.util.concurrent.TimeUnit) NamespaceAndName(io.strimzi.operator.common.model.NamespaceAndName) Labels(io.strimzi.operator.common.model.Labels) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) AbstractWatchableStatusedResourceOperator(io.strimzi.operator.common.operator.resource.AbstractWatchableStatusedResourceOperator) Group(io.fabric8.kubernetes.model.annotation.Group) Checkpoint(io.vertx.junit5.Checkpoint) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) Condition(io.strimzi.api.kafka.model.status.Condition) Collections(java.util.Collections) CustomResource(io.fabric8.kubernetes.client.CustomResource) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) CustomResource(io.fabric8.kubernetes.client.CustomResource) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Checkpoint(io.vertx.junit5.Checkpoint) AbstractWatchableStatusedResourceOperator(io.strimzi.operator.common.operator.resource.AbstractWatchableStatusedResourceOperator) Tag(io.micrometer.core.instrument.Tag) Test(org.junit.jupiter.api.Test)

Example 14 with AbstractWatchableStatusedResourceOperator

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

the class OperatorMetricsTest method testPauseReconcile.

@Test
public void testPauseReconcile(VertxTestContext context) {
    MetricsProvider metrics = createCleanMetricsProvider();
    AbstractWatchableStatusedResourceOperator resourceOperator = resourceOperatorWithExistingPausedResource();
    AbstractOperator operator = new AbstractOperator(vertx, "TestResource", resourceOperator, metrics, null) {

        @Override
        protected Future createOrUpdate(Reconciliation reconciliation, CustomResource resource) {
            return Future.succeededFuture();
        }

        @Override
        public Set<Condition> validate(Reconciliation reconciliation, CustomResource resource) {
            return new HashSet<>();
        }

        @Override
        protected Future<Boolean> delete(Reconciliation reconciliation) {
            return null;
        }

        @Override
        protected Status createStatus() {
            return new Status() {
            };
        }
    };
    Checkpoint async = context.checkpoint();
    operator.reconcile(new Reconciliation("test", "TestResource", "my-namespace", "my-resource")).onComplete(context.succeeding(v -> context.verify(() -> {
        MeterRegistry registry = metrics.meterRegistry();
        Tag selectorTag = Tag.of("selector", "");
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations").meter().getId().getTags().get(2), is(selectorTag));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations").tag("kind", "TestResource").counter().count(), is(1.0));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations.successful").meter().getId().getTags().get(2), is(selectorTag));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations.successful").tag("kind", "TestResource").counter().count(), is(1.0));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "resources.paused").meter().getId().getTags().get(2), is(selectorTag));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "resources.paused").tag("kind", "TestResource").gauge().value(), is(1.0));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations.duration").meter().getId().getTags().get(2), is(selectorTag));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations.duration").tag("kind", "TestResource").timer().count(), is(1L));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations.duration").tag("kind", "TestResource").timer().totalTime(TimeUnit.MILLISECONDS), greaterThan(0.0));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "resource.state").tag("kind", "TestResource").tag("name", "my-resource").tag("resource-namespace", "my-namespace").gauge().value(), is(1.0));
        async.flag();
    })));
}
Also used : Condition(io.strimzi.api.kafka.model.status.Condition) Status(io.strimzi.api.kafka.model.status.Status) VertxTestContext(io.vertx.junit5.VertxTestContext) CoreMatchers.is(org.hamcrest.CoreMatchers.is) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) MixedOperation(io.fabric8.kubernetes.client.dsl.MixedOperation) AfterAll(org.junit.jupiter.api.AfterAll) HashSet(java.util.HashSet) MicrometerMetricsOptions(io.vertx.micrometer.MicrometerMetricsOptions) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) BeforeAll(org.junit.jupiter.api.BeforeAll) Status(io.strimzi.api.kafka.model.status.Status) Collections.singletonMap(java.util.Collections.singletonMap) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Version(io.fabric8.kubernetes.model.annotation.Version) Tag(io.micrometer.core.instrument.Tag) Collections.emptyMap(java.util.Collections.emptyMap) MeterNotFoundException(io.micrometer.core.instrument.search.MeterNotFoundException) Collections.emptySet(java.util.Collections.emptySet) Promise(io.vertx.core.Promise) Vertx(io.vertx.core.Vertx) VertxOptions(io.vertx.core.VertxOptions) Set(java.util.Set) VertxPrometheusOptions(io.vertx.micrometer.VertxPrometheusOptions) VertxExtension(io.vertx.junit5.VertxExtension) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Spec(io.strimzi.api.kafka.model.Spec) Future(io.vertx.core.Future) Test(org.junit.jupiter.api.Test) TimeUnit(java.util.concurrent.TimeUnit) NamespaceAndName(io.strimzi.operator.common.model.NamespaceAndName) Labels(io.strimzi.operator.common.model.Labels) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) AbstractWatchableStatusedResourceOperator(io.strimzi.operator.common.operator.resource.AbstractWatchableStatusedResourceOperator) Group(io.fabric8.kubernetes.model.annotation.Group) Checkpoint(io.vertx.junit5.Checkpoint) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) Condition(io.strimzi.api.kafka.model.status.Condition) Collections(java.util.Collections) CustomResource(io.fabric8.kubernetes.client.CustomResource) CustomResource(io.fabric8.kubernetes.client.CustomResource) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Checkpoint(io.vertx.junit5.Checkpoint) AbstractWatchableStatusedResourceOperator(io.strimzi.operator.common.operator.resource.AbstractWatchableStatusedResourceOperator) Tag(io.micrometer.core.instrument.Tag) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 15 with AbstractWatchableStatusedResourceOperator

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

the class OperatorMetricsTest method failingReconcile.

public void failingReconcile(VertxTestContext context, Labels selectorLabels) {
    MetricsProvider metrics = createCleanMetricsProvider();
    AbstractWatchableStatusedResourceOperator resourceOperator = resourceOperatorWithExistingResourceWithSelectorLabel(selectorLabels);
    AbstractOperator operator = new AbstractOperator(vertx, "TestResource", resourceOperator, metrics, selectorLabels) {

        @Override
        protected Future createOrUpdate(Reconciliation reconciliation, CustomResource resource) {
            return Future.failedFuture(new RuntimeException("Test error"));
        }

        @Override
        public Set<Condition> validate(Reconciliation reconciliation, CustomResource resource) {
            // Do nothing
            return emptySet();
        }

        @Override
        protected Future<Boolean> delete(Reconciliation reconciliation) {
            return null;
        }

        @Override
        protected Status createStatus() {
            return new Status() {
            };
        }
    };
    Checkpoint async = context.checkpoint();
    operator.reconcile(new Reconciliation("test", "TestResource", "my-namespace", "my-resource")).onComplete(context.failing(v -> context.verify(() -> {
        MeterRegistry registry = metrics.meterRegistry();
        Tag selectorTag = Tag.of("selector", selectorLabels != null ? selectorLabels.toSelectorString() : "");
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations").meter().getId().getTags().get(2), is(selectorTag));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations").tag("kind", "TestResource").counter().count(), is(1.0));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations.failed").meter().getId().getTags().get(2), is(selectorTag));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations.failed").tag("kind", "TestResource").counter().count(), is(1.0));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations.duration").meter().getId().getTags().get(2), is(selectorTag));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations.duration").tag("kind", "TestResource").timer().count(), is(1L));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations.duration").tag("kind", "TestResource").timer().totalTime(TimeUnit.MILLISECONDS), greaterThan(0.0));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "resource.state").tag("kind", "TestResource").tag("name", "my-resource").tag("resource-namespace", "my-namespace").tag("reason", "Test error").gauge().value(), is(0.0));
        async.flag();
    })));
}
Also used : Condition(io.strimzi.api.kafka.model.status.Condition) Status(io.strimzi.api.kafka.model.status.Status) VertxTestContext(io.vertx.junit5.VertxTestContext) CoreMatchers.is(org.hamcrest.CoreMatchers.is) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) MixedOperation(io.fabric8.kubernetes.client.dsl.MixedOperation) AfterAll(org.junit.jupiter.api.AfterAll) HashSet(java.util.HashSet) MicrometerMetricsOptions(io.vertx.micrometer.MicrometerMetricsOptions) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) BeforeAll(org.junit.jupiter.api.BeforeAll) Status(io.strimzi.api.kafka.model.status.Status) Collections.singletonMap(java.util.Collections.singletonMap) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Version(io.fabric8.kubernetes.model.annotation.Version) Tag(io.micrometer.core.instrument.Tag) Collections.emptyMap(java.util.Collections.emptyMap) MeterNotFoundException(io.micrometer.core.instrument.search.MeterNotFoundException) Collections.emptySet(java.util.Collections.emptySet) Promise(io.vertx.core.Promise) Vertx(io.vertx.core.Vertx) VertxOptions(io.vertx.core.VertxOptions) Set(java.util.Set) VertxPrometheusOptions(io.vertx.micrometer.VertxPrometheusOptions) VertxExtension(io.vertx.junit5.VertxExtension) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Spec(io.strimzi.api.kafka.model.Spec) Future(io.vertx.core.Future) Test(org.junit.jupiter.api.Test) TimeUnit(java.util.concurrent.TimeUnit) NamespaceAndName(io.strimzi.operator.common.model.NamespaceAndName) Labels(io.strimzi.operator.common.model.Labels) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) AbstractWatchableStatusedResourceOperator(io.strimzi.operator.common.operator.resource.AbstractWatchableStatusedResourceOperator) Group(io.fabric8.kubernetes.model.annotation.Group) Checkpoint(io.vertx.junit5.Checkpoint) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) Condition(io.strimzi.api.kafka.model.status.Condition) Collections(java.util.Collections) CustomResource(io.fabric8.kubernetes.client.CustomResource) CustomResource(io.fabric8.kubernetes.client.CustomResource) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Checkpoint(io.vertx.junit5.Checkpoint) AbstractWatchableStatusedResourceOperator(io.strimzi.operator.common.operator.resource.AbstractWatchableStatusedResourceOperator) Tag(io.micrometer.core.instrument.Tag)

Aggregations

HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)16 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)16 Group (io.fabric8.kubernetes.model.annotation.Group)16 Version (io.fabric8.kubernetes.model.annotation.Version)16 Spec (io.strimzi.api.kafka.model.Spec)16 AbstractWatchableStatusedResourceOperator (io.strimzi.operator.common.operator.resource.AbstractWatchableStatusedResourceOperator)16 CustomResource (io.fabric8.kubernetes.client.CustomResource)14 MixedOperation (io.fabric8.kubernetes.client.dsl.MixedOperation)14 MeterRegistry (io.micrometer.core.instrument.MeterRegistry)14 Tag (io.micrometer.core.instrument.Tag)14 MeterNotFoundException (io.micrometer.core.instrument.search.MeterNotFoundException)14 Condition (io.strimzi.api.kafka.model.status.Condition)14 Status (io.strimzi.api.kafka.model.status.Status)14 Labels (io.strimzi.operator.common.model.Labels)14 NamespaceAndName (io.strimzi.operator.common.model.NamespaceAndName)14 Future (io.vertx.core.Future)14 Promise (io.vertx.core.Promise)14 Vertx (io.vertx.core.Vertx)14 VertxOptions (io.vertx.core.VertxOptions)14 Checkpoint (io.vertx.junit5.Checkpoint)14