Skip to content

Commit

Permalink
RUMM-2559: Register V1 features as V2
Browse files Browse the repository at this point in the history
  • Loading branch information
0xnm committed Oct 4, 2022
1 parent bfe770a commit 5555f8d
Show file tree
Hide file tree
Showing 59 changed files with 421 additions and 170 deletions.
8 changes: 4 additions & 4 deletions dd-sdk-android/apiSurface
Original file line number Diff line number Diff line change
Expand Up @@ -1707,11 +1707,11 @@ interface com.datadog.android.v2.api.EventBatchWriter
fun currentMetadata(): ByteArray?
fun write(ByteArray, String, ByteArray?, BatchWriterListener)
interface com.datadog.android.v2.api.FeatureConfiguration
fun register(SDKCore)
fun register(SdkCore)
interface com.datadog.android.v2.api.FeatureScope
fun withWriteContext((com.datadog.android.v2.api.context.DatadogContext, EventBatchWriter) -> Unit)
data class com.datadog.android.v2.api.FeatureStorageConfiguration
constructor(Int, Int, Int, Long)
constructor(Long, Int, Long, Long)
data class com.datadog.android.v2.api.FeatureUploadConfiguration
constructor(RequestFactory)
interface com.datadog.android.v2.api.InternalLogger
Expand Down Expand Up @@ -1742,7 +1742,7 @@ interface com.datadog.android.v2.api.RequestFactory
const val HEADER_REQUEST_ID: String
const val QUERY_PARAM_SOURCE: String
const val QUERY_PARAM_TAGS: String
interface com.datadog.android.v2.api.SDKCore
interface com.datadog.android.v2.api.SdkCore
fun registerFeature(String, FeatureStorageConfiguration, FeatureUploadConfiguration)
fun getFeature(String): FeatureScope?
fun setVerbosity(Int)
Expand All @@ -1754,7 +1754,7 @@ interface com.datadog.android.v2.api.SDKCore
fun clearAllData()
fun flushStoredData()
fun setFeatureContext(String, Map<String, Any?>)
enum com.datadog.android.v2.api.SDKEndpoint
enum com.datadog.android.v2.api.SdkEndpoint
- US1
- US3
- US5
Expand Down
30 changes: 15 additions & 15 deletions dd-sdk-android/src/main/kotlin/com/datadog/android/Datadog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import com.datadog.android.privacy.TrackingConsent
import com.datadog.android.rum.GlobalRum
import com.datadog.android.rum.internal.RumFeature
import com.datadog.android.rum.internal.monitor.DatadogRumMonitor
import com.datadog.android.v2.api.NoOpSDKCore
import com.datadog.android.v2.api.SDKCore
import com.datadog.android.v2.api.NoOpSdkCore
import com.datadog.android.v2.api.SdkCore
import com.datadog.android.v2.core.DatadogCore
import com.datadog.android.v2.core.internal.HashGenerator
import com.datadog.android.v2.core.internal.Sha256HashGenerator
Expand All @@ -28,7 +28,7 @@ import java.util.concurrent.atomic.AtomicBoolean
*/
object Datadog {

internal var globalSDKCore: SDKCore = NoOpSDKCore()
internal var globalSdkCore: SdkCore = NoOpSdkCore()

internal var hashGenerator: HashGenerator = Sha256HashGenerator()

Expand Down Expand Up @@ -69,8 +69,8 @@ object Datadog {
return
}

globalSDKCore = DatadogCore(context, credentials, configuration, sdkInstanceId)
globalSDKCore.setTrackingConsent(trackingConsent)
globalSdkCore = DatadogCore(context, credentials, configuration, sdkInstanceId)
globalSdkCore.setTrackingConsent(trackingConsent)

initialized.set(true)
}
Expand All @@ -93,15 +93,15 @@ object Datadog {
*/
@JvmStatic
fun clearAllData() {
globalSDKCore.clearAllData()
globalSdkCore.clearAllData()
}

// Stop all Datadog work (for test purposes).
internal fun stop() {
if (initialized.get()) {
globalSDKCore.stop()
globalSdkCore.stop()
initialized.set(false)
globalSDKCore = NoOpSDKCore()
globalSdkCore = NoOpSdkCore()
}
}

Expand All @@ -121,7 +121,7 @@ object Datadog {
it.stopKeepAliveCallback()
it.drainExecutorService()
}
globalSDKCore.flushStoredData()
globalSdkCore.flushStoredData()
}
}

Expand All @@ -137,7 +137,7 @@ object Datadog {
*/
@JvmStatic
fun setVerbosity(level: Int) {
globalSDKCore.setVerbosity(level)
globalSdkCore.setVerbosity(level)
}

/**
Expand All @@ -148,7 +148,7 @@ object Datadog {
*/
@JvmStatic
fun setTrackingConsent(consent: TrackingConsent) {
globalSDKCore.setTrackingConsent(consent)
globalSdkCore.setTrackingConsent(consent)
}

/**
Expand All @@ -168,7 +168,7 @@ object Datadog {
email: String? = null,
extraInfo: Map<String, Any?> = emptyMap()
) {
globalSDKCore.setUserInfo(
globalSdkCore.setUserInfo(
UserInfo(
id,
name,
Expand All @@ -192,7 +192,7 @@ object Datadog {
fun addUserExtraInfo(
extraInfo: Map<String, Any?> = emptyMap()
) {
globalSDKCore.addUserProperties(extraInfo)
globalSdkCore.addUserProperties(extraInfo)
}

/**
Expand All @@ -204,7 +204,7 @@ object Datadog {
*/
@JvmStatic
fun enableRumDebugging(enable: Boolean) {
val rumFeature = ((globalSDKCore as? DatadogCore)?.rumFeature) as? RumFeature
val rumFeature = ((globalSdkCore as? DatadogCore)?.rumFeature) as? RumFeature
if (enable) {
rumFeature?.enableDebugging()
} else {
Expand All @@ -221,7 +221,7 @@ object Datadog {
val _internal: _InternalProxy by lazy {
_InternalProxy(
telemetry,
(globalSDKCore as? DatadogCore)?.coreFeature
(globalSdkCore as? DatadogCore)?.coreFeature
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ internal constructor(

/** @inheritdoc */
override fun intercept(chain: Interceptor.Chain): Response {
val rumFeature = (Datadog.globalSDKCore as? DatadogCore)?.rumFeature
val rumFeature = (Datadog.globalSdkCore as? DatadogCore)?.rumFeature
if (rumFeature != null) {
val request = chain.request()
val url = request.url().toString()
Expand All @@ -186,7 +186,7 @@ internal constructor(
throwable: Throwable?
) {
super.onRequestIntercepted(request, span, response, throwable)
val rumFeature = (Datadog.globalSDKCore as? DatadogCore)?.rumFeature
val rumFeature = (Datadog.globalSdkCore as? DatadogCore)?.rumFeature
if (rumFeature != null) {
if (response != null) {
handleResponse(request, response, span)
Expand All @@ -198,7 +198,7 @@ internal constructor(

/** @inheritdoc */
override fun canSendSpan(): Boolean {
val rumFeature = (Datadog.globalSDKCore as? DatadogCore)?.rumFeature
val rumFeature = (Datadog.globalSdkCore as? DatadogCore)?.rumFeature
return rumFeature == null
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,8 @@ internal class CoreFeature {
persistenceExecutorService,
FileReaderWriter.create(sdkLogger, localDataEncryption),
FileMover(sdkLogger),
sdkLogger
sdkLogger,
buildFilePersistenceConfig()
),
persistenceExecutorService,
sdkLogger
Expand All @@ -354,7 +355,8 @@ internal class CoreFeature {
persistenceExecutorService,
FileReaderWriter.create(sdkLogger, localDataEncryption),
FileMover(sdkLogger),
sdkLogger
sdkLogger,
buildFilePersistenceConfig()
),
persistenceExecutorService,
sdkLogger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ internal class UploadWorker(
return Result.success()
}

val globalSDKCore: DatadogCore? = (Datadog.globalSDKCore as? DatadogCore)
val globalSdkCore: DatadogCore? = (Datadog.globalSdkCore as? DatadogCore)

if (globalSDKCore != null) {
if (globalSdkCore != null) {
// the idea behind upload is the following:
// 1. we shuffle features list to randomize initial upload task sequence. It is done to
// avoid the possible bottleneck when some feature has big batches which are uploaded
Expand All @@ -47,13 +47,13 @@ internal class UploadWorker(
// be uploaded we put retry task to the end of queue, so that batches of other features
// have a chance to go.
val features =
globalSDKCore.getAllFeatures().mapNotNull { it as? DatadogFeature }.shuffled()
globalSdkCore.getAllFeatures().mapNotNull { it as? DatadogFeature }.shuffled()

val tasksQueue = LinkedList<UploadNextBatchTask>()

features.forEach {
@Suppress("UnsafeThirdPartyFunctionCall") // safe to add
tasksQueue.offer(UploadNextBatchTask(tasksQueue, globalSDKCore, it))
tasksQueue.offer(UploadNextBatchTask(tasksQueue, globalSdkCore, it))
}

while (!tasksQueue.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ internal open class BatchFilePersistenceStrategy<T : Any>(
internal val internalLogger: Logger,
internal val fileReaderWriter: BatchFileReaderWriter,
internal val metadataFileReaderWriter: FileReaderWriter,
val fileMover: FileMover
internal val fileMover: FileMover,
internal val filePersistenceConfig: FilePersistenceConfig
) : PersistenceStrategy<T> {

private val dataWriter: DataWriter<T> by lazy {
Expand All @@ -61,8 +62,7 @@ internal open class BatchFilePersistenceStrategy<T : Any>(
fileMover = fileMover,
// TODO RUMM-0000 create internal logger
internalLogger = NoOpInternalLogger(),
// TODO RUMM-0000 don't use default value
filePersistenceConfig = FilePersistenceConfig()
filePersistenceConfig = filePersistenceConfig
)

// region PersistenceStrategy
Expand Down Expand Up @@ -110,5 +110,5 @@ internal open class BatchFilePersistenceStrategy<T : Any>(
)
}

//
// endregion
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ internal open class SingleItemDataWriter<T : Any>(
internal val serializer: Serializer<T>,
internal val fileWriter: FileWriter,
internal val internalLogger: Logger,
// TODO RUMM-0000 don't use default value
internal val filePersistenceConfig: FilePersistenceConfig = FilePersistenceConfig()
internal val filePersistenceConfig: FilePersistenceConfig
) : DataWriter<T> {

// region DataWriter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import com.datadog.android.log.internal.logger.LogcatLogHandler
import com.datadog.android.log.internal.logger.NoOpLogHandler
import com.datadog.android.log.internal.logger.TelemetryLogHandler
import com.datadog.android.telemetry.internal.Telemetry
import com.datadog.android.v2.api.SDKCore
import com.datadog.android.v2.api.SdkCore
import java.util.Locale

internal const val SDK_LOG_PREFIX = "DD_LOG"
Expand Down Expand Up @@ -48,11 +48,11 @@ internal fun buildSdkLogger(): Logger {
*/
internal val devLogger: Logger = buildDevLogger()

private fun buildDevLogger(sdkCore: SDKCore? = null): Logger {
private fun buildDevLogger(sdkCore: SdkCore? = null): Logger {
return Logger(buildDevLogHandler(sdkCore))
}

internal fun buildDevLogHandler(sdkCore: SDKCore?): ConditionalLogHandler {
internal fun buildDevLogHandler(sdkCore: SdkCore?): ConditionalLogHandler {
return ConditionalLogHandler(
LogcatLogHandler(DEV_LOG_PREFIX, false)
) { i, _ ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package com.datadog.android.error.internal

import com.datadog.android.core.internal.persistence.PayloadDecoration
import com.datadog.android.core.internal.persistence.file.FileMover
import com.datadog.android.core.internal.persistence.file.FilePersistenceConfig
import com.datadog.android.core.internal.persistence.file.FileReaderWriter
import com.datadog.android.core.internal.persistence.file.advanced.FeatureFileOrchestrator
import com.datadog.android.core.internal.persistence.file.batch.BatchFilePersistenceStrategy
Expand All @@ -28,7 +29,8 @@ internal class CrashReportFilePersistenceStrategy(
storageDir: File,
executorService: ExecutorService,
internalLogger: Logger,
localDataEncryption: Encryption?
localDataEncryption: Encryption?,
filePersistenceConfig: FilePersistenceConfig
) : BatchFilePersistenceStrategy<LogEvent>(
contextProvider,
FeatureFileOrchestrator(
Expand All @@ -44,5 +46,6 @@ internal class CrashReportFilePersistenceStrategy(
sdkLogger,
BatchFileReaderWriter.create(sdkLogger, localDataEncryption),
FileReaderWriter.create(sdkLogger, localDataEncryption),
FileMover(sdkLogger)
FileMover(sdkLogger),
filePersistenceConfig
)
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ internal class CrashReportsFeature(
coreFeature.storageDir,
coreFeature.persistenceExecutorService,
sdkLogger,
coreFeature.localDataEncryption
coreFeature.localDataEncryption,
coreFeature.buildFilePersistenceConfig()
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ internal class DatadogExceptionHandler(
)

// give some time to the persistence executor service to finish its tasks
val coreFeature = (Datadog.globalSDKCore as? DatadogCore)?.coreFeature
val coreFeature = (Datadog.globalSdkCore as? DatadogCore)?.coreFeature
if (coreFeature != null) {
val idled = (coreFeature.persistenceExecutorService as? ThreadPoolExecutor)
?.waitToIdle(MAX_WAIT_FOR_IDLE_TIME_IN_MS) ?: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ internal constructor(internal var handler: LogHandler) {
* Builds a [Logger] based on the current state of this Builder.
*/
fun build(): Logger {
val datadogCore = Datadog.globalSDKCore as? DatadogCore
val datadogCore = Datadog.globalSdkCore as? DatadogCore
val coreFeature = datadogCore?.coreFeature
val logsFeature = datadogCore?.logsFeature
val handler = when {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ internal class LogsFeature(
coreFeature.persistenceExecutorService,
sdkLogger,
configuration.logsEventMapper,
coreFeature.localDataEncryption
coreFeature.localDataEncryption,
coreFeature.buildFilePersistenceConfig()
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package com.datadog.android.log.internal.domain

import com.datadog.android.core.internal.persistence.PayloadDecoration
import com.datadog.android.core.internal.persistence.file.FileMover
import com.datadog.android.core.internal.persistence.file.FilePersistenceConfig
import com.datadog.android.core.internal.persistence.file.FileReaderWriter
import com.datadog.android.core.internal.persistence.file.advanced.FeatureFileOrchestrator
import com.datadog.android.core.internal.persistence.file.batch.BatchFilePersistenceStrategy
Expand All @@ -33,7 +34,8 @@ internal class LogFilePersistenceStrategy(
executorService: ExecutorService,
internalLogger: Logger,
logEventMapper: EventMapper<LogEvent>,
localDataEncryption: Encryption?
localDataEncryption: Encryption?,
filePersistenceConfig: FilePersistenceConfig
) : BatchFilePersistenceStrategy<LogEvent>(
contextProvider,
FeatureFileOrchestrator(
Expand All @@ -49,5 +51,6 @@ internal class LogFilePersistenceStrategy(
sdkLogger,
BatchFileReaderWriter.create(sdkLogger, localDataEncryption),
FileReaderWriter.create(sdkLogger, localDataEncryption),
FileMover(internalLogger)
FileMover(internalLogger),
filePersistenceConfig
)
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ object GlobalRum {
newContext.viewId
)
)
val datadogCore = (Datadog.globalSDKCore as? DatadogCore)
val datadogCore = (Datadog.globalSdkCore as? DatadogCore)
updateContextInPlugins(
pluginContext,
datadogCore?.rumFeature?.getPlugins().orEmpty()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ interface RumMonitor {
* Builds a [RumMonitor] based on the current state of this Builder.
*/
fun build(): RumMonitor {
val datadogCore = Datadog.globalSDKCore as? DatadogCore
val datadogCore = Datadog.globalSdkCore as? DatadogCore
val coreFeature = datadogCore?.coreFeature
val contextProvider = datadogCore?.contextProvider
val rumFeature = datadogCore?.rumFeature as? RumFeature
Expand Down
Loading

0 comments on commit 5555f8d

Please sign in to comment.