-
Notifications
You must be signed in to change notification settings - Fork 294
feat: expose comet metrics through Sparks external monitoring system #3708
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
base: main
Are you sure you want to change the base?
Changes from all commits
ad7de5c
2eb506f
eaa1dc4
2b6dcc1
e6635d7
86a17fb
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 |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
|
|
||
| package org.apache.comet | ||
|
|
||
| import org.apache.spark.CometSource | ||
| import org.apache.spark.sql.execution.QueryExecution | ||
| import org.apache.spark.sql.util.QueryExecutionListener | ||
|
|
||
| class CometMetricsListener extends QueryExecutionListener { | ||
|
|
||
| override def onSuccess(funcName: String, qe: QueryExecution, durationNs: Long): Unit = { | ||
| val stats = CometCoverageStats.forPlan(qe.executedPlan) | ||
| CometSource.recordStats(stats) | ||
| } | ||
|
|
||
| override def onFailure(funcName: String, qe: QueryExecution, exception: Exception): Unit = {} | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
|
|
||
| package org.apache.spark | ||
|
|
||
| import org.apache.spark.metrics.source.Source | ||
|
|
||
| import com.codahale.metrics.{Counter, Gauge, MetricRegistry} | ||
|
|
||
| import org.apache.comet.CometCoverageStats | ||
|
|
||
| /** | ||
| * Exposes following metrics (hooked from CometCoverageStats) | ||
| * - operators.native: Total operators executed natively | ||
| * - operators.spark: Total operators that fell back to Spark | ||
| * - queries.planned: Total queries processed | ||
| * - transitions: Total Spark-to-Comet transitions | ||
| * - acceleration.ratio: native / (native + spark) | ||
| */ | ||
| object CometSource extends Source { | ||
| override val sourceName = "comet" | ||
| override val metricRegistry = new MetricRegistry() | ||
|
|
||
| val NATIVE_OPERATORS: Counter = | ||
| metricRegistry.counter(MetricRegistry.name("operators", "native")) | ||
| val SPARK_OPERATORS: Counter = metricRegistry.counter(MetricRegistry.name("operators", "spark")) | ||
| val QUERIES_PLANNED: Counter = metricRegistry.counter(MetricRegistry.name("queries", "planned")) | ||
| val TRANSITIONS: Counter = metricRegistry.counter(MetricRegistry.name("transitions")) | ||
|
|
||
| metricRegistry.register( | ||
| MetricRegistry.name("acceleration", "ratio"), | ||
| new Gauge[Double] { | ||
| override def getValue: Double = { | ||
| val native = NATIVE_OPERATORS.getCount | ||
| val total = native + SPARK_OPERATORS.getCount | ||
| if (total > 0) native.toDouble / total else 0.0 | ||
| } | ||
| }) | ||
|
|
||
| def recordStats(stats: CometCoverageStats): Unit = { | ||
|
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. This isn't exactly ideal. These stats make sense per
Contributor
Author
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. Sure. But spark does follow a similar approach here but there is always an option to improve granularity
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 wasn't saying the approach is wrong. Just pointing out that for these specific metrics, if the Spark application has multiple plans, the accumulated values are not necessarily meaningful. |
||
| NATIVE_OPERATORS.inc(stats.cometOperators) | ||
| SPARK_OPERATORS.inc(stats.sparkOperators) | ||
| TRANSITIONS.inc(stats.transitions) | ||
| QUERIES_PLANNED.inc() | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,6 +57,9 @@ class CometDriverPlugin extends DriverPlugin with Logging with ShimCometDriverPl | |
| // register CometSparkSessionExtensions if it isn't already registered | ||
| CometDriverPlugin.registerCometSessionExtension(sc.conf) | ||
|
|
||
| // Register Comet metrics | ||
| CometDriverPlugin.registerCometMetrics(sc) | ||
|
|
||
| if (CometSparkSessionExtensions.shouldOverrideMemoryConf(sc.getConf)) { | ||
| val execMemOverhead = if (sc.getConf.contains(EXECUTOR_MEMORY_OVERHEAD.key)) { | ||
| sc.getConf.getSizeAsMb(EXECUTOR_MEMORY_OVERHEAD.key) | ||
|
|
@@ -101,6 +104,25 @@ class CometDriverPlugin extends DriverPlugin with Logging with ShimCometDriverPl | |
| } | ||
|
|
||
| object CometDriverPlugin extends Logging { | ||
| def registerCometMetrics(sc: SparkContext): Unit = { | ||
|
Member
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. Add a configuration to enable this behavior. |
||
| sc.env.metricsSystem.registerSource(CometSource) | ||
|
|
||
| val listenerKey = "spark.sql.queryExecutionListeners" | ||
| val listenerClass = "org.apache.comet.CometMetricsListener" | ||
| val listeners = sc.conf.get(listenerKey, "") | ||
| if (listeners.isEmpty) { | ||
| logInfo(s"Setting $listenerKey=$listenerClass") | ||
| sc.conf.set(listenerKey, listenerClass) | ||
| } else { | ||
| val currentListeners = listeners.split(",").map(_.trim) | ||
| if (!currentListeners.contains(listenerClass)) { | ||
| val newValue = s"$listeners,$listenerClass" | ||
| logInfo(s"Setting $listenerKey=$newValue") | ||
| sc.conf.set(listenerKey, newValue) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| def registerCometSessionExtension(conf: SparkConf): Unit = { | ||
| val extensionKey = StaticSQLConf.SPARK_SESSION_EXTENSIONS.key | ||
| val extensionClass = classOf[CometSparkSessionExtensions].getName | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.