Skip to content
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

RUMM-2501: Use SDK v2 components in the upload pipeline #1040

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion dd-sdk-android/apiSurface
Original file line number Diff line number Diff line change
Expand Up @@ -1729,6 +1729,15 @@ data class com.datadog.android.v2.api.Request
constructor(String, String, String, Map<String, String>, ByteArray, String? = null)
interface com.datadog.android.v2.api.RequestFactory
fun create(com.datadog.android.v2.api.context.DatadogContext, List<ByteArray>, ByteArray?): Request
companion object
const val CONTENT_TYPE_JSON: String
const val CONTENT_TYPE_TEXT_UTF8: String
const val HEADER_API_KEY: String
const val HEADER_EVP_ORIGIN: String
const val HEADER_EVP_ORIGIN_VERSION: String
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
fun registerFeature(String, FeatureStorageConfiguration, FeatureUploadConfiguration)
fun getFeature(String): FeatureScope?
Expand All @@ -1750,7 +1759,7 @@ enum com.datadog.android.v2.api.SDKEndpoint
data class com.datadog.android.v2.api.context.CarrierInfo
constructor(String?, String?)
data class com.datadog.android.v2.api.context.DatadogContext
constructor(com.datadog.android.DatadogSite, String, String, String, String, String, String, TimeInfo, ProcessInfo, NetworkInfo, DeviceInfo, UserInfo, com.datadog.android.privacy.TrackingConsent, Map<String, Map<String, Any?>>)
constructor(com.datadog.android.DatadogSite, String, String, String, String, String, String, String, TimeInfo, ProcessInfo, NetworkInfo, DeviceInfo, UserInfo, com.datadog.android.privacy.TrackingConsent, Map<String, Map<String, Any?>>)
data class com.datadog.android.v2.api.context.DeviceInfo
constructor(String, String, String, DeviceType, String, String, String, String, String)
enum com.datadog.android.v2.api.context.DeviceType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ import com.datadog.android.rum.internal.ndk.NdkNetworkInfoDataWriter
import com.datadog.android.rum.internal.ndk.NdkUserInfoDataWriter
import com.datadog.android.rum.internal.ndk.NoOpNdkCrashHandler
import com.datadog.android.security.Encryption
import com.datadog.android.v2.core.internal.ContextProvider
import com.datadog.android.v2.core.internal.DatadogContextProvider
import com.datadog.android.v2.core.internal.NoOpContextProvider
import com.lyft.kronos.AndroidClockFactory
import com.lyft.kronos.KronosClock
import java.io.File
Expand Down Expand Up @@ -94,6 +97,7 @@ internal class CoreFeature {
internal var timeProvider: TimeProvider = NoOpTimeProvider()
internal var trackingConsentProvider: ConsentProvider = NoOpConsentProvider()
internal var userInfoProvider: MutableUserInfoProvider = NoOpMutableUserInfoProvider()
internal var contextProvider: ContextProvider = NoOpContextProvider()

internal lateinit var okHttpClient: OkHttpClient
internal lateinit var kronosClock: KronosClock
Expand Down Expand Up @@ -160,6 +164,7 @@ internal class CoreFeature {
prepareNdkCrashData()
setupInfoProviders(appContext, consent)
initialized.set(true)
contextProvider = DatadogContextProvider(this)
}

fun stop() {
Expand All @@ -186,6 +191,7 @@ internal class CoreFeature {
initialized.set(false)
ndkCrashHandler = NoOpNdkCrashHandler()
trackingConsentProvider = NoOpConsentProvider()
contextProvider = NoOpContextProvider()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,19 @@ package com.datadog.android.core.internal

import android.content.Context
import com.datadog.android.core.configuration.Configuration
import com.datadog.android.core.internal.data.upload.DataUploadScheduler
import com.datadog.android.core.internal.data.upload.NoOpUploadScheduler
import com.datadog.android.core.internal.data.upload.UploadScheduler
import com.datadog.android.core.internal.net.DataUploader
import com.datadog.android.core.internal.net.NoOpDataUploader
import com.datadog.android.core.internal.persistence.NoOpPersistenceStrategy
import com.datadog.android.core.internal.persistence.PersistenceStrategy
import com.datadog.android.core.internal.privacy.ConsentProvider
import com.datadog.android.core.internal.utils.sdkLogger
import com.datadog.android.plugin.DatadogPlugin
import com.datadog.android.plugin.DatadogPluginConfig
import com.datadog.android.v2.api.RequestFactory
import com.datadog.android.v2.core.internal.data.upload.DataUploadScheduler
import com.datadog.android.v2.core.internal.net.DataOkHttpUploader
import com.datadog.android.v2.core.internal.net.DataUploader
import com.datadog.android.v2.core.internal.net.NoOpDataUploader
import java.util.concurrent.atomic.AtomicBoolean

@Suppress("TooManyFunctions")
Expand Down Expand Up @@ -109,7 +112,7 @@ internal abstract class SdkFeature<T : Any, C : Configuration.Feature>(
configuration: C
): PersistenceStrategy<T>

abstract fun createUploader(configuration: C): DataUploader
abstract fun createRequestFactory(configuration: C): RequestFactory

// endregion

Expand All @@ -136,10 +139,18 @@ internal abstract class SdkFeature<T : Any, C : Configuration.Feature>(

private fun setupUploader(configuration: C) {
uploadScheduler = if (coreFeature.isMainProcess) {
uploader = createUploader(configuration)
val requestFactory = createRequestFactory(configuration)
uploader = DataOkHttpUploader(
requestFactory,
internalLogger = sdkLogger,
callFactory = coreFeature.okHttpClient,
sdkVersion = coreFeature.sdkVersion,
androidInfoProvider = coreFeature.androidInfoProvider
)
DataUploadScheduler(
persistenceStrategy.getReader(),
persistenceStrategy.getStorage(),
uploader,
coreFeature.contextProvider,
coreFeature.networkInfoProvider,
coreFeature.systemInfoProvider,
coreFeature.uploadFrequency,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ internal class UploadWorker(
@Suppress("UnsafeThirdPartyFunctionCall") // safe to create, argument is not negative
val lock = CountDownLatch(1)

storage.readNextBatch(context, noBatchCallback = {
storage.readNextBatch(noBatchCallback = {
lock.countDown()
}) { batchId, reader ->
val batch = reader.read()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

package com.datadog.android.core.internal.persistence

import com.datadog.android.core.internal.data.upload.Flusher
import com.datadog.android.v2.core.internal.data.upload.Flusher
import com.datadog.android.v2.core.internal.storage.Storage
import com.datadog.tools.annotation.NoOpImplementation

/**
Expand All @@ -21,4 +22,6 @@ internal interface PersistenceStrategy<T : Any> {
fun getReader(): DataReader

fun getFlusher(): Flusher

fun getStorage(): Storage
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,36 @@

package com.datadog.android.core.internal.persistence.file.batch

import com.datadog.android.core.internal.data.upload.DataFlusher
import com.datadog.android.core.internal.data.upload.Flusher
import com.datadog.android.core.internal.persistence.DataReader
import com.datadog.android.core.internal.persistence.DataWriter
import com.datadog.android.core.internal.persistence.PayloadDecoration
import com.datadog.android.core.internal.persistence.PersistenceStrategy
import com.datadog.android.core.internal.persistence.Serializer
import com.datadog.android.core.internal.persistence.file.FileMover
import com.datadog.android.core.internal.persistence.file.FileOrchestrator
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.ConsentAwareFileOrchestrator
import com.datadog.android.core.internal.persistence.file.advanced.ScheduledWriter
import com.datadog.android.log.Logger
import com.datadog.android.v2.api.NoOpBatchWriterListener
import com.datadog.android.v2.api.NoOpInternalLogger
import com.datadog.android.v2.core.internal.ContextProvider
import com.datadog.android.v2.core.internal.data.upload.DataFlusher
import com.datadog.android.v2.core.internal.data.upload.Flusher
import com.datadog.android.v2.core.internal.storage.ConsentAwareStorage
import com.datadog.android.v2.core.internal.storage.Storage
import java.util.concurrent.ExecutorService

internal open class BatchFilePersistenceStrategy<T : Any>(
private val fileOrchestrator: FileOrchestrator,
private val contextProvider: ContextProvider,
private val fileOrchestrator: ConsentAwareFileOrchestrator,
private val executorService: ExecutorService,
serializer: Serializer<T>,
private val payloadDecoration: PayloadDecoration,
internalLogger: Logger,
payloadDecoration: PayloadDecoration,
internal val internalLogger: Logger,
internal val fileReaderWriter: BatchFileReaderWriter,
internal val metadataFileReaderWriter: FileReaderWriter,
val fileMover: FileMover
) : PersistenceStrategy<T> {

Expand Down Expand Up @@ -57,7 +67,13 @@ internal open class BatchFilePersistenceStrategy<T : Any>(
}

override fun getFlusher(): Flusher {
return DataFlusher(fileOrchestrator, payloadDecoration, fileReaderWriter, fileMover)
return DataFlusher(
contextProvider,
fileOrchestrator,
fileReaderWriter,
metadataFileReaderWriter,
fileMover
)
}

// endregion
Expand All @@ -82,5 +98,20 @@ internal open class BatchFilePersistenceStrategy<T : Any>(
)
}

override fun getStorage(): Storage {
return ConsentAwareStorage(
grantedOrchestrator = fileOrchestrator.grantedOrchestrator,
pendingOrchestrator = fileOrchestrator.pendingOrchestrator,
batchEventsReaderWriter = fileReaderWriter,
batchMetadataReaderWriter = metadataFileReaderWriter,
fileMover = fileMover,
// TODO RUMM-2504 register listener
listener = NoOpBatchWriterListener(),
// TODO RUMM-0000 create internal logger
internalLogger = NoOpInternalLogger(),
filePersistenceConfig = FilePersistenceConfig()
)
}

//
}
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.FileReaderWriter
import com.datadog.android.core.internal.persistence.file.advanced.FeatureFileOrchestrator
import com.datadog.android.core.internal.persistence.file.batch.BatchFilePersistenceStrategy
import com.datadog.android.core.internal.persistence.file.batch.BatchFileReaderWriter
Expand All @@ -17,16 +18,19 @@ import com.datadog.android.log.Logger
import com.datadog.android.log.internal.domain.event.LogEventSerializer
import com.datadog.android.log.model.LogEvent
import com.datadog.android.security.Encryption
import com.datadog.android.v2.core.internal.ContextProvider
import java.io.File
import java.util.concurrent.ExecutorService

internal class CrashReportFilePersistenceStrategy(
contextProvider: ContextProvider,
consentProvider: ConsentProvider,
storageDir: File,
executorService: ExecutorService,
internalLogger: Logger,
localDataEncryption: Encryption?
) : BatchFilePersistenceStrategy<LogEvent>(
contextProvider,
FeatureFileOrchestrator(
consentProvider,
storageDir,
Expand All @@ -39,5 +43,6 @@ internal class CrashReportFilePersistenceStrategy(
PayloadDecoration.JSON_ARRAY_DECORATION,
sdkLogger,
BatchFileReaderWriter.create(sdkLogger, localDataEncryption),
FileReaderWriter.create(sdkLogger, localDataEncryption),
FileMover(sdkLogger)
)
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import android.content.Context
import com.datadog.android.core.configuration.Configuration
import com.datadog.android.core.internal.CoreFeature
import com.datadog.android.core.internal.SdkFeature
import com.datadog.android.core.internal.net.DataUploader
import com.datadog.android.core.internal.persistence.PersistenceStrategy
import com.datadog.android.core.internal.utils.sdkLogger
import com.datadog.android.log.internal.domain.DatadogLogGenerator
import com.datadog.android.log.internal.net.LogsOkHttpUploaderV2
import com.datadog.android.log.model.LogEvent
import com.datadog.android.v2.api.RequestFactory
import com.datadog.android.v2.log.internal.net.LogsRequestFactory

internal class CrashReportsFeature(
coreFeature: CoreFeature
Expand All @@ -38,6 +38,7 @@ internal class CrashReportsFeature(
configuration: Configuration.Feature.CrashReport
): PersistenceStrategy<LogEvent> {
return CrashReportFilePersistenceStrategy(
coreFeature.contextProvider,
coreFeature.trackingConsentProvider,
coreFeature.storageDir,
coreFeature.persistenceExecutorService,
Expand All @@ -46,19 +47,12 @@ internal class CrashReportsFeature(
)
}

override fun createUploader(configuration: Configuration.Feature.CrashReport): DataUploader {
return LogsOkHttpUploaderV2(
configuration.endpointUrl,
coreFeature.clientToken,
coreFeature.sourceName,
coreFeature.sdkVersion,
coreFeature.okHttpClient,
coreFeature.androidInfoProvider,
sdkLogger
)
override fun createRequestFactory(configuration: Configuration.Feature.CrashReport):
RequestFactory {
return LogsRequestFactory(configuration.endpointUrl)
}

override fun onPostInitialized(context: Context) { }
override fun onPostInitialized(context: Context) {}

// endregion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import android.content.Context
import com.datadog.android.core.configuration.Configuration
import com.datadog.android.core.internal.CoreFeature
import com.datadog.android.core.internal.SdkFeature
import com.datadog.android.core.internal.net.DataUploader
import com.datadog.android.core.internal.persistence.PersistenceStrategy
import com.datadog.android.core.internal.utils.sdkLogger
import com.datadog.android.log.internal.domain.LogFilePersistenceStrategy
import com.datadog.android.log.internal.net.LogsOkHttpUploaderV2
import com.datadog.android.log.model.LogEvent
import com.datadog.android.v2.api.RequestFactory
import com.datadog.android.v2.log.internal.net.LogsRequestFactory

internal class LogsFeature(
coreFeature: CoreFeature
Expand All @@ -28,6 +28,7 @@ internal class LogsFeature(
configuration: Configuration.Feature.Logs
): PersistenceStrategy<LogEvent> {
return LogFilePersistenceStrategy(
coreFeature.contextProvider,
coreFeature.trackingConsentProvider,
coreFeature.storageDir,
coreFeature.persistenceExecutorService,
Expand All @@ -37,19 +38,11 @@ internal class LogsFeature(
)
}

override fun createUploader(configuration: Configuration.Feature.Logs): DataUploader {
return LogsOkHttpUploaderV2(
configuration.endpointUrl,
coreFeature.clientToken,
coreFeature.sourceName,
coreFeature.sdkVersion,
coreFeature.okHttpClient,
coreFeature.androidInfoProvider,
sdkLogger
)
override fun createRequestFactory(configuration: Configuration.Feature.Logs): RequestFactory {
return LogsRequestFactory(configuration.endpointUrl)
}

override fun onPostInitialized(context: Context) { }
override fun onPostInitialized(context: Context) {}

// endregion

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.FileReaderWriter
import com.datadog.android.core.internal.persistence.file.advanced.FeatureFileOrchestrator
import com.datadog.android.core.internal.persistence.file.batch.BatchFilePersistenceStrategy
import com.datadog.android.core.internal.persistence.file.batch.BatchFileReaderWriter
Expand All @@ -21,29 +22,32 @@ import com.datadog.android.log.internal.domain.event.LogEventMapperWrapper
import com.datadog.android.log.internal.domain.event.LogEventSerializer
import com.datadog.android.log.model.LogEvent
import com.datadog.android.security.Encryption
import com.datadog.android.v2.core.internal.ContextProvider
import java.io.File
import java.util.concurrent.ExecutorService

internal class LogFilePersistenceStrategy(
contextProvider: ContextProvider,
consentProvider: ConsentProvider,
storageDir: File,
executorService: ExecutorService,
internalLogger: Logger,
logEventMapper: EventMapper<LogEvent>,
localDataEncryption: Encryption?
) :
BatchFilePersistenceStrategy<LogEvent>(
FeatureFileOrchestrator(
consentProvider,
storageDir,
LogsFeature.LOGS_FEATURE_NAME,
executorService,
internalLogger
),
) : BatchFilePersistenceStrategy<LogEvent>(
contextProvider,
FeatureFileOrchestrator(
consentProvider,
storageDir,
LogsFeature.LOGS_FEATURE_NAME,
executorService,
MapperSerializer(LogEventMapperWrapper(logEventMapper), LogEventSerializer()),
PayloadDecoration.JSON_ARRAY_DECORATION,
sdkLogger,
BatchFileReaderWriter.create(sdkLogger, localDataEncryption),
FileMover(internalLogger)
)
internalLogger
),
executorService,
MapperSerializer(LogEventMapperWrapper(logEventMapper), LogEventSerializer()),
PayloadDecoration.JSON_ARRAY_DECORATION,
sdkLogger,
BatchFileReaderWriter.create(sdkLogger, localDataEncryption),
FileReaderWriter.create(sdkLogger, localDataEncryption),
FileMover(internalLogger)
)
Loading