RUM-9854: Introduce event processing thread#2631
Conversation
c5ad35e to
7956da7
Compare
| val contextProvider = coreFeature.contextProvider | ||
| if (contextProvider is NoOpContextProvider) return@executeSafe | ||
| val context = contextProvider.context | ||
| val eventBatchWriteScope = storage.getEventWriteScope(context) |
There was a problem hiding this comment.
[minor] Looks like a duplicate code similar to the one in getWriteContextSync.
There was a problem hiding this comment.
for now, it is, yes. There is a TODO item attached to the getWriteContextSync, so maybe this method will be gone by the end of the development.
| tags = emptySet() | ||
| ) | ||
| // TODO RUM-9852 Implement better passthrough mechanism for the JVM crash scenario | ||
| val writeContext = sdkCore.getFeature(name) |
There was a problem hiding this comment.
Is my understanding correct that we need this getWriteContextSync only because we have to log the crash synchronously, because otherwise the process might die before we finish (because we do it in Thread.UncaughtExceptionHandler)?
There was a problem hiding this comment.
yes, this is right. That is why we have a TODO item as well, we want to have a quick passthrough for crashes avoiding switching threads. The only thread switch we can allow is for the I/O write.
| // max pool size, | ||
| 1, | ||
| // keep-alive time | ||
| 0L, |
There was a problem hiding this comment.
why not keeping it alive for a while ?
There was a problem hiding this comment.
This is to align with defaults of the Executors.newSingleThreadExecutor call (link)
| } | ||
| } | ||
|
|
||
| private fun resolveCallFullNames(resolvedCall: ResolvedCall<out CallableDescriptor>): Set<String> { |
There was a problem hiding this comment.
Could you please explain what this change is for? I'm just not familiar with writing custom detekt rules and don't understand what changed.
There was a problem hiding this comment.
ah, I see the new tests, it is clearer now
There was a problem hiding this comment.
yes, it is basically for typealias thing, because ResolvedCall will have a direct type signature, with typealias erased, so we need to generate the signature with typealias included in addition.
What does this PR do?
This PR adds a dedicated context event processing thread which will be used when
FeatureScope.withWriteContextis called.Before this change when
FeatureScope.withWriteContextwas called, the content of the block was executed on the thread from I/O pool and block arguments wereDatadogContextandEventBatchWriter.After this change the block arguments are
DatadogContextandEventWriteScope, whereEventWriteScopeis block-accepting lambda where argument isEventWriteScope. This allows now have 2 pipelines insidewithWriteContextcall:withWriteContextwill be executed on the single context processing thread shared between all the features.EventWriteScopewill be executed on the thread from I/O pool.To illustrate it better:
This will allow to introduce the wait mechanism for the feature context synchronization without imposing such wait on the client thread.
Also this PR moves
withWriteContextcall up to the root scope in the RUM processing, so that we can have context earlier.The diff looks big, but its majority is in the tests where the main volume of changes comes from formatting and renaming.
Review checklist (to be filled by reviewers)