-
Notifications
You must be signed in to change notification settings - Fork 99
Live data preview and node transition throughput on Flink minicluster #8047
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
Merged
Changes from all commits
Commits
Show all changes
49 commits
Select commit
Hold shift + click to select a range
b7f6fe9
live data draft
mgoworko 549018e
Merge remote-tracking branch 'origin/staging' into live-data
mgoworko caf5ad6
config and API refactor
mgoworko 75b40ae
Merge remote-tracking branch 'origin/staging' into live-data
mgoworko a8a7772
qs
mgoworko f0f3713
fix scala 2.12
mgoworko 5fab9d1
qs
mgoworko 29eb20a
qs
mgoworko 922bc1b
qs
mgoworko 875ed75
Merge remote-tracking branch 'origin/staging' into live-data
mgoworko b18a021
tests
mgoworko a353c19
tests and frequency
mgoworko c63a84f
tests and frequency
mgoworko 8acef21
qs
mgoworko c5a5483
qs
mgoworko 94c6242
qs
mgoworko 8fe11c8
qs
mgoworko 66f3af5
qs
mgoworko 07ffb12
qs
mgoworko e2e24fd
Merge remote-tracking branch 'origin/staging' into live-data
mgoworko 83cc4fe
qs
mgoworko 140a62b
qs
mgoworko 8ed4c8b
Merge remote-tracking branch 'origin/staging' into live-data
mgoworko d1d7004
qs
mgoworko fd4ce84
Merge remote-tracking branch 'origin/staging' into live-data
mgoworko 8063a7f
qs
mgoworko 3a8111e
qs
mgoworko f3bf584
qs
mgoworko 53ef524
Merge remote-tracking branch 'origin/staging' into live-data
mgoworko 35e7599
review changes
mgoworko 9bde15c
review changes
mgoworko 38bbde3
Merge remote-tracking branch 'origin/staging' into live-data
mgoworko 68dfadf
review changes
mgoworko e0ccee6
review changes
mgoworko f1e1b92
qs
mgoworko 47be346
qs
mgoworko 936f68f
qs
mgoworko cbf2ef9
qs
mgoworko 38f530c
qs
mgoworko 9a4db61
improve regex
mgoworko 66a1db4
Merge remote-tracking branch 'origin/staging' into live-data
mgoworko 1d8061d
improve regex
mgoworko b4daff0
improve regex
mgoworko 1359c22
separate live data API and logn sliding window
mgoworko bdebf1f
Merge remote-tracking branch 'origin/staging' into live-data
mgoworko 238f7e7
qs
mgoworko 61632ef
qs
mgoworko e6c7ee3
qs
mgoworko 0cb1d87
qs
mgoworko 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
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
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
104 changes: 104 additions & 0 deletions
104
...ector/src/main/scala/pl/touk/nussknacker/engine/livedata/LiveDataCollectingListener.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,104 @@ | ||
package pl.touk.nussknacker.engine.livedata | ||
|
||
import io.circe.Json | ||
import pl.touk.nussknacker.engine.api._ | ||
import pl.touk.nussknacker.engine.api.exception.NuExceptionInfo | ||
import pl.touk.nussknacker.engine.api.process.ProcessName | ||
import pl.touk.nussknacker.engine.testmode.TestInterpreterRunner | ||
import pl.touk.nussknacker.engine.testmode.TestProcess.TestResults | ||
|
||
import scala.util.Try | ||
|
||
// This class must be serializable. It means, that when deserializing, we lose the reference to it. | ||
// The actual data is stored in the LiveDataCollectingListenerHolder, and all instances of LiveDataCollectingListener can access the data. | ||
class LiveDataCollectingListener private[livedata] ( | ||
processName: ProcessName, | ||
maxNumberOfSamples: Int, | ||
throughputTimeWindowInSeconds: Int, | ||
) extends ProcessListener | ||
with Serializable { | ||
|
||
private val variableEncoder: Any => io.circe.Json = TestInterpreterRunner.testResultsVariableEncoder | ||
|
||
private def storage = LiveDataCollectingListenerHolder.storage( | ||
processName = processName, | ||
maxNumberOfSamples = maxNumberOfSamples, | ||
throughputTimeWindowInSeconds = throughputTimeWindowInSeconds, | ||
) | ||
|
||
override def nodeEntered(nodeId: String, context: Context, processMetaData: MetaData): Unit = { | ||
updateResults(context, _.updateNodeResult(nodeId, context, variableEncoder)) | ||
} | ||
|
||
override def transitionToNextNode( | ||
nodeId: String, | ||
nextNodeId: String, | ||
context: Context, | ||
processMetaData: MetaData, | ||
): Unit = { | ||
storage.registerTransitionBetweenNodes(nodeId, Some(nextNodeId)) | ||
updateResults(context, _.updateNodeOutputResult(nodeId, Some(nextNodeId), context, variableEncoder)) | ||
} | ||
|
||
override def processingFinishedInNode( | ||
nodeId: String, | ||
context: Context, | ||
processMetaData: MetaData, | ||
): Unit = { | ||
storage.registerTransitionBetweenNodes(nodeId, None) | ||
updateResults(context, _.updateNodeOutputResult(nodeId, None, context, variableEncoder)) | ||
} | ||
|
||
override def endEncountered( | ||
nodeId: String, | ||
ref: String, | ||
context: Context, | ||
processMetaData: MetaData | ||
): Unit = () | ||
|
||
override def deadEndEncountered( | ||
lastNodeId: String, | ||
context: Context, | ||
processMetaData: MetaData | ||
): Unit = {} | ||
|
||
override def expressionEvaluated( | ||
nodeId: String, | ||
expressionId: String, | ||
expression: String, | ||
context: Context, | ||
processMetaData: MetaData, | ||
result: Any | ||
): Unit = { | ||
updateResults(context, _.updateExpressionResult(nodeId, context, expressionId, result, variableEncoder)) | ||
} | ||
|
||
override def serviceInvoked( | ||
nodeId: String, | ||
id: String, | ||
context: Context, | ||
processMetaData: MetaData, | ||
result: Try[Any] | ||
): Unit = {} | ||
|
||
override def exceptionThrown(exceptionInfo: NuExceptionInfo): Unit = { | ||
updateResults(exceptionInfo.context, _.updateExceptionResult(exceptionInfo, variableEncoder)) | ||
} | ||
|
||
override final def close(): Unit = () | ||
|
||
private def updateResults(context: Context, action: TestResults[Json] => TestResults[Json]): Unit = { | ||
// todo: The ContextId will be refactored to be represented by case class with fields, | ||
// but for now we have to use regex in order to parse the initial context id as generated by the source. | ||
val pattern = raw"^(.+?-.+?-\d+-\d+)(-.+)?".r | ||
val initialContextIdOpt = context.id match { | ||
case pattern(initialContextId, _*) => Some(initialContextId) | ||
case _ => None | ||
} | ||
initialContextIdOpt match { | ||
case Some(initialContextId) => storage.updateResults(initialContextId, action) | ||
case None => () | ||
} | ||
} | ||
|
||
} |
56 changes: 56 additions & 0 deletions
56
...src/main/scala/pl/touk/nussknacker/engine/livedata/LiveDataCollectingListenerHolder.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,56 @@ | ||
package pl.touk.nussknacker.engine.livedata | ||
|
||
import com.github.benmanes.caffeine.cache.Caffeine | ||
import pl.touk.nussknacker.engine.api.deployment.LiveDataPreviewSupported.{LiveData, LiveDataError} | ||
import pl.touk.nussknacker.engine.api.process.ProcessName | ||
|
||
import java.time.Clock | ||
import scala.compat.java8.FunctionConverters._ | ||
|
||
object LiveDataCollectingListenerHolder { | ||
|
||
private implicit val clock: Clock = Clock.systemUTC() | ||
|
||
private val listenerStorages = | ||
Caffeine | ||
.newBuilder() | ||
.expireAfterAccess(java.time.Duration.ofHours(1)) | ||
.build[String, LiveDataCollectingListenerStorage]() | ||
|
||
def createListenerFor( | ||
processName: ProcessName, | ||
maxNumberOfSamples: Int, | ||
throughputTimeWindowInSeconds: Int, | ||
): LiveDataCollectingListener = { | ||
cleanResults(processName) | ||
new LiveDataCollectingListener(processName, maxNumberOfSamples, throughputTimeWindowInSeconds) | ||
} | ||
|
||
def getLiveDataPreview(processName: ProcessName): Either[LiveDataError, LiveData] = { | ||
Option(listenerStorages.getIfPresent(processName.value)).map(_.getLiveData) match { | ||
case Some(liveData) => Right(liveData) | ||
case None => Left(LiveDataError.NoLiveDataAvailableForScenario) | ||
} | ||
} | ||
|
||
private[livedata] def storage( | ||
processName: ProcessName, | ||
maxNumberOfSamples: Int, | ||
throughputTimeWindowInSeconds: Int, | ||
): LiveDataCollectingListenerStorage = { | ||
listenerStorages.get( | ||
processName.value, | ||
asJavaFunction((_: String) => | ||
new LiveDataCollectingListenerStorage(maxNumberOfSamples, throughputTimeWindowInSeconds) | ||
) | ||
) | ||
} | ||
|
||
// We want to store and present the live data from the most recent deployment: | ||
// - the data from the old run is stored until the listener storage cache expires (currently hardcoded 1 hour) | ||
// - or new deployment is done - then we discard all old data | ||
private def cleanResults(processName: ProcessName): Unit = { | ||
listenerStorages.invalidate(processName.value) | ||
} | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
...rc/main/scala/pl/touk/nussknacker/engine/livedata/LiveDataCollectingListenerStorage.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,38 @@ | ||
package pl.touk.nussknacker.engine.livedata | ||
|
||
import io.circe.Json | ||
import pl.touk.nussknacker.engine.api.deployment.LiveDataPreviewSupported.LiveData | ||
import pl.touk.nussknacker.engine.testmode.TestProcess._ | ||
|
||
import java.time.{Clock, Instant} | ||
|
||
private[livedata] class LiveDataCollectingListenerStorage( | ||
maxNumberOfSamples: Int, | ||
throughputTimeWindowInSeconds: Int, | ||
)(implicit clock: Clock) { | ||
|
||
private val results = new RingBuffer[String, TestResults[Json]](maxNumberOfSamples) | ||
private val transitionsCounter = new SlidingWindowCounter[NodeTransition](Instant.now, throughputTimeWindowInSeconds) | ||
|
||
def getLiveData: LiveData = { | ||
LiveData( | ||
liveDataSamples = TestResults.aggregate(results.values), | ||
nodeTransitionThroughput = transitionsCounter.getThroughput, | ||
) | ||
} | ||
|
||
def updateResults(contextId: String, action: TestResults[Json] => TestResults[Json]): Unit = { | ||
results.update( | ||
contextId, | ||
{ | ||
case Some(resultsSoFar) => action(resultsSoFar) | ||
case None => action(TestResults.empty[Json]) | ||
} | ||
) | ||
} | ||
|
||
def registerTransitionBetweenNodes(from: String, to: Option[String]): Unit = { | ||
transitionsCounter.add(NodeTransition(from, to)) | ||
} | ||
|
||
} |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.