-
Notifications
You must be signed in to change notification settings - Fork 293
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
Open
coderfender
wants to merge
4
commits into
apache:main
Choose a base branch
from
coderfender:project_comet_metrics
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+178
−1
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
spark/src/main/scala/org/apache/comet/CometMetricsListener.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 = {} | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 = { | ||
| NATIVE_OPERATORS.inc(stats.cometOperators) | ||
| SPARK_OPERATORS.inc(stats.sparkOperators) | ||
| TRANSITIONS.inc(stats.transitions) | ||
| QUERIES_PLANNED.inc() | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This isn't exactly ideal. These stats make sense per
plan. Here we are incrementing all metrics globally, so all plans that are executed across all sessions in a Spark application will have their counts accumulated and may provide no useful information.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.
Sure. But spark does follow a similar approach here but there is always an option to improve granularity
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.
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.