-
Notifications
You must be signed in to change notification settings - Fork 28.7k
[SPARK-8743] [Streaming]: Deregister Codahale metrics for streaming when StreamingContext is closed #7250
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
Closed
Closed
[SPARK-8743] [Streaming]: Deregister Codahale metrics for streaming when StreamingContext is closed #7250
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
92fa04b
SPARK-8743: Added the registerSource method call to the start method …
a665965
Added // instead of /** for commenting in code
7621adf
Added indentation and Space at the comment on line 578; Registering..
18bcc7e
Added test case for de-register metrics and made a change to the scop…
e4f00d7
Added additional variable to check the updated Sources size value to …
f5e47e0
Added the removeSource method in try
d04fd2a
Removed the assert for the env field, added the registerSource line i…
e2c3bf8
Added test to check registering and de-registering of streamingSource
742398c
Removed unused imports
ca081fa
Moved the registerSource() call before line 601
33a2091
Changed scope of sources and corrected comments for helper
a67918c
Removed extra line in Helper Methods section
74598ce
Added helper method for private methods and changed the test logic to…
e37a2f3
Changed import statements to remove unnecessary imports and add speci…
f54afcf
Removed types for fields in test for registering and deregistering me…
ea0dc1a
Changed imports statements, negated test statement and removed postfix
a0f1950
Removed added comment to Assert for INITIALIZED state
2a81287
Removing the INITIALIZED check since after start() the state moves to…
5d3af31
Move the INITIALIZED state check to when the ssc is initialized
299a57d
SPARK-8743: Added the registerSource method call to the start method …
b86e80b
Merge branch 'SPARK-8743' of https://github.com/nssalian/spark into S…
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
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 |
---|---|---|
|
@@ -19,19 +19,20 @@ package org.apache.spark.streaming | |
|
||
import java.io.{File, NotSerializableException} | ||
import java.util.concurrent.atomic.AtomicInteger | ||
|
||
import org.apache.commons.io.FileUtils | ||
import org.apache.spark.metrics.MetricsSystem | ||
import org.apache.spark.metrics.source.Source | ||
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. These need to be with other spark imports, and the spark imports shouldn't have a blank line in the middle. |
||
import org.scalatest.concurrent.Eventually._ | ||
import org.scalatest.concurrent.Timeouts | ||
import org.scalatest.exceptions.TestFailedDueToTimeoutException | ||
import org.scalatest.time.SpanSugar._ | ||
import org.scalatest.{Assertions, BeforeAndAfter} | ||
|
||
import org.scalatest.{PrivateMethodTester, Assertions, BeforeAndAfter} | ||
import org.apache.spark.storage.StorageLevel | ||
import org.apache.spark.streaming.dstream.DStream | ||
import org.apache.spark.streaming.receiver.Receiver | ||
import org.apache.spark.util.Utils | ||
import org.apache.spark.{Logging, SparkConf, SparkContext, SparkException, SparkFunSuite} | ||
import org.apache.spark.{Logging, SparkConf, SparkContext, SparkFunSuite} | ||
import scala.collection.mutable.ArrayBuffer | ||
|
||
|
||
class StreamingContextSuite extends SparkFunSuite with BeforeAndAfter with Timeouts with Logging { | ||
|
@@ -297,6 +298,26 @@ class StreamingContextSuite extends SparkFunSuite with BeforeAndAfter with Timeo | |
Thread.sleep(100) | ||
} | ||
|
||
test("registering and de-registering of streamingSource") { | ||
val conf = new SparkConf().setMaster(master).setAppName(appName) | ||
ssc = new StreamingContext(conf, batchDuration) | ||
assert(ssc.getState() === StreamingContextState.INITIALIZED) | ||
addInputStream(ssc).register() | ||
ssc.start() | ||
|
||
val sources = StreamingContextSuite.getSources(ssc.env.metricsSystem) | ||
val streamingSource = StreamingContextSuite.getStreamingSource(ssc) | ||
assert(sources.contains(streamingSource)) | ||
assert(ssc.getState() === StreamingContextState.ACTIVE) | ||
Thread.sleep(100) | ||
|
||
ssc.stop() | ||
val sourcesAfterStop = StreamingContextSuite.getSources(ssc.env.metricsSystem) | ||
val streamingSourceAfterStop = StreamingContextSuite.getStreamingSource(ssc) | ||
assert(ssc.getState() === StreamingContextState.STOPPED) | ||
assert(!sourcesAfterStop.contains(streamingSourceAfterStop)) | ||
} | ||
|
||
test("awaitTermination") { | ||
ssc = new StreamingContext(master, appName, batchDuration) | ||
val inputStream = addInputStream(ssc) | ||
|
@@ -796,3 +817,21 @@ package object testPackage extends Assertions { | |
} | ||
} | ||
} | ||
|
||
/** | ||
* Helper methods for testing StreamingContextSuite. | ||
* This includes methods to access private methods and fields in StreamingContext and MetricsSystem. | ||
*/ | ||
private object StreamingContextSuite extends PrivateMethodTester { | ||
private val _sources = PrivateMethod[ArrayBuffer[Source]]('sources) | ||
private def getSources(metricsSystem: MetricsSystem): ArrayBuffer[Source] = { | ||
metricsSystem.invokePrivate(_sources()) | ||
} | ||
private val _streamingSource = PrivateMethod[StreamingSource]('streamingSource) | ||
private def getStreamingSource(streamingContext: StreamingContext): StreamingSource = { | ||
streamingContext.invokePrivate(_streamingSource()) | ||
} | ||
} | ||
|
||
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. extra empty line |
||
|
||
|
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.
I think here remove the source in
ACTIVE
state may introduce some corner case problem. For example, since metrics source is added when StreamingContext's state isINITIALIZED
, if we met exception at this point, we will never change the state intoACTIVE
, so metrics source cannot be removed, since you only assume the state isACTIVE
to remove the source. What do you think?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.
The idea was to register at the call of the
start()
.So, based on your comment, that would mean registering the sources after the state is set to
INITIALIZED
and before.def start(): Unit = synchronized { // Registering Streaming Metrics at the start of the StreamingContext assert(env != null) assert(env.metricsSystem != null) env.metricsSystem.registerSource(streamingSource)
Makes sense to have it after
INITIALIZED
and before the synchronized block ofACTIVE
andSTOPPED
.@tdas, could add more light.
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.
What I mean is to move this line out of
ACTIVE
condition, In any case you have to deregister the metrics source, not only inACTIVE
state.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.
@jerryshao In this PR the streaming metric source is added only after starting the context. So it is fine to deregister only when the state is ACTIVE. Also that maintain the characteristic that
stop
is idempotent.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 think it is OK for normal case, but what if an exception is met after metrics is successfully registered, but before changing the state into
ACTIVE
, according to the code, it will try the exception and change state intoSTOPPED
, so at that situation, if we call stop(), we will never de-register the metrics source according to the current implementation.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.
Yeah good point. I suggested above that the registering be moved after the ACTIVE status change.