use of io.strimzi.api.kafka.model.ExternalLoggingBuilder in project strimzi by strimzi.
the class LoggingChangeST method testNotExistingCMSetsDefaultLogging.
@ParallelNamespaceTest
void testNotExistingCMSetsDefaultLogging(ExtensionContext extensionContext) {
final String namespaceName = StUtils.getNamespaceBasedOnRbac(namespace, extensionContext);
final String defaultProps = TestUtils.getFileAsString(TestUtils.USER_PATH + "/../cluster-operator/src/main/resources/kafkaDefaultLoggingProperties");
final String clusterName = mapWithClusterNames.get(extensionContext.getDisplayName());
final LabelSelector kafkaSelector = KafkaResource.getLabelSelector(clusterName, KafkaResources.kafkaStatefulSetName(clusterName));
String cmData = "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";
String existingCmName = "external-cm";
String nonExistingCmName = "non-existing-cm-name";
ConfigMap configMap = new ConfigMapBuilder().withNewMetadata().withName(existingCmName).withNamespace(namespaceName).endMetadata().withData(Collections.singletonMap("log4j.properties", cmData)).build();
kubeClient().getClient().configMaps().inNamespace(namespaceName).createOrReplace(configMap);
LOGGER.info("Deploying Kafka with custom logging");
resourceManager.createResource(extensionContext, KafkaTemplates.kafkaPersistent(clusterName, 3, 1).editOrNewSpec().editKafka().withExternalLogging(new ExternalLoggingBuilder().withNewValueFrom().withConfigMapKeyRef(new ConfigMapKeySelectorBuilder().withKey("log4j.properties").withName(existingCmName).withOptional(false).build()).endValueFrom().build()).endKafka().endSpec().build());
String kafkaSsName = KafkaResources.kafkaStatefulSetName(clusterName);
Map<String, String> kafkaPods = PodUtils.podSnapshot(namespaceName, kafkaSelector);
String log4jFile = cmdKubeClient().namespace(namespaceName).execInPodContainer(Level.DEBUG, KafkaResources.kafkaPodName(clusterName, 0), "kafka", "/bin/bash", "-c", "cat custom-config/log4j.properties").out();
assertTrue(log4jFile.contains(cmData));
LOGGER.info("Changing external logging's CM to not existing one");
KafkaResource.replaceKafkaResourceInSpecificNamespace(clusterName, kafka -> kafka.getSpec().getKafka().setLogging(new ExternalLoggingBuilder().withNewValueFrom().withConfigMapKeyRef(new ConfigMapKeySelectorBuilder().withKey("log4j.properties").withName(nonExistingCmName).withOptional(false).build()).endValueFrom().build()), namespaceName);
RollingUpdateUtils.waitForNoRollingUpdate(namespaceName, kafkaSelector, kafkaPods);
LOGGER.info("Checking that log4j.properties in custom-config isn't empty and configuration is default");
log4jFile = cmdKubeClient().namespace(namespaceName).execInPodContainer(Level.DEBUG, KafkaResources.kafkaPodName(clusterName, 0), "kafka", "/bin/bash", "-c", "cat custom-config/log4j.properties").out();
assertFalse(log4jFile.isEmpty());
assertTrue(log4jFile.contains(cmData));
assertFalse(log4jFile.contains(defaultProps));
LOGGER.info("Checking if Kafka:{} contains error about non-existing CM", clusterName);
Condition condition = KafkaResource.kafkaClient().inNamespace(namespaceName).withName(clusterName).get().getStatus().getConditions().get(0);
assertThat(condition.getType(), is(CustomResourceStatus.NotReady.toString()));
assertTrue(condition.getMessage().matches("ConfigMap " + nonExistingCmName + " with external logging configuration does not exist .*"));
}
use of io.strimzi.api.kafka.model.ExternalLoggingBuilder in project strimzi-kafka-operator by strimzi.
the class LoggingChangeST method testDynamicallySetConnectLoggingLevels.
@ParallelNamespaceTest
@Tag(ROLLING_UPDATE)
@Tag(CONNECT)
@Tag(CONNECT_COMPONENTS)
void testDynamicallySetConnectLoggingLevels(ExtensionContext extensionContext) {
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("connect.root.logger.level", "OFF");
ilOff.setLoggers(loggers);
// create async
resourceManager.createResource(extensionContext, false, KafkaTemplates.kafkaEphemeral(clusterName, 3).build());
resourceManager.createResource(extensionContext, false, KafkaClientsTemplates.kafkaClients(false, kafkaClientsName).build());
// sync point
KafkaUtils.waitForKafkaReady(namespaceName, clusterName);
final String kafkaClientsPodName = PodUtils.getPodsByPrefixInNameWithDynamicWait(namespaceName, kafkaClientsName).get(0).getMetadata().getName();
resourceManager.createResource(extensionContext, false, KafkaConnectTemplates.kafkaConnect(extensionContext, clusterName, 1).editSpec().withInlineLogging(ilOff).endSpec().editMetadata().addToAnnotations(Annotations.STRIMZI_IO_USE_CONNECTOR_RESOURCES, "true").endMetadata().build());
KafkaConnectUtils.waitForConnectReady(namespaceName, clusterName);
Map<String, String> connectSnapshot = DeploymentUtils.depSnapshot(namespaceName, KafkaConnectResources.deploymentName(clusterName));
final String connectPodName = connectSnapshot.keySet().iterator().next();
LOGGER.info("Asserting if log is without records");
assertFalse(DEFAULT_LOG4J_PATTERN.matcher(StUtils.getLogFromPodByTime(namespaceName, connectPodName, "", "30s")).find());
LOGGER.info("Changing rootLogger level to DEBUG with inline logging");
InlineLogging ilDebug = new InlineLogging();
loggers.put("connect.root.logger.level", "DEBUG");
ilDebug.setLoggers(loggers);
KafkaConnectResource.replaceKafkaConnectResourceInSpecificNamespace(clusterName, conn -> {
conn.getSpec().setLogging(ilDebug);
}, namespaceName);
LOGGER.info("Waiting for log4j.properties will contain desired settings");
TestUtils.waitFor("Logger change", Constants.GLOBAL_POLL_INTERVAL, Constants.GLOBAL_TIMEOUT, () -> cmdKubeClient().namespace(namespaceName).execInPod(kafkaClientsPodName, "curl", "http://" + KafkaConnectResources.serviceName(clusterName) + ":8083/admin/loggers/root").out().contains("DEBUG"));
TestUtils.waitFor("log to not be empty", Duration.ofMillis(100).toMillis(), Constants.SAFETY_RECONCILIATION_INTERVAL, () -> {
String kcLog = StUtils.getLogFromPodByTime(namespaceName, connectPodName, "", "30s");
return kcLog != null && !kcLog.isEmpty() && DEFAULT_LOG4J_PATTERN.matcher(kcLog).find();
});
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 %X{connector.context}%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.reflections=ERROR";
String externalCmName = "external-cm";
ConfigMap connectLoggingMap = new ConfigMapBuilder().withNewMetadata().addToLabels("app", "strimzi").withName(externalCmName).withNamespace(namespaceName).endMetadata().withData(Collections.singletonMap("log4j.properties", log4jConfig)).build();
kubeClient().getClient().configMaps().inNamespace(namespaceName).createOrReplace(connectLoggingMap);
ExternalLogging connectXternalLogging = new ExternalLoggingBuilder().withNewValueFrom().withConfigMapKeyRef(new ConfigMapKeySelectorBuilder().withName(externalCmName).withKey("log4j.properties").build()).endValueFrom().build();
LOGGER.info("Setting log level of Connect to OFF");
// change to the external logging
KafkaConnectResource.replaceKafkaConnectResourceInSpecificNamespace(clusterName, conn -> {
conn.getSpec().setLogging(connectXternalLogging);
}, namespaceName);
TestUtils.waitFor("Logger change", Constants.GLOBAL_POLL_INTERVAL, Constants.GLOBAL_TIMEOUT, () -> cmdKubeClient().namespace(namespaceName).execInPod(kafkaClientsPodName, "curl", "http://" + KafkaConnectResources.serviceName(clusterName) + ":8083/admin/loggers/root").out().contains("OFF"));
TestUtils.waitFor("log to be empty", Duration.ofMillis(100).toMillis(), Constants.SAFETY_RECONCILIATION_INTERVAL, () -> {
String kcLog = StUtils.getLogFromPodByTime(namespaceName, connectPodName, "", "30s");
return kcLog != null && kcLog.isEmpty() && !DEFAULT_LOG4J_PATTERN.matcher(kcLog).find();
});
assertThat("Connect pod should not roll", DeploymentUtils.depSnapshot(namespaceName, KafkaConnectResources.deploymentName(clusterName)), equalTo(connectSnapshot));
}
use of io.strimzi.api.kafka.model.ExternalLoggingBuilder in project strimzi-kafka-operator by strimzi.
the class LoggingChangeST method testDynamicallySetMM2LoggingLevels.
@ParallelNamespaceTest
@Tag(ROLLING_UPDATE)
@Tag(MIRROR_MAKER2)
@Tag(CONNECT_COMPONENTS)
void testDynamicallySetMM2LoggingLevels(ExtensionContext extensionContext) {
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("connect.root.logger.level", "OFF");
loggers.put("log4j.logger.org.apache.zookeeper", "OFF");
loggers.put("log4j.logger.org.I0Itec.zkclient", "OFF");
loggers.put("log4j.logger.org.reflections", "OFF");
ilOff.setLoggers(loggers);
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());
resourceManager.createResource(extensionContext, KafkaMirrorMaker2Templates.kafkaMirrorMaker2(clusterName, clusterName + "-target", clusterName + "-source", 1, false).editOrNewSpec().withInlineLogging(ilOff).endSpec().build());
String kafkaMM2PodName = kubeClient().namespace(namespaceName).listPods(namespaceName, clusterName, Labels.STRIMZI_KIND_LABEL, KafkaMirrorMaker2.RESOURCE_KIND).get(0).getMetadata().getName();
String mm2LogCheckCmd = "http://localhost:8083/admin/loggers/root";
Map<String, String> mm2Snapshot = DeploymentUtils.depSnapshot(namespaceName, KafkaMirrorMaker2Resources.deploymentName(clusterName));
TestUtils.waitFor("log to be empty", Duration.ofMillis(100).toMillis(), Constants.SAFETY_RECONCILIATION_INTERVAL, () -> {
String mmLog = StUtils.getLogFromPodByTime(namespaceName, kafkaMM2PodName, "", "30s");
return mmLog != null && mmLog.isEmpty() && !DEFAULT_LOG4J_PATTERN.matcher(mmLog).find();
});
LOGGER.info("Changing rootLogger level to DEBUG with inline logging");
InlineLogging ilDebug = new InlineLogging();
loggers.put("connect.root.logger.level", "DEBUG");
ilDebug.setLoggers(loggers);
KafkaMirrorMaker2Resource.replaceKafkaMirrorMaker2ResourceInSpecificNamespace(clusterName, mm2 -> {
mm2.getSpec().setLogging(ilDebug);
}, namespaceName);
LOGGER.info("Waiting for log4j.properties will contain desired settings");
TestUtils.waitFor("Logger change", Constants.GLOBAL_POLL_INTERVAL, Constants.GLOBAL_TIMEOUT, () -> cmdKubeClient().namespace(namespaceName).execInPod(kafkaMM2PodName, "curl", mm2LogCheckCmd).out().contains("DEBUG"));
TestUtils.waitFor("log to not be empty", Duration.ofMillis(100).toMillis(), Constants.SAFETY_RECONCILIATION_INTERVAL, () -> {
String mmLog = StUtils.getLogFromPodByTime(namespaceName, kafkaMM2PodName, "", "30s");
return mmLog != null && !mmLog.isEmpty() && DEFAULT_LOG4J_PATTERN.matcher(mmLog).find();
});
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 %X{connector.context}%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.reflections=ERROR";
String externalCmName = "external-cm";
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();
LOGGER.info("Setting log level of MM2 to OFF");
// change to the external logging
KafkaMirrorMaker2Resource.replaceKafkaMirrorMaker2ResourceInSpecificNamespace(clusterName, mm2 -> {
mm2.getSpec().setLogging(mm2XternalLogging);
}, namespaceName);
TestUtils.waitFor("Logger change", Constants.GLOBAL_POLL_INTERVAL, Constants.GLOBAL_TIMEOUT, () -> cmdKubeClient().namespace(namespaceName).execInPod(kafkaMM2PodName, "curl", mm2LogCheckCmd).out().contains("OFF"));
TestUtils.waitFor("log to not be empty", Duration.ofMillis(100).toMillis(), Constants.SAFETY_RECONCILIATION_INTERVAL, () -> {
String mmLog = StUtils.getLogFromPodByTime(namespaceName, kafkaMM2PodName, "", "30s");
return mmLog != null && !mmLog.isEmpty() && DEFAULT_LOG4J_PATTERN.matcher(mmLog).find();
});
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 LoggingChangeST method testDynamicallySetEOloggingLevels.
@ParallelNamespaceTest
@Tag(ROLLING_UPDATE)
@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));
}
use of io.strimzi.api.kafka.model.ExternalLoggingBuilder in project strimzi 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));
}
Aggregations