|
61 | 61 | import io.strimzi.test.TestUtils; |
62 | 62 | import org.apache.logging.log4j.LogManager; |
63 | 63 | import org.apache.logging.log4j.Logger; |
64 | | -import org.junit.jupiter.api.Assumptions; |
65 | 64 | import org.junit.jupiter.api.BeforeAll; |
66 | 65 | import org.junit.jupiter.api.Tag; |
67 | 66 |
|
@@ -2132,88 +2131,117 @@ void testLoggingHierarchy() { |
2132 | 2131 | @ParallelNamespaceTest |
2133 | 2132 | @Tag(ROLLING_UPDATE) |
2134 | 2133 | @TestDoc( |
2135 | | - description = @Desc("This test case checks that changing Logging configuration from internal to external triggers Rolling Update."), |
| 2134 | + description = @Desc("This test case checks that changing Logging configuration from internal to external will not trigger Rolling Update."), |
2136 | 2135 | steps = { |
2137 | 2136 | @Step(value = "Deploy Kafka cluster, without any logging related configuration.", expected = "Cluster is deployed."), |
2138 | | - @Step(value = "Modify Kafka by changing specification of logging to new external value.", expected = "Change in logging specification triggers Rolling Update."), |
2139 | | - @Step(value = "Modify ConfigMap to new logging format.", expected = "Change in logging specification triggers Rolling Update.") |
| 2137 | + @Step(value = "Modify Kafka by changing specification of logging to new external value.", expected = "Change in logging specification doesn't trigger Rolling Update."), |
| 2138 | + @Step(value = "Modify ConfigMap to new logging format.", expected = "Change in logging specification doesn't trigger Rolling Update.") |
2140 | 2139 | }, |
2141 | 2140 | labels = { |
2142 | 2141 | @Label(value = TestDocsLabels.KAFKA), |
2143 | 2142 | @Label(value = TestDocsLabels.LOGGING) |
2144 | 2143 | } |
2145 | 2144 | ) |
2146 | | - void testChangingInternalToExternalLoggingTriggerRollingUpdate() { |
2147 | | - // This test would need some changes since Kafka 4.0.0 uses Log4j2 which provides dynamic logging changes for the brokers and is therefore disabled. |
2148 | | - // This test can be enabled again once we fix the issue: https://github.com/strimzi/strimzi-kafka-operator/issues/11312 |
2149 | | - Assumptions.assumeTrue(TestKafkaVersion.compareDottedVersions(Environment.ST_KAFKA_VERSION, "4.0.0") < 0); |
2150 | | - |
| 2145 | + void testChangingInternalToExternalLoggingDoesNotTriggerRollingUpdate() { |
2151 | 2146 | final TestStorage testStorage = new TestStorage(KubeResourceManager.get().getTestContext()); |
2152 | 2147 |
|
2153 | 2148 | // EO dynamic logging is tested in io.strimzi.systemtest.log.LoggingChangeST.testDynamicallySetEOloggingLevels |
2154 | 2149 | KubeResourceManager.get().createResourceWithWait( |
2155 | 2150 | KafkaNodePoolTemplates.brokerPool(testStorage.getNamespaceName(), testStorage.getBrokerPoolName(), testStorage.getClusterName(), 3).build(), |
2156 | 2151 | KafkaNodePoolTemplates.controllerPool(testStorage.getNamespaceName(), testStorage.getControllerPoolName(), testStorage.getClusterName(), 3).build() |
2157 | 2152 | ); |
2158 | | - KubeResourceManager.get().createResourceWithWait(KafkaTemplates.kafka(testStorage.getNamespaceName(), testStorage.getClusterName(), 3).build()); |
| 2153 | + KubeResourceManager.get().createResourceWithWait( |
| 2154 | + KafkaTemplates.kafka(testStorage.getNamespaceName(), testStorage.getClusterName(), 3).build(), |
| 2155 | + ScraperTemplates.scraperPod(testStorage.getNamespaceName(), testStorage.getScraperName()).build() |
| 2156 | + ); |
2159 | 2157 |
|
2160 | 2158 | Map<String, String> brokerPods = PodUtils.podSnapshot(testStorage.getNamespaceName(), testStorage.getBrokerSelector()); |
2161 | 2159 | Map<String, String> controllerPods = PodUtils.podSnapshot(testStorage.getNamespaceName(), testStorage.getControllerSelector()); |
| 2160 | + String scraperPodName = KubeResourceManager.get().kubeClient().listPodsByPrefixInName(testStorage.getNamespaceName(), testStorage.getScraperName()).get(0).getMetadata().getName(); |
2162 | 2161 |
|
2163 | | - final String loggersConfig = "log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender\n" + |
2164 | | - "log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout\n" + |
2165 | | - "log4j.appender.CONSOLE.layout.ConversionPattern=%d{ISO8601} %p %m (%c) [%t]\n" + |
2166 | | - "kafka.root.logger.level=INFO\n" + |
2167 | | - "log4j.rootLogger=${kafka.root.logger.level}, CONSOLE\n" + |
2168 | | - "log4j.logger.kafka=INFO\n" + |
2169 | | - "log4j.logger.org.apache.kafka=INFO\n" + |
2170 | | - "log4j.logger.kafka.request.logger=WARN, CONSOLE\n" + |
2171 | | - "log4j.logger.kafka.network.Processor=INFO\n" + |
2172 | | - "log4j.logger.kafka.server.KafkaApis=INFO\n" + |
2173 | | - "log4j.logger.kafka.network.RequestChannel$=INFO\n" + |
2174 | | - "log4j.logger.kafka.controller=INFO\n" + |
2175 | | - "log4j.logger.kafka.log.LogCleaner=INFO\n" + |
2176 | | - "log4j.logger.state.change.logger=TRACE\n" + |
2177 | | - "log4j.logger.kafka.authorizer.logger=INFO"; |
| 2162 | + assertThat(KafkaCmdClient.describeKafkaBrokerLoggersUsingPodCli(testStorage.getNamespaceName(), scraperPodName, KafkaResources.plainBootstrapAddress(testStorage.getClusterName()), 0).contains("root=DEBUG"), is(true)); |
| 2163 | + |
| 2164 | + final String loggersConfig = """ |
| 2165 | + status = WARN |
| 2166 | + # Periodic interval for Log4j2 to check the properties and change it accordingly |
| 2167 | + monitorInterval = 10 |
| 2168 | + # Dynamic property |
| 2169 | + property.kafka.root.logger.level = INFO |
| 2170 | + appender.console.type = Console |
| 2171 | + appender.console.name = CONSOLE |
| 2172 | + appender.console.target = SYSTEM_OUT |
| 2173 | + appender.console.layout.type = PatternLayout |
| 2174 | + appender.console.layout.pattern = %d{ISO8601} %p %m (%c) [%t] |
| 2175 | + rootLogger.level = ${kafka.root.logger.level} |
| 2176 | + rootLogger.appenderRef.console.ref = CONSOLE |
| 2177 | + logger.kafka.name = kafka |
| 2178 | + logger.kafka.level = INFO |
| 2179 | + logger.orgapachekafka.name = org.apache.kafka |
| 2180 | + logger.orgapachekafka.level = INFO |
| 2181 | + logger.kafkarequest.name = kafka.request.logger |
| 2182 | + logger.kafkarequest.level = WARN |
| 2183 | + logger.kafkarequest.additivity = false |
| 2184 | + logger.kafkarequest.appenderRef.console.ref = CONSOLE |
| 2185 | + logger.kafkanetproc.name = kafka.network.Processor |
| 2186 | + logger.kafkanetproc.level = INFO |
| 2187 | + logger.kafkaserverapis.name = kafka.server.KafkaApis |
| 2188 | + logger.kafkaserverapis.level = INFO |
| 2189 | + logger.kafkarequestchannel.name = kafka.network.RequestChannel$ |
| 2190 | + logger.kafkarequestchannel.level = INFO |
| 2191 | + logger.kafkacontroller.name = kafka.controller |
| 2192 | + logger.kafkacontroller.level = INFO |
| 2193 | + logger.kafkalogcleaner.name = kafka.log.LogCleaner |
| 2194 | + logger.kafkalogcleaner.level = INFO |
| 2195 | + logger.statechange.name = state.change.logger |
| 2196 | + logger.statechange.level = TRACE |
| 2197 | + logger.kafkabrokerauth.name = kafka.authorizer.logger |
| 2198 | + logger.kafkabrokerauth.level = INFO |
| 2199 | + """; |
2178 | 2200 |
|
2179 | 2201 | final String configMapLoggersName = "loggers-config-map"; |
2180 | 2202 | ConfigMap configMapLoggers = new ConfigMapBuilder() |
2181 | 2203 | .withNewMetadata() |
2182 | 2204 | .withNamespace(testStorage.getNamespaceName()) |
2183 | 2205 | .withName(configMapLoggersName) |
2184 | 2206 | .endMetadata() |
2185 | | - .addToData("log4j-custom.properties", loggersConfig) |
| 2207 | + .addToData("log4j2-custom.properties", loggersConfig) |
2186 | 2208 | .build(); |
2187 | 2209 |
|
2188 | 2210 | ConfigMapKeySelector log4jLoggimgCMselector = new ConfigMapKeySelectorBuilder() |
2189 | 2211 | .withName(configMapLoggersName) |
2190 | | - .withKey("log4j-custom.properties") |
| 2212 | + .withKey("log4j2-custom.properties") |
2191 | 2213 | .build(); |
2192 | 2214 |
|
2193 | 2215 | KubeResourceManager.get().createResourceWithWait(configMapLoggers); |
2194 | 2216 |
|
2195 | 2217 | KafkaUtils.replace(testStorage.getNamespaceName(), testStorage.getClusterName(), kafka -> { |
2196 | 2218 | kafka.getSpec().getKafka().setLogging(new ExternalLoggingBuilder() |
2197 | 2219 | .withNewValueFrom() |
2198 | | - .withConfigMapKeyRef(log4jLoggimgCMselector) |
| 2220 | + .withConfigMapKeyRef(log4jLoggimgCMselector) |
2199 | 2221 | .endValueFrom() |
2200 | 2222 | .build()); |
2201 | 2223 | }); |
2202 | 2224 |
|
2203 | | - LOGGER.info("Waiting for controller pods to roll after change in logging"); |
2204 | | - controllerPods = RollingUpdateUtils.waitTillComponentHasRolledAndPodsReady(testStorage.getNamespaceName(), testStorage.getControllerSelector(), 3, controllerPods); |
| 2225 | + LOGGER.info("Waiting for controller pods to not roll after change in logging"); |
| 2226 | + RollingUpdateUtils.waitForNoRollingUpdate(testStorage.getNamespaceName(), testStorage.getControllerSelector(), controllerPods); |
| 2227 | + |
| 2228 | + LOGGER.info("Waiting for broker pods to not roll after change in logging"); |
| 2229 | + RollingUpdateUtils.waitForNoRollingUpdate(testStorage.getNamespaceName(), testStorage.getBrokerSelector(), brokerPods); |
2205 | 2230 |
|
2206 | | - LOGGER.info("Waiting for broker pods to roll after change in logging"); |
2207 | | - brokerPods = RollingUpdateUtils.waitTillComponentHasRolledAndPodsReady(testStorage.getNamespaceName(), testStorage.getBrokerSelector(), 3, brokerPods); |
| 2231 | + TestUtils.waitFor("Logger change", TestConstants.GLOBAL_POLL_INTERVAL, TestConstants.GLOBAL_TIMEOUT, |
| 2232 | + () -> KafkaCmdClient.describeKafkaBrokerLoggersUsingPodCli(testStorage.getNamespaceName(), scraperPodName, KafkaResources.plainBootstrapAddress(testStorage.getClusterName()), 0).contains("root=INFO")); |
2208 | 2233 |
|
2209 | | - configMapLoggers.getData().put("log4j-custom.properties", loggersConfig.replace("%p %m (%c) [%t]", "%p %m (%c) [%t]%n")); |
| 2234 | + configMapLoggers.getData().put("log4j2-custom.properties", loggersConfig.replace("property.kafka.root.logger.level = INFO", "property.kafka.root.logger.level = WARN")); |
2210 | 2235 | KubeResourceManager.get().updateResource(configMapLoggers); |
2211 | 2236 |
|
2212 | | - LOGGER.info("Waiting for controller pods to roll after change in logging properties config map"); |
2213 | | - RollingUpdateUtils.waitTillComponentHasRolledAndPodsReady(testStorage.getNamespaceName(), testStorage.getControllerSelector(), 3, controllerPods); |
| 2237 | + LOGGER.info("Waiting for controller pods to not roll after change in logging"); |
| 2238 | + RollingUpdateUtils.waitForNoRollingUpdate(testStorage.getNamespaceName(), testStorage.getControllerSelector(), controllerPods); |
2214 | 2239 |
|
2215 | | - LOGGER.info("Waiting for broker pods to roll after change in logging properties config map"); |
2216 | | - RollingUpdateUtils.waitTillComponentHasRolledAndPodsReady(testStorage.getNamespaceName(), testStorage.getBrokerSelector(), 3, brokerPods); |
| 2240 | + LOGGER.info("Waiting for broker pods to not roll after change in logging"); |
| 2241 | + RollingUpdateUtils.waitForNoRollingUpdate(testStorage.getNamespaceName(), testStorage.getBrokerSelector(), brokerPods); |
| 2242 | + |
| 2243 | + TestUtils.waitFor("Logger change", TestConstants.GLOBAL_POLL_INTERVAL, TestConstants.GLOBAL_TIMEOUT, |
| 2244 | + () -> KafkaCmdClient.describeKafkaBrokerLoggersUsingPodCli(testStorage.getNamespaceName(), scraperPodName, KafkaResources.plainBootstrapAddress(testStorage.getClusterName()), 0).contains("root=WARN")); |
2217 | 2245 | } |
2218 | 2246 |
|
2219 | 2247 | @BeforeAll |
|
0 commit comments