use of io.strimzi.api.kafka.model.ExternalLoggingBuilder in project strimzi-kafka-operator by strimzi.
the class LoggingChangeST method testDynamicallySetBridgeLoggingLevels.
@ParallelNamespaceTest
@Tag(BRIDGE)
@Tag(ROLLING_UPDATE)
void testDynamicallySetBridgeLoggingLevels(ExtensionContext extensionContext) throws InterruptedException {
final String namespaceName = StUtils.getNamespaceBasedOnRbac(namespace, extensionContext);
final String clusterName = mapWithClusterNames.get(extensionContext.getDisplayName());
final String kafkaClientsName = mapWithKafkaClientNames.get(extensionContext.getDisplayName());
InlineLogging ilOff = new InlineLogging();
Map<String, String> loggers = new HashMap<>();
loggers.put("rootLogger.level", "OFF");
loggers.put("logger.bridge.level", "OFF");
loggers.put("logger.healthy.level", "OFF");
loggers.put("logger.ready.level", "OFF");
ilOff.setLoggers(loggers);
// create resources async
resourceManager.createResource(extensionContext, false, KafkaTemplates.kafkaPersistent(clusterName, 1, 1).build(), KafkaClientsTemplates.kafkaClients(false, kafkaClientsName).build(), KafkaBridgeTemplates.kafkaBridge(clusterName, KafkaResources.tlsBootstrapAddress(clusterName), 1).editSpec().withInlineLogging(ilOff).endSpec().build());
KafkaUtils.waitForKafkaReady(namespaceName, clusterName);
DeploymentUtils.waitForDeploymentReady(namespaceName, kafkaClientsName);
KafkaBridgeUtils.waitForKafkaBridgeReady(namespaceName, clusterName);
Map<String, String> bridgeSnapshot = DeploymentUtils.depSnapshot(namespaceName, KafkaBridgeResources.deploymentName(clusterName));
final String bridgePodName = bridgeSnapshot.keySet().iterator().next();
LOGGER.info("Asserting if log is without records");
assertFalse(DEFAULT_LOG4J_PATTERN.matcher(StUtils.getLogFromPodByTime(namespaceName, bridgePodName, "", "30s")).find());
LOGGER.info("Changing rootLogger level to DEBUG with inline logging");
InlineLogging ilDebug = new InlineLogging();
loggers.put("rootLogger.level", "DEBUG");
loggers.put("logger.bridge.level", "OFF");
loggers.put("logger.healthy.level", "OFF");
loggers.put("logger.ready.level", "OFF");
ilDebug.setLoggers(loggers);
KafkaBridgeResource.replaceBridgeResourceInSpecificNamespace(clusterName, bridz -> {
bridz.getSpec().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, bridgePodName, KafkaBridgeResources.deploymentName(clusterName), "cat", "/opt/strimzi/custom-config/log4j2.properties").out().contains("rootLogger.level=DEBUG") && cmdKubeClient().namespace(namespaceName).execInPodContainer(Level.TRACE, bridgePodName, KafkaBridgeResources.deploymentName(clusterName), "cat", "/opt/strimzi/custom-config/log4j2.properties").out().contains("monitorInterval=30"));
TestUtils.waitFor("log to not be empty", Duration.ofMillis(100).toMillis(), Constants.SAFETY_RECONCILIATION_INTERVAL, () -> {
String bridgeLog = StUtils.getLogFromPodByTime(namespaceName, bridgePodName, KafkaBridgeResources.deploymentName(clusterName), "30s");
return bridgeLog != null && !bridgeLog.isEmpty() && DEFAULT_LOG4J_PATTERN.matcher(bridgeLog).find();
});
ConfigMap configMapBridge = new ConfigMapBuilder().withNewMetadata().withName("external-configmap-bridge").withNamespace(namespaceName).endMetadata().withData(Collections.singletonMap("log4j2.properties", "name = BridgeConfig\n" + "\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" + "\n" + "rootLogger.level = OFF\n" + "rootLogger.appenderRefs = console\n" + "rootLogger.appenderRef.console.ref = STDOUT\n" + "rootLogger.additivity = false\n" + "\n" + "logger.bridge.name = io.strimzi.kafka.bridge\n" + "logger.bridge.level = OFF\n" + "logger.bridge.appenderRefs = console\n" + "logger.bridge.appenderRef.console.ref = STDOUT\n" + "logger.bridge.additivity = false\n" + "\n" + "# HTTP OpenAPI specific logging levels (default is INFO)\n" + "# Logging healthy and ready endpoints is very verbose because of Kubernetes health checking.\n" + "logger.healthy.name = http.openapi.operation.healthy\n" + "logger.healthy.level = OFF\n" + "logger.ready.name = http.openapi.operation.ready\n" + "logger.ready.level = OFF")).build();
kubeClient().getClient().configMaps().inNamespace(namespaceName).createOrReplace(configMapBridge);
ExternalLogging bridgeXternalLogging = new ExternalLoggingBuilder().withNewValueFrom().withConfigMapKeyRef(new ConfigMapKeySelectorBuilder().withName("external-configmap-bridge").withKey("log4j2.properties").build()).endValueFrom().build();
LOGGER.info("Setting log level of Bridge to OFF - records should not appear in the log");
// change to the external logging
KafkaBridgeResource.replaceBridgeResourceInSpecificNamespace(clusterName, bridz -> {
bridz.getSpec().setLogging(bridgeXternalLogging);
}, 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, bridgePodName, KafkaBridgeResources.deploymentName(clusterName), "cat", "/opt/strimzi/custom-config/log4j2.properties").out().contains("rootLogger.level = OFF") && cmdKubeClient().namespace(namespaceName).execInPodContainer(Level.TRACE, bridgePodName, KafkaBridgeResources.deploymentName(clusterName), "cat", "/opt/strimzi/custom-config/log4j2.properties").out().contains("monitorInterval=30"));
TestUtils.waitFor("log to be empty", Duration.ofMillis(100).toMillis(), Constants.SAFETY_RECONCILIATION_INTERVAL, () -> {
String bridgeLog = StUtils.getLogFromPodByTime(namespaceName, bridgePodName, KafkaBridgeResources.deploymentName(clusterName), "30s");
return bridgeLog != null && bridgeLog.isEmpty() && !DEFAULT_LOG4J_PATTERN.matcher(bridgeLog).find();
});
assertThat("Bridge pod should not roll", DeploymentUtils.depSnapshot(namespaceName, KafkaBridgeResources.deploymentName(clusterName)), equalTo(bridgeSnapshot));
}
use of io.strimzi.api.kafka.model.ExternalLoggingBuilder in project strimzi-kafka-operator by strimzi.
the class LoggingChangeST method testDynamicallySetKafkaLoggingLevels.
@ParallelNamespaceTest
void testDynamicallySetKafkaLoggingLevels(ExtensionContext extensionContext) {
final String namespaceName = StUtils.getNamespaceBasedOnRbac(namespace, extensionContext);
final String clusterName = mapWithClusterNames.get(extensionContext.getDisplayName());
String kafkaName = KafkaResources.kafkaStatefulSetName(clusterName);
final LabelSelector kafkaSelector = KafkaResource.getLabelSelector(clusterName, kafkaName);
InlineLogging ilOff = new InlineLogging();
Map<String, String> log4jConfig = new HashMap<>();
log4jConfig.put("kafka.root.logger.level", "OFF");
log4jConfig.put("log4j.logger.org.I0Itec.zkclient.ZkClient", "OFF");
log4jConfig.put("log4j.logger.org.apache.zookeeper", "OFF");
log4jConfig.put("log4j.logger.kafka", "OFF");
log4jConfig.put("log4j.logger.org.apache.kafka", "OFF");
log4jConfig.put("log4j.logger.kafka.request.logger", "OFF, CONSOLE");
log4jConfig.put("log4j.logger.kafka.network.Processor", "OFF");
log4jConfig.put("log4j.logger.kafka.server.KafkaApis", "OFF");
log4jConfig.put("log4j.logger.kafka.network.RequestChannel$", "OFF");
log4jConfig.put("log4j.logger.kafka.controller", "OFF");
log4jConfig.put("log4j.logger.kafka.log.LogCleaner", "OFF");
log4jConfig.put("log4j.logger.state.change.logger", "OFF");
log4jConfig.put("log4j.logger.kafka.authorizer.logger", "OFF");
ilOff.setLoggers(log4jConfig);
resourceManager.createResource(extensionContext, KafkaTemplates.kafkaEphemeral(clusterName, 3, 1).editSpec().editKafka().withInlineLogging(ilOff).endKafka().endSpec().build());
Map<String, String> kafkaPods = PodUtils.podSnapshot(namespaceName, kafkaSelector);
TestUtils.waitFor("log to not be empty", Duration.ofMillis(100).toMillis(), Constants.SAFETY_RECONCILIATION_INTERVAL, () -> {
boolean[] correctLogging = { true };
kafkaPods.keySet().forEach(podName -> {
String kafkaLog = StUtils.getLogFromPodByTime(namespaceName, podName, "kafka", "30s");
correctLogging[0] = kafkaLog != null && kafkaLog.isEmpty() && !DEFAULT_LOG4J_PATTERN.matcher(kafkaLog).find();
});
return correctLogging[0];
});
LOGGER.info("Changing rootLogger level to DEBUG with inline logging");
InlineLogging ilDebug = new InlineLogging();
ilDebug.setLoggers(Collections.singletonMap("kafka.root.logger.level", "DEBUG"));
KafkaResource.replaceKafkaResourceInSpecificNamespace(clusterName, k -> {
k.getSpec().getKafka().setLogging(ilDebug);
}, namespaceName);
LOGGER.info("Waiting for dynamic change in the kafka pod");
TestUtils.waitFor("Logger change", Constants.GLOBAL_POLL_INTERVAL, Constants.GLOBAL_TIMEOUT, () -> cmdKubeClient().namespace(namespaceName).execInPodContainer(Level.TRACE, KafkaResources.kafkaPodName(clusterName, 0), "kafka", "/bin/bash", "-c", "bin/kafka-configs.sh --bootstrap-server localhost:9092 --describe --entity-type broker-loggers --entity-name 0").out().contains("root=DEBUG"));
TestUtils.waitFor("log to not be empty", Duration.ofMillis(100).toMillis(), Constants.SAFETY_RECONCILIATION_INTERVAL, () -> {
boolean[] correctLogging = { true };
kafkaPods.keySet().forEach(podName -> {
String kafkaLog = StUtils.getLogFromPodByTime(namespaceName, podName, "kafka", "30s");
correctLogging[0] = kafkaLog != null && !kafkaLog.isEmpty() && DEFAULT_LOG4J_PATTERN.matcher(kafkaLog).find();
});
return correctLogging[0];
});
LOGGER.info("Setting external logging INFO");
ConfigMap configMap = new ConfigMapBuilder().withNewMetadata().withName("external-configmap").withNamespace(namespaceName).endMetadata().withData(Collections.singletonMap("log4j.properties", "log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender\n" + "log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout\n" + "log4j.appender.CONSOLE.layout.ConversionPattern=%d{ISO8601} %p %m (%c) [%t]%n\n" + "log4j.rootLogger=INFO, 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\n" + "log4j.logger.kafka.network.Processor=ERROR\n" + "log4j.logger.kafka.server.KafkaApis=ERROR\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")).build();
kubeClient().getClient().configMaps().inNamespace(namespaceName).createOrReplace(configMap);
ExternalLogging elKafka = new ExternalLoggingBuilder().withNewValueFrom().withConfigMapKeyRef(new ConfigMapKeySelectorBuilder().withKey("log4j.properties").withName("external-configmap").withOptional(false).build()).endValueFrom().build();
LOGGER.info("Setting log level of kafka INFO");
// change to external logging
KafkaResource.replaceKafkaResourceInSpecificNamespace(clusterName, k -> {
k.getSpec().getKafka().setLogging(elKafka);
}, namespaceName);
LOGGER.info("Waiting for dynamic change in the kafka pod");
TestUtils.waitFor("Logger change", Constants.GLOBAL_POLL_INTERVAL, Constants.GLOBAL_TIMEOUT, () -> cmdKubeClient().namespace(namespaceName).execInPodContainer(Level.TRACE, KafkaResources.kafkaPodName(clusterName, 0), "kafka", "/bin/bash", "-c", "bin/kafka-configs.sh --bootstrap-server localhost:9092 --describe --entity-type broker-loggers --entity-name 0").out().contains("root=INFO"));
TestUtils.waitFor("log to not be empty", Duration.ofMillis(100).toMillis(), Constants.SAFETY_RECONCILIATION_INTERVAL, () -> {
boolean[] correctLogging = { true };
kafkaPods.keySet().forEach(podName -> {
String kafkaLog = StUtils.getLogFromPodByTime(namespaceName, podName, "kafka", "30s");
correctLogging[0] = kafkaLog != null && !kafkaLog.isEmpty() && DEFAULT_LOG4J_PATTERN.matcher(kafkaLog).find();
});
return correctLogging[0];
});
assertThat("Kafka pod should not roll", RollingUpdateUtils.componentHasRolled(namespaceName, kafkaSelector, kafkaPods), is(false));
}
use of io.strimzi.api.kafka.model.ExternalLoggingBuilder in project strimzi-kafka-operator by strimzi.
the class LoggingChangeST method testDynamicallySetKafkaExternalLogging.
@ParallelNamespaceTest
void testDynamicallySetKafkaExternalLogging(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));
// this test changes dynamically unchangeable logging config and thus RU is expected
ConfigMap configMap = new ConfigMapBuilder().withNewMetadata().withName("external-cm").withNamespace(namespaceName).endMetadata().withData(Collections.singletonMap("log4j.properties", "log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender\n" + "log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout\n" + "log4j.appender.CONSOLE.layout.ConversionPattern=%d{ISO8601} %p %m (%c) [%t]%n\n" + "log4j.rootLogger=INFO, 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\n" + "log4j.logger.kafka.network.Processor=ERROR\n" + "log4j.logger.kafka.server.KafkaApis=ERROR\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=${kafka.my.level.string}\n" + "kafka.my.level.string=INFO")).build();
kubeClient().getClient().configMaps().inNamespace(namespaceName).createOrReplace(configMap);
ExternalLogging el = new ExternalLoggingBuilder().withNewValueFrom().withConfigMapKeyRef(new ConfigMapKeySelectorBuilder().withName("external-cm").withKey("log4j.properties").build()).endValueFrom().build();
resourceManager.createResource(extensionContext, KafkaTemplates.kafkaPersistent(clusterName, 3, 1).editOrNewSpec().editKafka().withExternalLogging(el).endKafka().endSpec().build());
String kafkaName = KafkaResources.kafkaStatefulSetName(clusterName);
Map<String, String> kafkaPods = PodUtils.podSnapshot(namespaceName, kafkaSelector);
configMap = new ConfigMapBuilder().withNewMetadata().withName("external-cm").withNamespace(namespaceName).endMetadata().withData(Collections.singletonMap("log4j.properties", "log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender\n" + "log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout\n" + "log4j.appender.CONSOLE.layout.ConversionPattern=%d{ISO8601} %p %m (%c) [%t]%n\n" + "log4j.rootLogger=INFO, CONSOLE\n" + "log4j.logger.org.I0Itec.zkclient.ZkClient=ERROR\n" + "log4j.logger.org.apache.zookeeper=ERROR\n" + "log4j.logger.kafka=ERROR\n" + "log4j.logger.org.apache.kafka=ERROR\n" + "log4j.logger.kafka.request.logger=WARN\n" + "log4j.logger.kafka.network.Processor=ERROR\n" + "log4j.logger.kafka.server.KafkaApis=ERROR\n" + "log4j.logger.kafka.network.RequestChannel$=ERROR\n" + "log4j.logger.kafka.controller=ERROR\n" + "log4j.logger.kafka.log.LogCleaner=ERROR\n" + "log4j.logger.state.change.logger=TRACE\n" + "log4j.logger.kafka.authorizer.logger=${kafka.my.level.string}\n" + "kafka.my.level.string=ERROR")).build();
kubeClient().getClient().configMaps().inNamespace(namespaceName).createOrReplace(configMap);
RollingUpdateUtils.waitForNoRollingUpdate(namespaceName, kafkaSelector, kafkaPods);
assertThat("Kafka pod should not roll", RollingUpdateUtils.componentHasRolled(namespaceName, kafkaSelector, kafkaPods), is(false));
TestUtils.waitFor("Verify logger change", Constants.GLOBAL_POLL_INTERVAL, Constants.GLOBAL_TIMEOUT, () -> cmdKubeClient().namespace(namespaceName).execInPodContainer(Level.TRACE, KafkaResources.kafkaPodName(clusterName, 0), "kafka", "/bin/bash", "-c", "bin/kafka-configs.sh --bootstrap-server localhost:9092 --describe --entity-type broker-loggers --entity-name 0").out().contains("kafka.authorizer.logger=ERROR"));
// log4j.appender.CONSOLE.layout.ConversionPattern is changed and thus we need RU
configMap = new ConfigMapBuilder().withNewMetadata().withName("external-cm").withNamespace(namespaceName).endMetadata().withData(Collections.singletonMap("log4j.properties", "log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender\n" + "log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout\n" + "log4j.appender.CONSOLE.layout.ConversionPattern=%d{ISO8601} %p %m (%c) [%t]\n" + "log4j.rootLogger=INFO, CONSOLE\n" + "log4j.logger.org.I0Itec.zkclient.ZkClient=ERROR\n" + "log4j.logger.org.apache.zookeeper=ERROR\n" + "log4j.logger.kafka=ERROR\n" + "log4j.logger.org.apache.kafka=ERROR\n" + "log4j.logger.kafka.request.logger=WARN\n" + "log4j.logger.kafka.network.Processor=ERROR\n" + "log4j.logger.kafka.server.KafkaApis=ERROR\n" + "log4j.logger.kafka.network.RequestChannel$=ERROR\n" + "log4j.logger.kafka.controller=ERROR\n" + "log4j.logger.kafka.log.LogCleaner=ERROR\n" + "log4j.logger.state.change.logger=TRACE\n" + "log4j.logger.kafka.authorizer.logger=${kafka.my.level.string}\n" + "kafka.my.level.string=DEBUG")).build();
kubeClient().getClient().configMaps().inNamespace(namespaceName).createOrReplace(configMap);
RollingUpdateUtils.waitTillComponentHasRolled(namespaceName, kafkaSelector, kafkaPods);
TestUtils.waitFor("Verify logger change", Constants.GLOBAL_POLL_INTERVAL, Constants.GLOBAL_TIMEOUT, () -> cmdKubeClient().namespace(namespaceName).execInPodContainer(Level.TRACE, KafkaResources.kafkaPodName(clusterName, 0), "kafka", "/bin/bash", "-c", "bin/kafka-configs.sh --bootstrap-server localhost:9092 --describe --entity-type broker-loggers --entity-name 0").out().contains("kafka.authorizer.logger=DEBUG"));
}
use of io.strimzi.api.kafka.model.ExternalLoggingBuilder in project strimzi-kafka-operator by strimzi.
the class LoggingChangeST method testMM2LoggingLevelsHierarchy.
@ParallelNamespaceTest
@Tag(ROLLING_UPDATE)
void testMM2LoggingLevelsHierarchy(ExtensionContext extensionContext) {
final String namespaceName = StUtils.getNamespaceBasedOnRbac(namespace, extensionContext);
final String clusterName = mapWithClusterNames.get(extensionContext.getDisplayName());
final String kafkaClientsName = mapWithKafkaClientNames.get(extensionContext.getDisplayName());
resourceManager.createResource(extensionContext, KafkaTemplates.kafkaEphemeral(clusterName + "-source", 3).build());
resourceManager.createResource(extensionContext, KafkaTemplates.kafkaEphemeral(clusterName + "-target", 3).build());
resourceManager.createResource(extensionContext, false, KafkaClientsTemplates.kafkaClients(false, kafkaClientsName).build());
String log4jConfig = "log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender\n" + "log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout\n" + "log4j.appender.CONSOLE.layout.ConversionPattern=%d{ISO8601} %p %m (%c) [%t]%n\n" + "log4j.rootLogger=OFF, CONSOLE\n" + "log4j.logger.org.apache.zookeeper=ERROR\n" + "log4j.logger.org.I0Itec.zkclient=ERROR\n" + "log4j.logger.org.eclipse.jetty.util.thread=FATAL\n" + "log4j.logger.org.apache.kafka.connect.runtime.WorkerTask=OFF\n" + "log4j.logger.org.eclipse.jetty.util.thread.strategy.EatWhatYouKill=OFF\n" + "log4j.logger.org.reflections=ERROR";
String externalCmName = "external-cm-hierarchy";
ConfigMap mm2LoggingMap = new ConfigMapBuilder().withNewMetadata().addToLabels("app", "strimzi").withName(externalCmName).withNamespace(namespaceName).endMetadata().withData(Collections.singletonMap("log4j.properties", log4jConfig)).build();
kubeClient().getClient().configMaps().inNamespace(namespaceName).createOrReplace(mm2LoggingMap);
ExternalLogging mm2XternalLogging = new ExternalLoggingBuilder().withNewValueFrom().withConfigMapKeyRef(new ConfigMapKeySelectorBuilder().withName(externalCmName).withKey("log4j.properties").build()).endValueFrom().build();
resourceManager.createResource(extensionContext, KafkaMirrorMaker2Templates.kafkaMirrorMaker2(clusterName, clusterName + "-target", clusterName + "-source", 1, false).editOrNewSpec().withLogging(mm2XternalLogging).endSpec().build());
String kafkaMM2PodName = kubeClient().namespace(namespaceName).listPods(namespaceName, clusterName, Labels.STRIMZI_KIND_LABEL, KafkaMirrorMaker2.RESOURCE_KIND).get(0).getMetadata().getName();
Map<String, String> mm2Snapshot = DeploymentUtils.depSnapshot(namespaceName, KafkaMirrorMaker2Resources.deploymentName(clusterName));
LOGGER.info("Waiting for log4j.properties will contain desired settings");
TestUtils.waitFor("Logger init levels", Constants.GLOBAL_POLL_INTERVAL, Constants.GLOBAL_TIMEOUT, () -> cmdKubeClient().namespace(namespaceName).execInPod(kafkaMM2PodName, "curl", "http://localhost:8083/admin/loggers/root").out().contains("OFF"));
LOGGER.info("Changing log levels");
String updatedLog4jConfig = "log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender\n" + "log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout\n" + "log4j.appender.CONSOLE.layout.ConversionPattern=%d{ISO8601} %p %m (%c) [%t]%n\n" + "log4j.rootLogger=INFO, CONSOLE\n" + "log4j.logger.org.apache.zookeeper=ERROR\n" + "log4j.logger.org.I0Itec.zkclient=ERROR\n" + "log4j.logger.org.eclipse.jetty.util.thread=WARN\n" + "log4j.logger.org.reflections=ERROR";
mm2LoggingMap = new ConfigMapBuilder().withNewMetadata().addToLabels("app", "strimzi").withName(externalCmName).withNamespace(namespaceName).endMetadata().withData(Collections.singletonMap("log4j.properties", updatedLog4jConfig)).build();
kubeClient().getClient().configMaps().inNamespace(namespaceName).createOrReplace(mm2LoggingMap);
TestUtils.waitFor("Logger change", Constants.GLOBAL_POLL_INTERVAL, Constants.GLOBAL_TIMEOUT, () -> cmdKubeClient().namespace(namespaceName).execInPod(kafkaMM2PodName, "curl", "http://localhost:8083/admin/loggers/root").out().contains("INFO") && // not set logger should inherit parent level (in this case 'org.eclipse.jetty.util.thread')
cmdKubeClient().namespace(namespaceName).execInPod(kafkaMM2PodName, "curl", "http://localhost:8083/admin/loggers/org.eclipse.jetty.util.thread.strategy.EatWhatYouKill").out().contains("WARN") && // logger with not set parent should inherit root
cmdKubeClient().namespace(namespaceName).execInPod(kafkaMM2PodName, "curl", "http://localhost:8083/admin/loggers/org.apache.kafka.connect.runtime.WorkerTask").out().contains("INFO"));
assertThat("MirrorMaker2 pod should not roll", DeploymentUtils.depSnapshot(namespaceName, KafkaMirrorMaker2Resources.deploymentName(clusterName)), equalTo(mm2Snapshot));
}
use of io.strimzi.api.kafka.model.ExternalLoggingBuilder in project strimzi-kafka-operator by strimzi.
the class RollingUpdateST method testExternalLoggingChangeTriggerRollingUpdate.
@ParallelNamespaceTest
@Tag(ROLLING_UPDATE)
void testExternalLoggingChangeTriggerRollingUpdate(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));
// EO dynamic logging is tested in io.strimzi.systemtest.log.LoggingChangeST.testDynamicallySetEOloggingLevels
resourceManager.createResource(extensionContext, KafkaTemplates.kafkaEphemeral(clusterName, 3, 3).build());
Map<String, String> kafkaPods = PodUtils.podSnapshot(namespaceName, kafkaSelector);
Map<String, String> zkPods = PodUtils.podSnapshot(namespaceName, zkSelector);
String loggersConfig = "log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender\n" + "log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout\n" + "log4j.appender.CONSOLE.layout.ConversionPattern=%d{ISO8601} %p %m (%c) [%t]\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=INFO\n" + "log4j.logger.kafka.server.KafkaApis=INFO\n" + "log4j.logger.kafka.network.RequestChannel$=INFO\n" + "log4j.logger.kafka.controller=INFO\n" + "log4j.logger.kafka.log.LogCleaner=INFO\n" + "log4j.logger.state.change.logger=TRACE\n" + "log4j.logger.kafka.authorizer.logger=INFO";
String configMapLoggersName = "loggers-config-map";
ConfigMap configMapLoggers = new ConfigMapBuilder().withNewMetadata().withNamespace(namespaceName).withName(configMapLoggersName).endMetadata().addToData("log4j-custom.properties", loggersConfig).build();
ConfigMapKeySelector log4jLoggimgCMselector = new ConfigMapKeySelectorBuilder().withName(configMapLoggersName).withKey("log4j-custom.properties").build();
kubeClient(namespaceName).getClient().configMaps().inNamespace(namespaceName).createOrReplace(configMapLoggers);
KafkaResource.replaceKafkaResourceInSpecificNamespace(clusterName, kafka -> {
kafka.getSpec().getKafka().setLogging(new ExternalLoggingBuilder().withNewValueFrom().withConfigMapKeyRef(log4jLoggimgCMselector).endValueFrom().build());
kafka.getSpec().getZookeeper().setLogging(new ExternalLoggingBuilder().withNewValueFrom().withConfigMapKeyRef(log4jLoggimgCMselector).endValueFrom().build());
}, namespaceName);
zkPods = RollingUpdateUtils.waitTillComponentHasRolledAndPodsReady(namespaceName, zkSelector, 3, zkPods);
kafkaPods = RollingUpdateUtils.waitTillComponentHasRolled(namespaceName, kafkaSelector, 3, kafkaPods);
configMapLoggers.getData().put("log4j-custom.properties", loggersConfig.replace("%p %m (%c) [%t]", "%p %m (%c) [%t]%n"));
kubeClient().getClient().configMaps().inNamespace(namespaceName).createOrReplace(configMapLoggers);
RollingUpdateUtils.waitTillComponentHasRolledAndPodsReady(namespaceName, zkSelector, 3, zkPods);
RollingUpdateUtils.waitTillComponentHasRolled(namespaceName, kafkaSelector, 3, kafkaPods);
}
Aggregations