Search in sources :

Example 21 with KRaftNotSupported

use of io.strimzi.systemtest.annotations.KRaftNotSupported in project strimzi by strimzi.

the class CruiseControlST method testCruiseControlTopicExclusion.

@ParallelNamespaceTest
@KRaftNotSupported("TopicOperator is not supported by KRaft mode and is used in this test class")
void testCruiseControlTopicExclusion(ExtensionContext extensionContext) {
    final String namespaceName = StUtils.getNamespaceBasedOnRbac(namespace, extensionContext);
    final String clusterName = mapWithClusterNames.get(extensionContext.getDisplayName());
    final String excludedTopic1 = "excluded-topic-1";
    final String excludedTopic2 = "excluded-topic-2";
    final String includedTopic = "included-topic";
    resourceManager.createResource(extensionContext, KafkaTemplates.kafkaWithCruiseControl(clusterName, 3, 1).build());
    resourceManager.createResource(extensionContext, KafkaTopicTemplates.topic(clusterName, excludedTopic1, namespaceName).build());
    resourceManager.createResource(extensionContext, KafkaTopicTemplates.topic(clusterName, excludedTopic2, namespaceName).build());
    resourceManager.createResource(extensionContext, KafkaTopicTemplates.topic(clusterName, includedTopic, namespaceName).build());
    resourceManager.createResource(extensionContext, KafkaRebalanceTemplates.kafkaRebalance(clusterName).editOrNewSpec().withExcludedTopics("excluded-.*").endSpec().build());
    KafkaRebalanceUtils.waitForKafkaRebalanceCustomResourceState(namespaceName, clusterName, KafkaRebalanceState.ProposalReady);
    LOGGER.info("Checking status of KafkaRebalance");
    KafkaRebalanceStatus kafkaRebalanceStatus = KafkaRebalanceResource.kafkaRebalanceClient().inNamespace(namespaceName).withName(clusterName).get().getStatus();
    assertThat(kafkaRebalanceStatus.getOptimizationResult().get("excludedTopics").toString(), containsString(excludedTopic1));
    assertThat(kafkaRebalanceStatus.getOptimizationResult().get("excludedTopics").toString(), containsString(excludedTopic2));
    assertThat(kafkaRebalanceStatus.getOptimizationResult().get("excludedTopics").toString(), not(containsString(includedTopic)));
    KafkaRebalanceUtils.annotateKafkaRebalanceResource(new Reconciliation("test", KafkaRebalance.RESOURCE_KIND, namespace, clusterName), namespaceName, clusterName, KafkaRebalanceAnnotation.approve);
    KafkaRebalanceUtils.waitForKafkaRebalanceCustomResourceState(namespaceName, clusterName, KafkaRebalanceState.Ready);
}
Also used : KafkaRebalanceStatus(io.strimzi.api.kafka.model.status.KafkaRebalanceStatus) Reconciliation(io.strimzi.operator.common.Reconciliation) Matchers.containsString(org.hamcrest.Matchers.containsString) KRaftNotSupported(io.strimzi.systemtest.annotations.KRaftNotSupported) ParallelNamespaceTest(io.strimzi.systemtest.annotations.ParallelNamespaceTest)

Example 22 with KRaftNotSupported

use of io.strimzi.systemtest.annotations.KRaftNotSupported in project strimzi by strimzi.

the class LoggingChangeST method testJSONFormatLogging.

@ParallelNamespaceTest
@KRaftNotSupported("Debug needed - https://github.com/strimzi/strimzi-kafka-operator/issues/6863")
@SuppressWarnings({ "checkstyle:MethodLength" })
void testJSONFormatLogging(ExtensionContext extensionContext) {
    final String namespaceName = StUtils.getNamespaceBasedOnRbac(namespace, extensionContext);
    final String clusterName = mapWithClusterNames.get(extensionContext.getDisplayName());
    final LabelSelector kafkaSelector = KafkaResource.getLabelSelector(clusterName, KafkaResources.kafkaStatefulSetName(clusterName));
    final LabelSelector zkSelector = KafkaResource.getLabelSelector(clusterName, KafkaResources.zookeeperStatefulSetName(clusterName));
    // In this test scenario we change configuration for CO and we have to be sure, that CO is installed via YAML bundle instead of helm or OLM
    assumeTrue(!Environment.isHelmInstall() && !Environment.isOlmInstall());
    String loggersConfigKafka = "log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender\n" + "log4j.appender.CONSOLE.layout=net.logstash.log4j.JSONEventLayoutV1\n" + "kafka.root.logger.level=INFO\n" + "log4j.rootLogger=${kafka.root.logger.level}, CONSOLE\n" + "log4j.logger.org.I0Itec.zkclient.ZkClient=INFO\n" + "log4j.logger.org.apache.zookeeper=INFO\n" + "log4j.logger.kafka=INFO\n" + "log4j.logger.org.apache.kafka=INFO\n" + "log4j.logger.kafka.request.logger=WARN, CONSOLE\n" + "log4j.logger.kafka.network.Processor=OFF\n" + "log4j.logger.kafka.server.KafkaApis=OFF\n" + "log4j.logger.kafka.network.RequestChannel$=WARN\n" + "log4j.logger.kafka.controller=TRACE\n" + "log4j.logger.kafka.log.LogCleaner=INFO\n" + "log4j.logger.state.change.logger=TRACE\n" + "log4j.logger.kafka.authorizer.logger=INFO";
    String loggersConfigOperators = "appender.console.type=Console\n" + "appender.console.name=STDOUT\n" + "appender.console.layout.type=JsonLayout\n" + "rootLogger.level=INFO\n" + "rootLogger.appenderRefs=stdout\n" + "rootLogger.appenderRef.console.ref=STDOUT\n" + "rootLogger.additivity=false";
    String loggersConfigZookeeper = "log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender\n" + "log4j.appender.CONSOLE.layout=net.logstash.log4j.JSONEventLayoutV1\n" + "zookeeper.root.logger=INFO\n" + "log4j.rootLogger=${zookeeper.root.logger}, CONSOLE";
    String loggersConfigCO = "name = COConfig\n" + "appender.console.type = Console\n" + "appender.console.name = STDOUT\n" + "appender.console.layout.type = JsonLayout\n" + "rootLogger.level = ${env:STRIMZI_LOG_LEVEL:-INFO}\n" + "rootLogger.appenderRefs = stdout\n" + "rootLogger.appenderRef.console.ref = STDOUT\n" + "rootLogger.additivity = false\n" + "logger.kafka.name = org.apache.kafka\n" + "logger.kafka.level = ${env:STRIMZI_AC_LOG_LEVEL:-WARN}\n" + "logger.kafka.additivity = false";
    String configMapOpName = "json-layout-operators";
    String configMapZookeeperName = "json-layout-zookeeper";
    String configMapKafkaName = "json-layout-kafka";
    String configMapCOName = Constants.STRIMZI_DEPLOYMENT_NAME;
    String originalCoLoggers = kubeClient().getClient().configMaps().inNamespace(clusterOperator.getDeploymentNamespace()).withName(configMapCOName).get().getData().get("log4j2.properties");
    ConfigMap configMapKafka = new ConfigMapBuilder().withNewMetadata().withName(configMapKafkaName).withNamespace(namespaceName).endMetadata().addToData("log4j.properties", loggersConfigKafka).build();
    ConfigMapKeySelector kafkaLoggingCMselector = new ConfigMapKeySelectorBuilder().withName(configMapKafkaName).withKey("log4j.properties").build();
    ConfigMap configMapOperators = new ConfigMapBuilder().withNewMetadata().withName(configMapOpName).withNamespace(namespaceName).endMetadata().addToData("log4j2.properties", loggersConfigOperators).build();
    ConfigMapKeySelector operatorsLoggimgCMselector = new ConfigMapKeySelectorBuilder().withName(configMapOpName).withKey("log4j2.properties").build();
    ConfigMap configMapZookeeper = new ConfigMapBuilder().withNewMetadata().withName(configMapZookeeperName).withNamespace(namespaceName).endMetadata().addToData("log4j-custom.properties", loggersConfigZookeeper).build();
    ConfigMapKeySelector zkLoggingCMselector = new ConfigMapKeySelectorBuilder().withName(configMapZookeeperName).withKey("log4j-custom.properties").build();
    ConfigMap configMapCO = new ConfigMapBuilder().withNewMetadata().withName(configMapCOName).withNamespace(clusterOperator.getDeploymentNamespace()).endMetadata().addToData("log4j2.properties", loggersConfigCO).build();
    kubeClient().getClient().configMaps().inNamespace(namespaceName).createOrReplace(configMapKafka);
    kubeClient().getClient().configMaps().inNamespace(namespaceName).createOrReplace(configMapOperators);
    kubeClient().getClient().configMaps().inNamespace(namespaceName).createOrReplace(configMapZookeeper);
    kubeClient().getClient().configMaps().inNamespace(namespaceName).createOrReplace(configMapOperators);
    kubeClient().getClient().configMaps().inNamespace(clusterOperator.getDeploymentNamespace()).createOrReplace(configMapCO);
    resourceManager.createResource(extensionContext, KafkaTemplates.kafkaPersistent(clusterName, 3, 3).editOrNewSpec().editKafka().withLogging(new ExternalLoggingBuilder().withNewValueFrom().withConfigMapKeyRef(kafkaLoggingCMselector).endValueFrom().build()).endKafka().editZookeeper().withLogging(new ExternalLoggingBuilder().withNewValueFrom().withConfigMapKeyRef(zkLoggingCMselector).endValueFrom().build()).endZookeeper().editEntityOperator().editTopicOperator().withLogging(new ExternalLoggingBuilder().withNewValueFrom().withConfigMapKeyRef(operatorsLoggimgCMselector).endValueFrom().build()).endTopicOperator().editUserOperator().withLogging(new ExternalLoggingBuilder().withNewValueFrom().withConfigMapKeyRef(operatorsLoggimgCMselector).endValueFrom().build()).endUserOperator().endEntityOperator().endSpec().build());
    Map<String, String> zkPods = PodUtils.podSnapshot(namespaceName, zkSelector);
    Map<String, String> kafkaPods = PodUtils.podSnapshot(namespaceName, kafkaSelector);
    Map<String, String> eoPods = null;
    if (!Environment.isKRaftModeEnabled()) {
        eoPods = DeploymentUtils.depSnapshot(namespaceName, KafkaResources.entityOperatorDeploymentName(clusterName));
    }
    Map<String, String> operatorSnapshot = DeploymentUtils.depSnapshot(clusterOperator.getDeploymentNamespace(), ResourceManager.getCoDeploymentName());
    StUtils.checkLogForJSONFormat(clusterOperator.getDeploymentNamespace(), operatorSnapshot, ResourceManager.getCoDeploymentName());
    StUtils.checkLogForJSONFormat(namespaceName, kafkaPods, "kafka");
    StUtils.checkLogForJSONFormat(namespaceName, zkPods, "zookeeper");
    if (!Environment.isKRaftModeEnabled()) {
        StUtils.checkLogForJSONFormat(namespaceName, eoPods, "topic-operator");
        StUtils.checkLogForJSONFormat(namespaceName, eoPods, "user-operator");
    }
    // set loggers of CO back to original
    configMapCO.getData().put("log4j2.properties", originalCoLoggers);
    kubeClient().getClient().configMaps().inNamespace(clusterOperator.getDeploymentNamespace()).createOrReplace(configMapCO);
}
Also used : ExternalLoggingBuilder(io.strimzi.api.kafka.model.ExternalLoggingBuilder) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) ConfigMapKeySelectorBuilder(io.fabric8.kubernetes.api.model.ConfigMapKeySelectorBuilder) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) LabelSelector(io.fabric8.kubernetes.api.model.LabelSelector) ConfigMapKeySelector(io.fabric8.kubernetes.api.model.ConfigMapKeySelector) KRaftNotSupported(io.strimzi.systemtest.annotations.KRaftNotSupported) ParallelNamespaceTest(io.strimzi.systemtest.annotations.ParallelNamespaceTest)

Example 23 with KRaftNotSupported

use of io.strimzi.systemtest.annotations.KRaftNotSupported in project strimzi by strimzi.

the class LoggingChangeST method testDynamicallySetEOloggingLevels.

@ParallelNamespaceTest
@Tag(ROLLING_UPDATE)
@KRaftNotSupported("TopicOperator is not supported by KRaft mode and is used in this test class")
@SuppressWarnings({ "checkstyle:MethodLength", "checkstyle:CyclomaticComplexity" })
void testDynamicallySetEOloggingLevels(ExtensionContext extensionContext) {
    final String namespaceName = StUtils.getNamespaceBasedOnRbac(namespace, extensionContext);
    final String clusterName = mapWithClusterNames.get(extensionContext.getDisplayName());
    InlineLogging ilOff = new InlineLogging();
    ilOff.setLoggers(Collections.singletonMap("rootLogger.level", "OFF"));
    resourceManager.createResource(extensionContext, KafkaTemplates.kafkaPersistent(clusterName, 1, 1).editSpec().editEntityOperator().editTopicOperator().withInlineLogging(ilOff).endTopicOperator().editUserOperator().withInlineLogging(ilOff).endUserOperator().endEntityOperator().endSpec().build());
    String eoDeploymentName = KafkaResources.entityOperatorDeploymentName(clusterName);
    Map<String, String> eoPods = DeploymentUtils.depSnapshot(namespaceName, eoDeploymentName);
    final String eoPodName = eoPods.keySet().iterator().next();
    LOGGER.info("Checking if EO pod contains any log (except configuration)");
    assertFalse(DEFAULT_LOG4J_PATTERN.matcher(StUtils.getLogFromPodByTime(namespaceName, eoPodName, "user-operator", "30s")).find());
    LOGGER.info("Changing rootLogger level to DEBUG with inline logging");
    InlineLogging ilDebug = new InlineLogging();
    ilDebug.setLoggers(Collections.singletonMap("rootLogger.level", "DEBUG"));
    KafkaResource.replaceKafkaResourceInSpecificNamespace(clusterName, k -> {
        k.getSpec().getEntityOperator().getTopicOperator().setLogging(ilDebug);
        k.getSpec().getEntityOperator().getUserOperator().setLogging(ilDebug);
    }, namespaceName);
    LOGGER.info("Waiting for log4j2.properties will contain desired settings");
    TestUtils.waitFor("Logger change", Constants.GLOBAL_POLL_INTERVAL, Constants.GLOBAL_TIMEOUT, () -> cmdKubeClient().namespace(namespaceName).execInPodContainer(Level.TRACE, eoPodName, "topic-operator", "cat", "/opt/topic-operator/custom-config/log4j2.properties").out().contains("rootLogger.level=DEBUG") && cmdKubeClient().namespace(namespaceName).execInPodContainer(Level.TRACE, eoPodName, "user-operator", "cat", "/opt/user-operator/custom-config/log4j2.properties").out().contains("rootLogger.level=DEBUG"));
    TestUtils.waitFor("log to not be empty", Duration.ofMillis(100).toMillis(), Constants.SAFETY_RECONCILIATION_INTERVAL, () -> {
        String uoLog = StUtils.getLogFromPodByTime(namespaceName, eoPodName, "user-operator", "30s");
        String toLog = StUtils.getLogFromPodByTime(namespaceName, eoPodName, "topic-operator", "30s");
        return uoLog != null && toLog != null && !(uoLog.isEmpty() && toLog.isEmpty()) && DEFAULT_LOG4J_PATTERN.matcher(uoLog).find() && DEFAULT_LOG4J_PATTERN.matcher(toLog).find();
    });
    LOGGER.info("Setting external logging OFF");
    ConfigMap configMapTo = new ConfigMapBuilder().withNewMetadata().withName("external-configmap-to").withNamespace(namespaceName).endMetadata().withData(Collections.singletonMap("log4j2.properties", "name=TOConfig\n" + "appender.console.type=Console\n" + "appender.console.name=STDOUT\n" + "appender.console.layout.type=PatternLayout\n" + "appender.console.layout.pattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n\n" + "rootLogger.level=OFF\n" + "rootLogger.appenderRefs=stdout\n" + "rootLogger.appenderRef.console.ref=STDOUT\n" + "rootLogger.additivity=false")).build();
    ConfigMap configMapUo = new ConfigMapBuilder().withNewMetadata().withName("external-configmap-uo").withNamespace(namespaceName).endMetadata().addToData(Collections.singletonMap("log4j2.properties", "name=UOConfig\n" + "appender.console.type=Console\n" + "appender.console.name=STDOUT\n" + "appender.console.layout.type=PatternLayout\n" + "appender.console.layout.pattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n\n" + "rootLogger.level=OFF\n" + "rootLogger.appenderRefs=stdout\n" + "rootLogger.appenderRef.console.ref=STDOUT\n" + "rootLogger.additivity=false")).build();
    kubeClient().getClient().configMaps().inNamespace(namespaceName).createOrReplace(configMapTo);
    kubeClient().getClient().configMaps().inNamespace(namespaceName).createOrReplace(configMapUo);
    ExternalLogging elTo = new ExternalLoggingBuilder().withNewValueFrom().withConfigMapKeyRef(new ConfigMapKeySelectorBuilder().withName("external-configmap-to").withKey("log4j2.properties").build()).endValueFrom().build();
    ExternalLogging elUo = new ExternalLoggingBuilder().withNewValueFrom().withConfigMapKeyRef(new ConfigMapKeySelectorBuilder().withName("external-configmap-uo").withKey("log4j2.properties").build()).endValueFrom().build();
    LOGGER.info("Setting log level of TO and UO to OFF - records should not appear in log");
    // change to external logging
    KafkaResource.replaceKafkaResourceInSpecificNamespace(clusterName, k -> {
        k.getSpec().getEntityOperator().getTopicOperator().setLogging(elTo);
        k.getSpec().getEntityOperator().getUserOperator().setLogging(elUo);
    }, namespaceName);
    LOGGER.info("Waiting for log4j2.properties will contain desired settings");
    TestUtils.waitFor("Logger change", Constants.GLOBAL_POLL_INTERVAL, Constants.GLOBAL_TIMEOUT, () -> cmdKubeClient().namespace(namespaceName).execInPodContainer(Level.TRACE, eoPodName, "topic-operator", "cat", "/opt/topic-operator/custom-config/log4j2.properties").out().contains("rootLogger.level=OFF") && cmdKubeClient().namespace(namespaceName).execInPodContainer(Level.TRACE, eoPodName, "user-operator", "cat", "/opt/user-operator/custom-config/log4j2.properties").out().contains("rootLogger.level=OFF") && cmdKubeClient().namespace(namespaceName).execInPodContainer(Level.TRACE, eoPodName, "topic-operator", "cat", "/opt/topic-operator/custom-config/log4j2.properties").out().contains("monitorInterval=30") && cmdKubeClient().namespace(namespaceName).execInPodContainer(Level.TRACE, eoPodName, "user-operator", "cat", "/opt/user-operator/custom-config/log4j2.properties").out().contains("monitorInterval=30"));
    TestUtils.waitFor("log to be empty", Duration.ofMillis(100).toMillis(), Constants.SAFETY_RECONCILIATION_INTERVAL, () -> {
        String uoLog = StUtils.getLogFromPodByTime(namespaceName, eoPodName, "user-operator", "30s");
        String toLog = StUtils.getLogFromPodByTime(namespaceName, eoPodName, "topic-operator", "30s");
        return uoLog != null && toLog != null && uoLog.isEmpty() && toLog.isEmpty() && !(DEFAULT_LOG4J_PATTERN.matcher(uoLog).find() && DEFAULT_LOG4J_PATTERN.matcher(toLog).find());
    });
    LOGGER.info("Setting external logging OFF");
    configMapTo = new ConfigMapBuilder().withNewMetadata().withName("external-configmap-to").withNamespace(namespaceName).endMetadata().withData(Collections.singletonMap("log4j2.properties", "name=TOConfig\n" + "appender.console.type=Console\n" + "appender.console.name=STDOUT\n" + "appender.console.layout.type=PatternLayout\n" + "appender.console.layout.pattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n\n" + "rootLogger.level=DEBUG\n" + "rootLogger.appenderRefs=stdout\n" + "rootLogger.appenderRef.console.ref=STDOUT\n" + "rootLogger.additivity=false")).build();
    configMapUo = new ConfigMapBuilder().withNewMetadata().withName("external-configmap-uo").withNamespace(namespaceName).endMetadata().addToData(Collections.singletonMap("log4j2.properties", "name=UOConfig\n" + "appender.console.type=Console\n" + "appender.console.name=STDOUT\n" + "appender.console.layout.type=PatternLayout\n" + "appender.console.layout.pattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n\n" + "rootLogger.level=DEBUG\n" + "rootLogger.appenderRefs=stdout\n" + "rootLogger.appenderRef.console.ref=STDOUT\n" + "rootLogger.additivity=false")).build();
    kubeClient().getClient().configMaps().inNamespace(namespaceName).createOrReplace(configMapTo);
    kubeClient().getClient().configMaps().inNamespace(namespaceName).createOrReplace(configMapUo);
    LOGGER.info("Waiting for log4j2.properties will contain desired settings");
    TestUtils.waitFor("Logger change", Constants.GLOBAL_POLL_INTERVAL, Constants.GLOBAL_TIMEOUT, () -> cmdKubeClient().namespace(namespaceName).execInPodContainer(Level.TRACE, eoPodName, "topic-operator", "cat", "/opt/topic-operator/custom-config/log4j2.properties").out().contains("rootLogger.level=DEBUG") && cmdKubeClient().namespace(namespaceName).execInPodContainer(Level.TRACE, eoPodName, "user-operator", "cat", "/opt/user-operator/custom-config/log4j2.properties").out().contains("rootLogger.level=DEBUG"));
    TestUtils.waitFor("log to not be empty", Duration.ofMillis(100).toMillis(), Constants.SAFETY_RECONCILIATION_INTERVAL, () -> {
        String uoLog = StUtils.getLogFromPodByTime(namespaceName, eoPodName, "user-operator", "30s");
        String toLog = StUtils.getLogFromPodByTime(namespaceName, eoPodName, "topic-operator", "30s");
        return uoLog != null && toLog != null && !(uoLog.isEmpty() && toLog.isEmpty()) && DEFAULT_LOG4J_PATTERN.matcher(uoLog).find() && DEFAULT_LOG4J_PATTERN.matcher(toLog).find();
    });
    assertThat("EO pod should not roll", DeploymentUtils.depSnapshot(namespaceName, eoDeploymentName), equalTo(eoPods));
}
Also used : ExternalLoggingBuilder(io.strimzi.api.kafka.model.ExternalLoggingBuilder) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) ExternalLogging(io.strimzi.api.kafka.model.ExternalLogging) ConfigMapKeySelectorBuilder(io.fabric8.kubernetes.api.model.ConfigMapKeySelectorBuilder) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) InlineLogging(io.strimzi.api.kafka.model.InlineLogging) KRaftNotSupported(io.strimzi.systemtest.annotations.KRaftNotSupported) ParallelNamespaceTest(io.strimzi.systemtest.annotations.ParallelNamespaceTest) Tag(org.junit.jupiter.api.Tag)

Example 24 with KRaftNotSupported

use of io.strimzi.systemtest.annotations.KRaftNotSupported in project strimzi by strimzi.

the class JmxIsolatedST method testKafkaZookeeperAndKafkaConnectWithJMX.

@ParallelNamespaceTest
@Tag(CONNECT)
@Tag(CONNECT_COMPONENTS)
@KRaftNotSupported("Debug needed - https://github.com/strimzi/strimzi-kafka-operator/issues/6863")
void testKafkaZookeeperAndKafkaConnectWithJMX(ExtensionContext extensionContext) {
    final String clusterName = mapWithClusterNames.get(extensionContext.getDisplayName());
    final String scraperName = mapWithScraperNames.get(extensionContext.getDisplayName());
    final String namespaceName = StUtils.getNamespaceBasedOnRbac(clusterOperator.getDeploymentNamespace(), extensionContext);
    final String zkSecretName = clusterName + "-zookeeper-jmx";
    final String connectJmxSecretName = clusterName + "-kafka-connect-jmx";
    final String kafkaJmxSecretName = clusterName + "-kafka-jmx";
    Map<String, String> jmxSecretLabels = Collections.singletonMap("my-label", "my-value");
    Map<String, String> jmxSecretAnnotations = Collections.singletonMap("my-annotation", "some-value");
    resourceManager.createResource(extensionContext, KafkaTemplates.kafkaEphemeral(clusterName, 3).editOrNewSpec().editKafka().withNewJmxOptions().withAuthentication(new KafkaJmxAuthenticationPassword()).endJmxOptions().endKafka().editOrNewZookeeper().withNewJmxOptions().withAuthentication(new KafkaJmxAuthenticationPassword()).endJmxOptions().editOrNewTemplate().withNewJmxSecret().withNewMetadata().withLabels(jmxSecretLabels).withAnnotations(jmxSecretAnnotations).endMetadata().endJmxSecret().endTemplate().endZookeeper().endSpec().build());
    resourceManager.createResource(extensionContext, ScraperTemplates.scraperPod(namespaceName, scraperName).build());
    String scraperPodName = kubeClient().listPodsByPrefixInName(scraperName).get(0).getMetadata().getName();
    JmxUtils.downloadJmxTermToPod(namespaceName, scraperPodName);
    resourceManager.createResource(extensionContext, KafkaConnectTemplates.kafkaConnect(clusterName, 1).editOrNewSpec().withNewJmxOptions().withAuthentication(new KafkaJmxAuthenticationPassword()).endJmxOptions().endSpec().build());
    String kafkaResults = JmxUtils.collectJmxMetricsWithWait(namespaceName, KafkaResources.brokersServiceName(clusterName), kafkaJmxSecretName, scraperPodName, "bean kafka.server:type=app-info\nget -i *");
    String kafkaConnectResults = JmxUtils.collectJmxMetricsWithWait(namespaceName, KafkaConnectResources.serviceName(clusterName), connectJmxSecretName, scraperPodName, "bean kafka.connect:type=app-info\nget -i *");
    assertThat("Result from Kafka JMX doesn't contain right version of Kafka, result: " + kafkaResults, kafkaResults, containsString("version = " + Environment.ST_KAFKA_VERSION));
    assertThat("Result from KafkaConnect JMX doesn't contain right version of Kafka, result: " + kafkaConnectResults, kafkaConnectResults, containsString("version = " + Environment.ST_KAFKA_VERSION));
    if (!Environment.isKRaftModeEnabled()) {
        Secret jmxZkSecret = kubeClient().getSecret(namespaceName, zkSecretName);
        String zkBeans = JmxUtils.collectJmxMetricsWithWait(namespaceName, KafkaResources.zookeeperHeadlessServiceName(clusterName), zkSecretName, scraperPodName, "domain org.apache.ZooKeeperService\nbeans");
        String zkBean = Arrays.asList(zkBeans.split("\\n")).stream().filter(bean -> bean.matches("org.apache.ZooKeeperService:name[0-9]+=ReplicatedServer_id[0-9]+")).findFirst().get();
        String zkResults = JmxUtils.collectJmxMetricsWithWait(namespaceName, KafkaResources.zookeeperHeadlessServiceName(clusterName), zkSecretName, scraperPodName, "bean " + zkBean + "\nget -i *");
        assertThat("Result from Zookeeper JMX doesn't contain right quorum size, result: " + zkResults, zkResults, containsString("QuorumSize = 3"));
        LOGGER.info("Checking that Zookeeper JMX secret is created with custom labels and annotations");
        assertTrue(jmxZkSecret.getMetadata().getLabels().entrySet().containsAll(jmxSecretLabels.entrySet()));
        assertTrue(jmxZkSecret.getMetadata().getAnnotations().entrySet().containsAll(jmxSecretAnnotations.entrySet()));
    }
}
Also used : Secret(io.fabric8.kubernetes.api.model.Secret) KafkaJmxAuthenticationPassword(io.strimzi.api.kafka.model.KafkaJmxAuthenticationPassword) Matchers.containsString(org.hamcrest.Matchers.containsString) KRaftNotSupported(io.strimzi.systemtest.annotations.KRaftNotSupported) ParallelNamespaceTest(io.strimzi.systemtest.annotations.ParallelNamespaceTest) Tag(org.junit.jupiter.api.Tag)

Example 25 with KRaftNotSupported

use of io.strimzi.systemtest.annotations.KRaftNotSupported in project strimzi by strimzi.

the class MetricsIsolatedST method testTopicOperatorMetrics.

@ParallelTest
@KRaftNotSupported("TopicOperator is not supported by KRaft mode and is used in this test case")
void testTopicOperatorMetrics() {
    topicOperatorMetricsData = collector.toBuilder().withComponentType(ComponentType.TopicOperator).build().collectMetricsFromPods();
    assertCoMetricNotNull("strimzi_reconciliations_locked_total", "KafkaTopic", topicOperatorMetricsData);
    assertCoMetricNotNull("strimzi_reconciliations_successful_total", "KafkaTopic", topicOperatorMetricsData);
    assertCoMetricNotNull("strimzi_reconciliations_duration_seconds_count", "KafkaTopic", topicOperatorMetricsData);
    assertCoMetricNotNull("strimzi_reconciliations_duration_seconds_sum", "KafkaTopic", topicOperatorMetricsData);
    assertCoMetricNotNull("strimzi_reconciliations_duration_seconds_max", "KafkaTopic", topicOperatorMetricsData);
    assertCoMetricNotNull("strimzi_reconciliations_periodical_total", "KafkaTopic", topicOperatorMetricsData);
    assertCoMetricNotNull("strimzi_reconciliations_failed_total", "KafkaTopic", topicOperatorMetricsData);
    assertCoMetricNotNull("strimzi_reconciliations_total", "KafkaTopic", topicOperatorMetricsData);
    Pattern topicPattern = Pattern.compile("strimzi_resources\\{kind=\"KafkaTopic\",.*} ([\\d.][^\\n]+)", Pattern.CASE_INSENSITIVE);
    ArrayList<Double> values = MetricsCollector.collectSpecificMetric(topicPattern, topicOperatorMetricsData);
    cmdKubeClient().list("KafkaTopic").forEach(topicName -> {
        LOGGER.info("KafkaTopic: {}", topicName);
    });
    // We use greater than in that case to avoid potential collisions with other tests from this class which could run in parallel
    assertThat(values.stream().mapToDouble(i -> i).sum(), greaterThanOrEqualTo((double) getExpectedTopics().size()));
}
Also used : Pattern(java.util.regex.Pattern) OptionalDouble(java.util.OptionalDouble) KRaftNotSupported(io.strimzi.systemtest.annotations.KRaftNotSupported) ParallelTest(io.strimzi.systemtest.annotations.ParallelTest)

Aggregations

KRaftNotSupported (io.strimzi.systemtest.annotations.KRaftNotSupported)162 ParallelNamespaceTest (io.strimzi.systemtest.annotations.ParallelNamespaceTest)138 Tag (org.junit.jupiter.api.Tag)100 KafkaClientsBuilder (io.strimzi.systemtest.kafkaclients.internalClients.KafkaClientsBuilder)94 TestStorage (io.strimzi.systemtest.storage.TestStorage)94 KafkaClients (io.strimzi.systemtest.kafkaclients.internalClients.KafkaClients)86 GenericKafkaListenerBuilder (io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder)80 Matchers.containsString (org.hamcrest.Matchers.containsString)74 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)44 LabelSelector (io.fabric8.kubernetes.api.model.LabelSelector)36 ExternalKafkaClient (io.strimzi.systemtest.kafkaclients.externalClients.ExternalKafkaClient)32 Secret (io.fabric8.kubernetes.api.model.Secret)30 HashMap (java.util.HashMap)30 KafkaListenerAuthenticationTls (io.strimzi.api.kafka.model.listener.KafkaListenerAuthenticationTls)28 SecretBuilder (io.fabric8.kubernetes.api.model.SecretBuilder)24 KafkaResources (io.strimzi.api.kafka.model.KafkaResources)24 AbstractST (io.strimzi.systemtest.AbstractST)24 Constants (io.strimzi.systemtest.Constants)24 REGRESSION (io.strimzi.systemtest.Constants.REGRESSION)24 KafkaResource (io.strimzi.systemtest.resources.crd.KafkaResource)24