Browse Source

KAFKA-8857; Don't check synonyms while determining if config is readOnly (#7278)

Reviewers: Manikumar Reddy <manikumar.reddy@gmail.com>
pull/7127/head
Rajini Sivaram 5 years ago committed by GitHub
parent
commit
c9318ced19
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      core/src/main/scala/kafka/server/AdminManager.scala
  2. 41
      core/src/test/scala/integration/kafka/server/DynamicBrokerReconfigurationTest.scala

2
core/src/main/scala/kafka/server/AdminManager.scala

@ -661,7 +661,7 @@ class AdminManager(val config: KafkaConfig,
.filter(perBrokerConfig || _.source == ConfigSource.DYNAMIC_DEFAULT_BROKER_CONFIG) .filter(perBrokerConfig || _.source == ConfigSource.DYNAMIC_DEFAULT_BROKER_CONFIG)
val synonyms = if (!includeSynonyms) List.empty else allSynonyms val synonyms = if (!includeSynonyms) List.empty else allSynonyms
val source = if (allSynonyms.isEmpty) ConfigSource.DEFAULT_CONFIG else allSynonyms.head.source val source = if (allSynonyms.isEmpty) ConfigSource.DEFAULT_CONFIG else allSynonyms.head.source
val readOnly = !allNames.exists(DynamicBrokerConfig.AllDynamicConfigs.contains) val readOnly = !DynamicBrokerConfig.AllDynamicConfigs.contains(name)
new DescribeConfigsResponse.ConfigEntry(name, valueAsString, source, isSensitive, readOnly, synonyms.asJava) new DescribeConfigsResponse.ConfigEntry(name, valueAsString, source, isSensitive, readOnly, synonyms.asJava)
} }
} }

41
core/src/test/scala/integration/kafka/server/DynamicBrokerReconfigurationTest.scala

@ -119,6 +119,8 @@ class DynamicBrokerReconfigurationTest extends ZooKeeperTestHarness with SaslSet
props.put(KafkaConfig.NumReplicaFetchersProp, "2") // greater than one to test reducing threads props.put(KafkaConfig.NumReplicaFetchersProp, "2") // greater than one to test reducing threads
props.put(KafkaConfig.ProducerQuotaBytesPerSecondDefaultProp, "10000000") // non-default value to trigger a new metric props.put(KafkaConfig.ProducerQuotaBytesPerSecondDefaultProp, "10000000") // non-default value to trigger a new metric
props.put(KafkaConfig.PasswordEncoderSecretProp, "dynamic-config-secret") props.put(KafkaConfig.PasswordEncoderSecretProp, "dynamic-config-secret")
props.put(KafkaConfig.LogRetentionTimeMillisProp, 1680000000.toString)
props.put(KafkaConfig.LogRetentionTimeHoursProp, 168.toString)
props ++= sslProperties1 props ++= sslProperties1
props ++= securityProps(sslProperties1, KEYSTORE_PROPS, listenerPrefix(SecureInternal)) props ++= securityProps(sslProperties1, KEYSTORE_PROPS, listenerPrefix(SecureInternal))
@ -159,9 +161,10 @@ class DynamicBrokerReconfigurationTest extends ZooKeeperTestHarness with SaslSet
} }
@Test @Test
def testKeyStoreDescribeUsingAdminClient(): Unit = { def testConfigDescribeUsingAdminClient(): Unit = {
def verifyConfig(configName: String, configEntry: ConfigEntry, isSensitive: Boolean, expectedProps: Properties): Unit = { def verifyConfig(configName: String, configEntry: ConfigEntry, isSensitive: Boolean, isReadOnly: Boolean,
expectedProps: Properties): Unit = {
if (isSensitive) { if (isSensitive) {
assertTrue(s"Value is sensitive: $configName", configEntry.isSensitive) assertTrue(s"Value is sensitive: $configName", configEntry.isSensitive)
assertNull(s"Sensitive value returned for $configName", configEntry.value) assertNull(s"Sensitive value returned for $configName", configEntry.value)
@ -169,6 +172,7 @@ class DynamicBrokerReconfigurationTest extends ZooKeeperTestHarness with SaslSet
assertFalse(s"Config is not sensitive: $configName", configEntry.isSensitive) assertFalse(s"Config is not sensitive: $configName", configEntry.isSensitive)
assertEquals(expectedProps.getProperty(configName), configEntry.value) assertEquals(expectedProps.getProperty(configName), configEntry.value)
} }
assertEquals(s"isReadOnly incorrect for $configName: $configEntry", isReadOnly, configEntry.isReadOnly)
} }
def verifySynonym(configName: String, synonym: ConfigSynonym, isSensitive: Boolean, def verifySynonym(configName: String, synonym: ConfigSynonym, isSensitive: Boolean,
@ -203,7 +207,7 @@ class DynamicBrokerReconfigurationTest extends ZooKeeperTestHarness with SaslSet
KEYSTORE_PROPS.asScala.foreach { configName => KEYSTORE_PROPS.asScala.foreach { configName =>
val desc = configEntry(configDesc, s"$prefix$configName") val desc = configEntry(configDesc, s"$prefix$configName")
val isSensitive = configName.contains("password") val isSensitive = configName.contains("password")
verifyConfig(configName, desc, isSensitive, if (prefix.isEmpty) invalidSslProperties else sslProperties1) verifyConfig(configName, desc, isSensitive, isReadOnly = prefix.nonEmpty, if (prefix.isEmpty) invalidSslProperties else sslProperties1)
val defaultValue = if (configName == SSL_KEYSTORE_TYPE_CONFIG) Some("JKS") else None val defaultValue = if (configName == SSL_KEYSTORE_TYPE_CONFIG) Some("JKS") else None
verifySynonyms(configName, desc.synonyms, isSensitive, prefix, defaultValue) verifySynonyms(configName, desc.synonyms, isSensitive, prefix, defaultValue)
} }
@ -215,6 +219,37 @@ class DynamicBrokerReconfigurationTest extends ZooKeeperTestHarness with SaslSet
val configDesc = describeConfig(adminClient) val configDesc = describeConfig(adminClient)
verifySslConfig("listener.name.external.", sslProperties1, configDesc) verifySslConfig("listener.name.external.", sslProperties1, configDesc)
verifySslConfig("", invalidSslProperties, configDesc) verifySslConfig("", invalidSslProperties, configDesc)
// Verify a few log configs with and without synonyms
val expectedProps = new Properties
expectedProps.setProperty(KafkaConfig.LogRetentionTimeMillisProp, "1680000000")
expectedProps.setProperty(KafkaConfig.LogRetentionTimeHoursProp, "168")
expectedProps.setProperty(KafkaConfig.LogRollTimeHoursProp, "168")
expectedProps.setProperty(KafkaConfig.LogCleanerThreadsProp, "1")
val logRetentionMs = configEntry(configDesc, KafkaConfig.LogRetentionTimeMillisProp)
verifyConfig(KafkaConfig.LogRetentionTimeMillisProp, logRetentionMs,
isSensitive = false, isReadOnly = false, expectedProps)
val logRetentionHours = configEntry(configDesc, KafkaConfig.LogRetentionTimeHoursProp)
verifyConfig(KafkaConfig.LogRetentionTimeHoursProp, logRetentionHours,
isSensitive = false, isReadOnly = true, expectedProps)
val logRollHours = configEntry(configDesc, KafkaConfig.LogRollTimeHoursProp)
verifyConfig(KafkaConfig.LogRollTimeHoursProp, logRollHours,
isSensitive = false, isReadOnly = true, expectedProps)
val logCleanerThreads = configEntry(configDesc, KafkaConfig.LogCleanerThreadsProp)
verifyConfig(KafkaConfig.LogCleanerThreadsProp, logCleanerThreads,
isSensitive = false, isReadOnly = false, expectedProps)
def synonymsList(configEntry: ConfigEntry): List[(String, ConfigSource)] =
configEntry.synonyms.asScala.map(s => (s.name, s.source)).toList
assertEquals(List((KafkaConfig.LogRetentionTimeMillisProp, ConfigSource.STATIC_BROKER_CONFIG),
(KafkaConfig.LogRetentionTimeHoursProp, ConfigSource.STATIC_BROKER_CONFIG),
(KafkaConfig.LogRetentionTimeHoursProp, ConfigSource.DEFAULT_CONFIG)),
synonymsList(logRetentionMs))
assertEquals(List((KafkaConfig.LogRetentionTimeHoursProp, ConfigSource.STATIC_BROKER_CONFIG),
(KafkaConfig.LogRetentionTimeHoursProp, ConfigSource.DEFAULT_CONFIG)),
synonymsList(logRetentionHours))
assertEquals(List((KafkaConfig.LogRollTimeHoursProp, ConfigSource.DEFAULT_CONFIG)), synonymsList(logRollHours))
assertEquals(List((KafkaConfig.LogCleanerThreadsProp, ConfigSource.DEFAULT_CONFIG)), synonymsList(logCleanerThreads))
} }
@Test @Test

Loading…
Cancel
Save