Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ public static Set<String> configNames() {
}

public static ConfigDef configDef() {
return new ConfigDef(CONFIG);
return new ConfigDef(CONFIG);
}

public static void main(String[] args) {
Expand Down
18 changes: 15 additions & 3 deletions core/src/main/scala/kafka/log/LogConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,17 @@ object LogConfig {
"[PartitionId]:[BrokerId],[PartitionId]:[BrokerId]:... or alternatively the wildcard '*' can be used to throttle " +
"all replicas for this topic."

private class LogConfigDef extends ConfigDef {
private[log] val ServerDefaultHeaderName = "Server Default Property"

// Package private for testing
private[log] class LogConfigDef(base: ConfigDef) extends ConfigDef(base) {
def this() = this(new ConfigDef)

private final val serverDefaultConfigNames = mutable.Map[String, String]()
base match {
case b: LogConfigDef => serverDefaultConfigNames ++= b.serverDefaultConfigNames
case _ =>
}

def define(name: String, defType: ConfigDef.Type, defaultValue: Any, validator: Validator,
importance: ConfigDef.Importance, doc: String, serverDefaultConfigName: String): LogConfigDef = {
Expand All @@ -206,18 +214,22 @@ object LogConfig {
this
}

override def headers = List("Name", "Description", "Type", "Default", "Valid Values", "Server Default Property", "Importance").asJava
override def headers = List("Name", "Description", "Type", "Default", "Valid Values", ServerDefaultHeaderName,
"Importance").asJava

override def getConfigValue(key: ConfigKey, headerName: String): String = {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we can come up with a better name. I was having a hard time understanding this patch because this is named so generically. Maybe something like docStringForHeader or something like that?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I agree that it's not a good name. I thought about renaming it too, but then decided to limit the scope. Happy to do it given your feedback.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is grey area as far as compatibility is concerned since ConfigKey is public. Let's go ahead and leave it for now.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getConfigValue is defined in ConfigDef and it's protected. However, ConfigDef is designed to be inherited from, so it could be considered a compatibility break to rename it. I agree with you that it's best to leave it for now.

headerName match {
case "Server Default Property" => serverDefaultConfigNames.get(key.name).get
case ServerDefaultHeaderName => serverDefaultConfigNames.getOrElse(key.name, null)
case _ => super.getConfigValue(key, headerName)
}
}

def serverConfigName(configName: String): Option[String] = serverDefaultConfigNames.get(configName)
}

// Package private for testing, return a copy since it's a mutable global variable
private[log] def configDefCopy: LogConfigDef = new LogConfigDef(configDef)

private val configDef: LogConfigDef = {
import org.apache.kafka.common.config.ConfigDef.Importance._
import org.apache.kafka.common.config.ConfigDef.Range._
Expand Down
46 changes: 44 additions & 2 deletions core/src/test/scala/unit/kafka/log/LogConfigTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ package kafka.log

import java.util.Properties

import kafka.server.{ThrottledReplicaListValidator, KafkaConfig, KafkaServer}
import kafka.server.{KafkaConfig, KafkaServer, ThrottledReplicaListValidator}
import kafka.utils.TestUtils
import org.apache.kafka.common.config.ConfigException
import org.apache.kafka.common.config.ConfigDef.Importance.MEDIUM
import org.apache.kafka.common.config.ConfigDef.Type.INT
import org.apache.kafka.common.config.{ConfigException, TopicConfig}
import org.junit.{Assert, Test}
import org.junit.Assert._
import org.scalatest.Assertions._
Expand Down Expand Up @@ -113,6 +115,46 @@ class LogConfigTest {
assertFalse(isValid("100:0,10 : "))
}

/* Sanity check that toHtml produces one of the expected configs */
@Test
def testToHtml(): Unit = {
val html = LogConfig.configDefCopy.toHtmlTable
val expectedConfig = "<td>file.delete.delay.ms</td>"
assertTrue(s"Could not find `$expectedConfig` in:\n $html", html.contains(expectedConfig))
}

/* Sanity check that toEnrichedRst produces one of the expected configs */
@Test
def testToEnrichedRst(): Unit = {
val rst = LogConfig.configDefCopy.toEnrichedRst
val expectedConfig = "``file.delete.delay.ms``"
assertTrue(s"Could not find `$expectedConfig` in:\n $rst", rst.contains(expectedConfig))
}

/* Sanity check that toEnrichedRst produces one of the expected configs */
@Test
def testToRst(): Unit = {
val rst = LogConfig.configDefCopy.toRst
val expectedConfig = "``file.delete.delay.ms``"
assertTrue(s"Could not find `$expectedConfig` in:\n $rst", rst.contains(expectedConfig))
}

@Test
def testGetConfigValue(): Unit = {
// Add a config that doesn't set the `serverDefaultConfigName`
val configDef = LogConfig.configDefCopy
val configNameWithNoServerMapping = "log.foo"
configDef.define(configNameWithNoServerMapping, INT, 1, MEDIUM, s"$configNameWithNoServerMapping doc")

val deleteDelayKey = configDef.configKeys.get(TopicConfig.FILE_DELETE_DELAY_MS_CONFIG)
val deleteDelayServerDefault = configDef.getConfigValue(deleteDelayKey, LogConfig.ServerDefaultHeaderName)
assertEquals(KafkaConfig.LogDeleteDelayMsProp, deleteDelayServerDefault)

val keyWithNoServerMapping = configDef.configKeys.get(configNameWithNoServerMapping)
val nullServerDefault = configDef.getConfigValue(keyWithNoServerMapping, LogConfig.ServerDefaultHeaderName)
assertNull(nullServerDefault)
}

private def isValid(configValue: String): Boolean = {
try {
ThrottledReplicaListValidator.ensureValidString("", configValue)
Expand Down