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
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private[spark] class MetricsConfig(conf: SparkConf) extends Logging {
val prefix = "spark.metrics.conf."
conf.getAll.foreach {
case (k, v) if k.startsWith(prefix) =>
properties.setProperty(k.substring(prefix.length()), v)
properties.setProperty(k.substring(prefix.length()).trim(), v.trim())
case _ =>
}

Expand All @@ -78,7 +78,7 @@ private[spark] class MetricsConfig(conf: SparkConf) extends Logging {
val defaultSubProperties = perInstanceSubProperties(DEFAULT_PREFIX).asScala
for ((instance, prop) <- perInstanceSubProperties if (instance != DEFAULT_PREFIX);
(k, v) <- defaultSubProperties if (prop.get(k) == null)) {
prop.put(k, v)
prop.put(k.trim(), v.trim())
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,20 @@ class MetricsConfigSuite extends SparkFunSuite with BeforeAndAfter {
assert(servletProps.size() === 2)
}

test("MetricsConfig with properties with spaces") {
val sparkConf = new SparkConf(loadDefaults = false)
setMetricsProperty(sparkConf, "*.sink.console.class",
" org.apache.spark.metrics.sink.ConsoleSink ")
setMetricsProperty(sparkConf, "*.sink.console.period", "10 ")
val conf = new MetricsConfig(sparkConf)
conf.initialize()

val property = conf.getInstance("random")
assert(property.getProperty("sink.console.class") ===
"org.apache.spark.metrics.sink.ConsoleSink")
assert(property.getProperty("sink.console.period") === "10")
}

private def setMetricsProperty(conf: SparkConf, name: String, value: String): Unit = {
conf.set(s"spark.metrics.conf.$name", value)
}
Expand Down