-
Notifications
You must be signed in to change notification settings - Fork 28.1k
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
[SPARK-7786][STREAMING] Allow StreamingListener to be specified in SparkConf and loaded when creating StreamingContext #6380
Changes from all commits
73549ff
4eb6987
f8ad629
3c1a19d
f3a3fee
e8506d4
6453c90
d92d55b
00c0409
186766f
c94982f
40d91ed
d7e7b2e
33d3179
233335d
28e7f27
af41098
9ec68c1
70c31e4
aff08ff
fa8c752
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 |
---|---|---|
|
@@ -17,6 +17,8 @@ | |
|
||
package org.apache.spark.streaming.scheduler | ||
|
||
import org.apache.spark.scheduler.StatsReportListener | ||
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. Why was this needed? 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. You have not addressed this. Why was this needed?? I dont see anything that required this. |
||
|
||
import scala.collection.mutable.Queue | ||
|
||
import org.apache.spark.util.Distribution | ||
|
@@ -81,10 +83,13 @@ trait StreamingListener { | |
/** | ||
* :: DeveloperApi :: | ||
* A simple StreamingListener that logs summary statistics across Spark Streaming batches | ||
* @param numBatchInfos Number of last batches to consider for generating statistics (default: 10) | ||
* @param numBatchInfos Number of last batches to consider for generating statistics (default: 100) | ||
*/ | ||
@DeveloperApi | ||
class StatsReportListener(numBatchInfos: Int = 10) extends StreamingListener { | ||
class StatsReportListener(numBatchInfos: Int) extends StreamingListener { | ||
|
||
def this() = this(100) | ||
|
||
// Queue containing latest completed batches | ||
val batchInfos = new Queue[BatchInfo]() | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
package org.apache.spark.streaming | ||
|
||
import scala.collection.mutable.{ArrayBuffer, SynchronizedBuffer} | ||
import scala.collection.JavaConversions._ | ||
import scala.concurrent.Future | ||
import scala.concurrent.ExecutionContext.Implicits.global | ||
|
||
|
@@ -26,10 +27,10 @@ import org.apache.spark.streaming.dstream.DStream | |
import org.apache.spark.streaming.receiver.Receiver | ||
import org.apache.spark.streaming.scheduler._ | ||
|
||
import org.scalatest.Matchers | ||
import org.scalatest.concurrent.Eventually._ | ||
import org.scalatest.time.SpanSugar._ | ||
import org.apache.spark.Logging | ||
import org.scalatest.{Matchers, Assertions} | ||
import org.apache.spark.{SparkException, SparkConf, Logging} | ||
|
||
class StreamingListenerSuite extends TestSuiteBase with Matchers { | ||
|
||
|
@@ -140,6 +141,37 @@ class StreamingListenerSuite extends TestSuiteBase with Matchers { | |
} | ||
true | ||
} | ||
|
||
test("registering listeners via spark.streaming.extraListeners") { | ||
// Test for success with zero-argument constructor and sparkConf constructor | ||
val conf = new SparkConf().setMaster("local").setAppName("test") | ||
.set("spark.streaming.extraListeners", | ||
classOf[StreamingListenerThatAcceptsSparkConf].getName + "," + | ||
classOf[ReceiverInfoCollector].getName) | ||
val scc = new StreamingContext(conf, Seconds(1)) | ||
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 can lead to a leak in the StreamingContext and underlying SparkContext. Please put the whole in
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. StreamingListenerSuite extends TestSuiteBase, so I think we can use the 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. Is this still the case when the context is never started? On Fri, Jul 17, 2015 at 1:55 AM, Tathagata Das notifications@github.com
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. Yes, the StreamingContext is being created, which means an underlying SparkContext is being created, which is not being cleaned up. |
||
|
||
scc.scheduler.listenerBus.listeners.exists { | ||
_.isInstanceOf[StreamingListenerThatAcceptsSparkConf] } | ||
scc.scheduler.listenerBus.listeners.exists { | ||
_.isInstanceOf[ReceiverInfoCollector] } | ||
|
||
// Test for failure with too many arguments in constructor | ||
val failingConf = new SparkConf().setMaster("local").setAppName("failingTest") | ||
.set("spark.streaming.extraListeners", classOf[StreamingListenerTooManyArguments].getName) | ||
val thrown = intercept[SparkException] { | ||
val failingScc = new StreamingContext(failingConf, Seconds(1)) | ||
} | ||
val expectedErrorMessage = | ||
"Exception when registering Streaming Listener:" + | ||
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. Lets not be so specific, the exact text can change. Just verify whether the message has the name of the class inside it. |
||
" org.apache.spark.streaming.StreamingListenerTooManyArguments" + | ||
" did not have a zero-argument constructor or a" + | ||
" single-argument constructor that accepts SparkConf. Note: if the class is" + | ||
" defined inside of another Scala class, then its constructors may accept an" + | ||
" implicit parameter that references the enclosing class; in this case, you must" + | ||
" define the listener as a top-level class in order to prevent this extra" + | ||
" parameter from breaking Spark's ability to find a valid constructor." | ||
assert(thrown.getMessage === expectedErrorMessage) | ||
} | ||
} | ||
|
||
/** Listener that collects information on processed batches */ | ||
|
@@ -196,3 +228,11 @@ class StreamingListenerSuiteReceiver extends Receiver[Any](StorageLevel.MEMORY_O | |
} | ||
def onStop() { } | ||
} | ||
|
||
class StreamingListenerThatAcceptsSparkConf(conf: SparkConf) extends StreamingListener { | ||
// Empty dummy class used for testing | ||
} | ||
|
||
class StreamingListenerTooManyArguments(conf: SparkConf, failInt: Int) extends StreamingListener { | ||
// Empty dummy class used for testing | ||
} |
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 is incorrect:
"when initializing SparkContext"? ==> StreamingContext
"Spark's streaming listener bus" ==> "StreamingContext's listener bus"