-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-5847] Allow for namespacing metrics by conf params other than spark.app.id #4632
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,7 +34,9 @@ private[spark] class MetricsConfig(conf: SparkConf) extends Logging { | |
| private val DEFAULT_METRICS_CONF_FILENAME = "metrics.properties" | ||
|
|
||
| private[metrics] val properties = new Properties() | ||
| private[metrics] var propertyCategories: mutable.HashMap[String, Properties] = null | ||
| private[metrics] var perInstanceProperties: mutable.HashMap[String, Properties] = null | ||
|
|
||
| private[metrics] var metricsNamespaceConfParam: String = null | ||
|
|
||
| private def setDefaultProperties(prop: Properties) { | ||
| prop.setProperty("*.sink.servlet.class", "org.apache.spark.metrics.sink.MetricsServlet") | ||
|
|
@@ -57,14 +59,16 @@ private[spark] class MetricsConfig(conf: SparkConf) extends Logging { | |
| case _ => | ||
| } | ||
|
|
||
| propertyCategories = subProperties(properties, INSTANCE_REGEX) | ||
| if (propertyCategories.contains(DEFAULT_PREFIX)) { | ||
| val defaultProperty = propertyCategories(DEFAULT_PREFIX).asScala | ||
| for((inst, prop) <- propertyCategories if (inst != DEFAULT_PREFIX); | ||
| perInstanceProperties = subProperties(properties, INSTANCE_REGEX) | ||
| if (perInstanceProperties.contains(DEFAULT_PREFIX)) { | ||
| val defaultProperty = perInstanceProperties(DEFAULT_PREFIX).asScala | ||
| for((inst, prop) <- perInstanceProperties if (inst != DEFAULT_PREFIX); | ||
| (k, v) <- defaultProperty if (prop.get(k) == null)) { | ||
| prop.put(k, v) | ||
| } | ||
| } | ||
|
|
||
| metricsNamespaceConfParam = properties.getProperty("namespace-conf-param", "spark.app.id") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not a fan of this config name. How about one of:
Or something like those? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In graphite-environment you're calling something like this a prefix. How about 'metrics.appPrefix' ? |
||
| } | ||
|
|
||
| def subProperties(prop: Properties, regex: Regex): mutable.HashMap[String, Properties] = { | ||
|
|
@@ -79,9 +83,9 @@ private[spark] class MetricsConfig(conf: SparkConf) extends Logging { | |
| } | ||
|
|
||
| def getInstance(inst: String): Properties = { | ||
| propertyCategories.get(inst) match { | ||
| perInstanceProperties.get(inst) match { | ||
| case Some(s) => s | ||
| case None => propertyCategories.getOrElse(DEFAULT_PREFIX, new Properties) | ||
| case None => perInstanceProperties.getOrElse(DEFAULT_PREFIX, new Properties) | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -124,7 +124,7 @@ private[spark] class MetricsSystem private ( | |
| * application, executor/driver and metric source. | ||
| */ | ||
| private[spark] def buildRegistryName(source: Source): String = { | ||
| val appId = conf.getOption("spark.app.id") | ||
| val appId = conf.getOption(metricsConfig.metricsNamespaceConfParam) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. probably a good idea to change the name of this variable now. |
||
| val executorId = conf.getOption("spark.executor.id") | ||
| val defaultName = MetricRegistry.name(source.sourceName) | ||
|
|
||
|
|
@@ -135,8 +135,12 @@ private[spark] class MetricsSystem private ( | |
| // Only Driver and Executor set spark.app.id and spark.executor.id. | ||
| // Other instance types, e.g. Master and Worker, are not related to a specific application. | ||
| val warningMsg = s"Using default name $defaultName for source because %s is not set." | ||
| if (appId.isEmpty) { logWarning(warningMsg.format("spark.app.id")) } | ||
| if (executorId.isEmpty) { logWarning(warningMsg.format("spark.executor.id")) } | ||
| if (appId.isEmpty) { | ||
| logWarning(warningMsg.format(metricsConfig.metricsNamespaceConfParam)) | ||
| } | ||
| if (executorId.isEmpty) { | ||
| logWarning(warningMsg.format("spark.executor.id")) | ||
| } | ||
| defaultName | ||
| } | ||
| } else { defaultName } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| # | ||
| # Licensed to the Apache Software Foundation (ASF) under one or more | ||
| # contributor license agreements. See the NOTICE file distributed with | ||
| # this work for additional information regarding copyright ownership. | ||
| # The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| # (the "License"); you may not use this file except in compliance with | ||
| # the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # | ||
|
|
||
| namespace-conf-param = spark.app.name | ||
|
|
||
| *.sink.console.period = 10 | ||
| *.sink.console.unit = seconds | ||
| *.source.jvm.class = org.apache.spark.metrics.source.JvmSource | ||
| master.sink.console.period = 20 | ||
| master.sink.console.unit = minutes | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| # | ||
| # Licensed to the Apache Software Foundation (ASF) under one or more | ||
| # contributor license agreements. See the NOTICE file distributed with | ||
| # this work for additional information regarding copyright ownership. | ||
| # The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| # (the "License"); you may not use this file except in compliance with | ||
| # the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # | ||
|
|
||
| namespace-conf-param = spark.app.name | ||
|
|
||
| *.sink.console.period = 10 | ||
| *.sink.console.unit = seconds | ||
| test.sink.console.class = org.apache.spark.metrics.sink.ConsoleSink | ||
| test.sink.console.period = 20 | ||
| test.sink.console.unit = minutes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since you're touching this...
for (