-
Notifications
You must be signed in to change notification settings - Fork 4
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
Add deregistering of metrics #929
Closed
Closed
Changes from all commits
Commits
Show all changes
2 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 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 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 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,47 @@ | ||
package org.apache.spark.datasource | ||
|
||
import org.scalatest.{FlatSpec, Matchers} | ||
import org.apache.spark.SparkEnv | ||
import org.apache.spark.sql.SparkSession | ||
|
||
class MetricsSourceTest extends FlatSpec with Matchers { | ||
val spark: SparkSession = SparkSession | ||
.builder() | ||
.master("local[*]") | ||
.config("spark.ui.enabled", "false") // comment this out to use Spark UI during tests, on https://localhost:4040 by default | ||
// https://medium.com/@mrpowers/how-to-cut-the-run-time-of-a-spark-sbt-test-suite-by-40-52d71219773f | ||
.config("spark.sql.shuffle.partitions", "1") | ||
.config("spark.sql.storeAssignmentPolicy", "legacy") | ||
.config("spark.app.id", this.getClass.getName + math.floor(math.random() * 1000).toLong.toString) | ||
.getOrCreate() | ||
|
||
"A MetricsSource" should "register a new metric only once" in { | ||
val metric = MetricsSource.getOrCreateCounter("prefix", "name") | ||
val sameMetric = MetricsSource.getOrCreateCounter("prefix", "name") | ||
|
||
metric.getCount() should equal(0) | ||
sameMetric.getCount() should equal(0) | ||
|
||
metric.inc() | ||
|
||
metric.getCount() should equal(1) | ||
sameMetric.getCount() should equal(1) | ||
} | ||
|
||
it should "deregister a metric only once" in { | ||
MetricsSource.getOrCreateCounter("removePrefix.jobId", "name") | ||
MetricsSource.getOrCreateCounter("removePrefix.otherJobId", "name") | ||
|
||
Option(MetricsSource.metricsMap.get("removePrefix.jobId.name")).isDefined shouldBe true | ||
Option(MetricsSource.metricsMap.get("removePrefix.otherJobId.name")).isDefined shouldBe true | ||
SparkEnv.get.metricsSystem.getSourcesByName("removePrefix.jobId").size should equal(1) | ||
SparkEnv.get.metricsSystem.getSourcesByName("removePrefix.otherJobId").size should equal(1) | ||
|
||
MetricsSource.removeJobMetrics("removePrefix.jobId") | ||
|
||
Option(MetricsSource.metricsMap.get("removePrefix.jobId.name")).isDefined shouldBe false | ||
Option(MetricsSource.metricsMap.get("removePrefix.otherJobId.name")).isDefined shouldBe true | ||
SparkEnv.get.metricsSystem.getSourcesByName("removePrefix.jobId").size should equal(0) | ||
SparkEnv.get.metricsSystem.getSourcesByName("removePrefix.otherJobId").size should equal(1) | ||
} | ||
} |
This file contains 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.
https://github.com/LucaCanali/Miscellaneous/blob/master/Spark_Dashboard/Spark_dropwizard_metrics_info.md
So it seems like when we'll call this from driver it will not cleanup metrics on executors, but didn't try to verify what actually happens when there's driver and separate executors. Also would be good to double-check if all registered metrics continue to be exported. Just found https://github.com/cognitedata/spark-jdbc/blob/master/src/main/scala/org/apache/spark/metrics/sink/JdbcSink.scala#L89 that seems to try pruning them a little bit (but only the counter type)
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 don't understand why it wouldn't remove from the executors based on this.
Is it because the instance that is removing the sources and the counter will be different in the executor? Meaning that none will be found in the map, and therefore none will be remove as a source?
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 suspect that even though metrics registry is placed in sparkenv, it might still be isolated per-jvm