Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 2 additions & 14 deletions core/src/main/scala/kafka/network/RequestChannel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@ import java.util.concurrent._
import com.fasterxml.jackson.databind.JsonNode
import com.typesafe.scalalogging.Logger
import com.yammer.metrics.core.Meter
import kafka.log.LogConfig
import kafka.metrics.KafkaMetricsGroup
import kafka.server.KafkaConfig
import kafka.utils.{Logging, NotNothing, Pool}
import kafka.utils.Implicits._
import org.apache.kafka.common.config.types.Password
import org.apache.kafka.common.config.ConfigResource
import org.apache.kafka.common.memory.MemoryPool
import org.apache.kafka.common.message.IncrementalAlterConfigsRequestData
Expand Down Expand Up @@ -164,21 +162,11 @@ object RequestChannel extends Logging {

def loggableRequest: AbstractRequest = {

def loggableValue(resourceType: ConfigResource.Type, name: String, value: String): String = {
val maybeSensitive = resourceType match {
case ConfigResource.Type.BROKER => KafkaConfig.maybeSensitive(KafkaConfig.configType(name))
case ConfigResource.Type.TOPIC => KafkaConfig.maybeSensitive(LogConfig.configType(name))
case ConfigResource.Type.BROKER_LOGGER => false
case _ => true
}
if (maybeSensitive) Password.HIDDEN else value
}

bodyAndSize.request match {
case alterConfigs: AlterConfigsRequest =>
val loggableConfigs = alterConfigs.configs().asScala.map { case (resource, config) =>
val loggableEntries = new AlterConfigsRequest.Config(config.entries.asScala.map { entry =>
new AlterConfigsRequest.ConfigEntry(entry.name, loggableValue(resource.`type`, entry.name, entry.value))
new AlterConfigsRequest.ConfigEntry(entry.name, KafkaConfig.loggableValue(resource.`type`, entry.name, entry.value))
}.asJavaCollection)
(resource, loggableEntries)
}.asJava
Expand All @@ -193,7 +181,7 @@ object RequestChannel extends Logging {
resource.configs.forEach { config =>
newResource.configs.add(new AlterableConfig()
.setName(config.name)
.setValue(loggableValue(ConfigResource.Type.forId(resource.resourceType), config.name, config.value))
.setValue(KafkaConfig.loggableValue(ConfigResource.Type.forId(resource.resourceType), config.name, config.value))
.setConfigOperation(config.configOperation))
}
resources.add(newResource)
Expand Down
22 changes: 19 additions & 3 deletions core/src/main/scala/kafka/server/AdminManager.scala
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ class AdminManager(val config: KafkaConfig,
adminZkClient.validateTopicConfig(topic, configProps)
validateConfigPolicy(resource, configEntriesMap)
if (!validateOnly) {
info(s"Updating topic $topic with new configuration $config")
info(s"Updating topic $topic with new configuration : ${toLoggableProps(resource, configProps).mkString(",")}")
adminZkClient.changeTopicConfig(topic, configProps)
}

Expand All @@ -522,20 +522,36 @@ class AdminManager(val config: KafkaConfig,
if (!validateOnly) {
if (perBrokerConfig)
this.config.dynamicConfig.reloadUpdatedFilesWithoutConfigChange(configProps)

if (perBrokerConfig)
info(s"Updating broker ${brokerId.get} with new configuration : ${toLoggableProps(resource, configProps).mkString(",")}")
else
info(s"Updating brokers with new configuration : ${toLoggableProps(resource, configProps).mkString(",")}")

adminZkClient.changeBrokerConfig(brokerId,
this.config.dynamicConfig.toPersistentProps(configProps, perBrokerConfig))
}

resource -> ApiError.NONE
}

private def toLoggableProps(resource: ConfigResource, configProps: Properties): Map[String, String] = {
configProps.asScala.map {
case (key, value) => (key, KafkaConfig.loggableValue(resource.`type`, key, value))
}
}

private def alterLogLevelConfigs(alterConfigOps: Seq[AlterConfigOp]): Unit = {
alterConfigOps.foreach { alterConfigOp =>
val loggerName = alterConfigOp.configEntry().name()
val logLevel = alterConfigOp.configEntry().value()
alterConfigOp.opType() match {
case OpType.SET => Log4jController.logLevel(loggerName, logLevel)
case OpType.DELETE => Log4jController.unsetLogLevel(loggerName)
case OpType.SET =>
info(s"Updating the log level of $loggerName to $logLevel")
Log4jController.logLevel(loggerName, logLevel)
case OpType.DELETE =>
info(s"Unset the log level of $loggerName")
Log4jController.unsetLogLevel(loggerName)
case _ => throw new IllegalArgumentException(
s"Log level cannot be changed for OpType: ${alterConfigOp.opType()}")
}
Expand Down
14 changes: 12 additions & 2 deletions core/src/main/scala/kafka/server/KafkaConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ import kafka.api.{ApiVersion, ApiVersionValidator, KAFKA_0_10_0_IV1, KAFKA_2_1_I
import kafka.cluster.EndPoint
import kafka.coordinator.group.OffsetConfig
import kafka.coordinator.transaction.{TransactionLog, TransactionStateManager}
import kafka.log.LogConfig
import kafka.message.{BrokerCompressionCodec, CompressionCodec, ZStdCompressionCodec}
import kafka.security.authorizer.AuthorizerUtils
import kafka.utils.CoreUtils
import kafka.utils.Implicits._
import org.apache.kafka.clients.CommonClientConfigs
import org.apache.kafka.common.Reconfigurable
import org.apache.kafka.common.config.SecurityConfig
import org.apache.kafka.common.config.{AbstractConfig, ConfigDef, ConfigException, ConfigResource, SaslConfigs, SecurityConfig, SslClientAuth, SslConfigs, TopicConfig}
import org.apache.kafka.common.config.ConfigDef.{ConfigKey, ValidList}
import org.apache.kafka.common.config.internals.BrokerSecurityConfigs
import org.apache.kafka.common.config.types.Password
import org.apache.kafka.common.config.{AbstractConfig, ConfigDef, ConfigException, SaslConfigs, SslClientAuth, SslConfigs, TopicConfig}
import org.apache.kafka.common.metrics.Sensor
import org.apache.kafka.common.network.ListenerName
import org.apache.kafka.common.record.{LegacyRecord, Records, TimestampType}
Expand Down Expand Up @@ -1311,6 +1311,16 @@ object KafkaConfig {
// If we can't determine the config entry type, treat it as a sensitive config to be safe
configType.isEmpty || configType.contains(ConfigDef.Type.PASSWORD)
}

def loggableValue(resourceType: ConfigResource.Type, name: String, value: String): String = {
val maybeSensitive = resourceType match {
case ConfigResource.Type.BROKER => KafkaConfig.maybeSensitive(KafkaConfig.configType(name))
case ConfigResource.Type.TOPIC => KafkaConfig.maybeSensitive(LogConfig.configType(name))
case ConfigResource.Type.BROKER_LOGGER => false
case _ => true
}
if (maybeSensitive) Password.HIDDEN else value
}
}

class KafkaConfig(val props: java.util.Map[_, _], doLog: Boolean, dynamicConfigOverride: Option[DynamicBrokerConfig])
Expand Down