Search in sources :

Example 1 with CanaryService

use of org.bf2.operator.clients.canary.CanaryService in project kas-fleetshard by bf2fc6cc711aee1a0c2a.

the class CanaryTest method createCanaryService.

@Test
void createCanaryService() throws Exception {
    ManagedKafka mk = new ManagedKafkaBuilder().withNewMetadata().withNamespace("test").withName("test-mk").endMetadata().withSpec(new ManagedKafkaSpecBuilder().withNewVersions().withKafka("2.6.0").endVersions().withNewEndpoint().withBootstrapServerHost("test-mk-kafka-bootstrap").endEndpoint().build()).build();
    Service canaryService = canary.serviceFrom(mk, null);
    server.getClient().services().create(canaryService);
    assertNotNull(server.getClient().services().inNamespace(canaryService.getMetadata().getNamespace()).withName(canaryService.getMetadata().getName()).get());
    KafkaClusterTest.diffToExpected(canaryService, "/expected/canary-service.yml");
}
Also used : ManagedKafka(org.bf2.operator.resources.v1alpha1.ManagedKafka) ManagedKafkaSpecBuilder(org.bf2.operator.resources.v1alpha1.ManagedKafkaSpecBuilder) Service(io.fabric8.kubernetes.api.model.Service) ManagedKafkaBuilder(org.bf2.operator.resources.v1alpha1.ManagedKafkaBuilder) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with CanaryService

use of org.bf2.operator.clients.canary.CanaryService in project kas-fleetshard by bf2fc6cc711aee1a0c2a.

the class KafkaManager method doKafkaUpgradeStabilityCheck.

/**
 * Scheduled job to execute the Kafka stability check
 *
 * @param managedKafka ManagedKafka instance
 */
void doKafkaUpgradeStabilityCheck(ManagedKafka managedKafka) {
    log.infof("[%s/%s] Kafka upgrade stability check", managedKafka.getMetadata().getNamespace(), managedKafka.getMetadata().getName());
    CanaryService canaryService = RestClientBuilder.newBuilder().baseUri(URI.create("http://" + AbstractCanary.canaryName(managedKafka) + "." + managedKafka.getMetadata().getNamespace() + ":8080")).connectTimeout(10, TimeUnit.SECONDS).readTimeout(30, TimeUnit.SECONDS).build(CanaryService.class);
    try {
        Status status = canaryService.getStatus();
        log.infof("[%s/%s] Canary status: timeWindow %d - percentage %d", managedKafka.getMetadata().getNamespace(), managedKafka.getMetadata().getName(), status.getConsuming().getTimeWindow(), status.getConsuming().getPercentage());
        if (status.getConsuming().getPercentage() > consumingPercentageThreshold) {
            log.debugf("[%s/%s] Remove Kafka upgrade start/end annotations", managedKafka.getMetadata().getNamespace(), managedKafka.getMetadata().getName());
            managedKafkaClient.inNamespace(managedKafka.getMetadata().getNamespace()).withName(managedKafka.getMetadata().getName()).edit(mk -> new ManagedKafkaBuilder(mk).editMetadata().removeFromAnnotations(KAFKA_UPGRADE_START_TIMESTAMP_ANNOTATION).removeFromAnnotations(KAFKA_UPGRADE_END_TIMESTAMP_ANNOTATION).endMetadata().build());
        } else {
            log.warnf("[%s/%s] Reported consuming percentage %d less than %d threshold", managedKafka.getMetadata().getNamespace(), managedKafka.getMetadata().getName(), status.getConsuming().getPercentage(), consumingPercentageThreshold);
            managedKafkaClient.inNamespace(managedKafka.getMetadata().getNamespace()).withName(managedKafka.getMetadata().getName()).edit(mk -> new ManagedKafkaBuilder(mk).editMetadata().removeFromAnnotations(KAFKA_UPGRADE_END_TIMESTAMP_ANNOTATION).endMetadata().build());
        }
        // trigger a reconcile on the ManagedKafka instance to push checking if next step
        // Kafka IBP upgrade is needed or another stability check
        informerManager.resyncManagedKafka(managedKafka);
    } catch (Exception e) {
        log.errorf("[%s/%s] Error while checking Kafka upgrade stability", managedKafka.getMetadata().getNamespace(), managedKafka.getMetadata().getName(), e);
    }
}
Also used : Status(org.bf2.operator.clients.canary.Status) CanaryService(org.bf2.operator.clients.canary.CanaryService) ManagedKafkaBuilder(org.bf2.operator.resources.v1alpha1.ManagedKafkaBuilder) SchedulerException(org.quartz.SchedulerException)

Aggregations

ManagedKafkaBuilder (org.bf2.operator.resources.v1alpha1.ManagedKafkaBuilder)2 Service (io.fabric8.kubernetes.api.model.Service)1 QuarkusTest (io.quarkus.test.junit.QuarkusTest)1 CanaryService (org.bf2.operator.clients.canary.CanaryService)1 Status (org.bf2.operator.clients.canary.Status)1 ManagedKafka (org.bf2.operator.resources.v1alpha1.ManagedKafka)1 ManagedKafkaSpecBuilder (org.bf2.operator.resources.v1alpha1.ManagedKafkaSpecBuilder)1 Test (org.junit.jupiter.api.Test)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 SchedulerException (org.quartz.SchedulerException)1