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

Improve todo detekt rule #1955

Merged
merged 3 commits into from
Apr 2, 2024
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
1 change: 1 addition & 0 deletions dd-sdk-android-core/api/apiSurface
Original file line number Diff line number Diff line change
Expand Up @@ -365,3 +365,4 @@ enum com.datadog.android.trace.TracingHeaderType
- B3MULTI
- TRACECONTEXT
annotation com.datadog.tools.annotation.NoOpImplementation
constructor(Boolean = false)
6 changes: 6 additions & 0 deletions dd-sdk-android-core/api/dd-sdk-android-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,11 @@ public final class com/datadog/android/api/storage/FeatureStorageConfiguration$C
public final fun getDEFAULT ()Lcom/datadog/android/api/storage/FeatureStorageConfiguration;
}

public final class com/datadog/android/api/storage/NoOpDataWriter : com/datadog/android/api/storage/DataWriter {
public fun <init> ()V
public fun write (Lcom/datadog/android/api/storage/EventBatchWriter;Ljava/lang/Object;)Z
}

public final class com/datadog/android/api/storage/RawBatchEvent {
public fun <init> ([B[B)V
public synthetic fun <init> ([B[BILkotlin/jvm/internal/DefaultConstructorMarker;)V
Expand Down Expand Up @@ -867,5 +872,6 @@ public final class com/datadog/android/trace/TracingHeaderType : java/lang/Enum
}

public abstract interface annotation class com/datadog/tools/annotation/NoOpImplementation : java/lang/annotation/Annotation {
public abstract fun publicNoOpImplementation ()Z
}

Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class _InternalProxy internal constructor(
}

companion object {
// TODO RUMM-3008 Expose it as public API? Needed for the integration tests at least,
// TODO RUM-368 Expose it as public API? Needed for the integration tests at least,
// because OkHttp MockWebServer is HTTP based
fun allowClearTextHttp(builder: Configuration.Builder): Configuration.Builder {
return builder.allowClearTextHttp()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
package com.datadog.android.api.storage

import androidx.annotation.WorkerThread
import com.datadog.tools.annotation.NoOpImplementation

/**
* Interface to be implemented by the class which wants to write arbitrary data with the
* given [EventBatchWriter].
*/
@NoOpImplementation(publicNoOpImplementation = true)
interface DataWriter<T> {
/**
* Writes the element with a given [EventBatchWriter].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ internal class DatadogCore(
features.values.forEach {
it.clearAllData()
}
// TODO RUM-1462 address Thread safety
@Suppress("ThreadSafety") // removal of the data is done in synchronous manner
coreFeature.deleteLastViewEvent()
@Suppress("ThreadSafety") // removal of the data is done in synchronous manner
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ package com.datadog.android.core.internal
import com.datadog.android.api.context.DatadogContext

internal interface ContextProvider {
// TODO RUMM-0000 getting context may be quite heavy, should it be something non-blocking here?
// TODO RUMM-0000 lifecycle checks may be needed for the cases when context is requested
// TODO RUM-3784 getting context may be quite heavy, should it be something non-blocking here?

// TODO RUM-3784 lifecycle checks may be needed for the cases when context is requested
// when datadog is not initialized yet/anymore (case of UploadWorker, other calls site
// should be in sync with lifecycle)
// TODO RUMM-0000 can be accessed from different threads

// TODO RUM-3784 can be accessed from different threads
val context: DatadogContext

fun setFeatureContext(feature: String, context: Map<String, Any?>)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ internal class CoreFeature(
// lazy here on purpose: we need to read it only once, even if it is used in different features
@get:WorkerThread
internal val lastViewEvent: JsonObject? by lazy {
// TODO RUM-1462 address Thread safety
@Suppress("ThreadSafety") // called in worker thread context
val viewEvent = readLastViewEvent()
if (viewEvent != null) {
Expand Down Expand Up @@ -319,7 +320,7 @@ internal class CoreFeature(

@WorkerThread
internal fun writeLastFatalAnrSent(anrTimestamp: Long) {
// TODO RUMM-0000 this is temporary solution for storing just a timestamp, later we will
// TODO RUM-3790 this is temporary solution for storing just a timestamp, later we will
// migrate to a dedicated data store solution (same applies to the last RUM view event)
val file = File(storageDir, LAST_FATAL_ANR_SENT_FILE_NAME)
file.writeTextSafe(anrTimestamp.toString(), Charsets.UTF_8, internalLogger)
Expand Down Expand Up @@ -690,7 +691,7 @@ internal class CoreFeature(
// TESTS ONLY, to prevent Kronos spinning sync threads in unit-tests, otherwise
// LoggingSyncListener can interact with internalLogger, breaking mockito
// verification expectations.
// TODO RUMM-0000 isolate Kronos somehow for unit-tests
// TODO RUM-3791 isolate Kronos somehow for unit-tests
internal var disableKronosBackgroundSync = false

// endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import com.datadog.android.api.context.UserInfo
import com.datadog.android.privacy.TrackingConsent

internal class NoOpContextProvider : ContextProvider {
// TODO RUMM-0000 this one is quite ugly. Should return type be nullable?
// TODO RUM-3784 this one is quite ugly. Should return type be nullable?
override val context: DatadogContext
get() = DatadogContext(
site = DatadogSite.US1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ internal class SdkFeature(
}

fun clearAllData() {
@Suppress("ThreadSafety") // TODO RUMM-1503 delegate to another thread
@Suppress("ThreadSafety") // TODO RUM-3756 delegate to another thread
storage.dropAll()
}

Expand Down Expand Up @@ -136,7 +136,7 @@ internal class SdkFeature(
forceNewBatch: Boolean,
callback: (DatadogContext, EventBatchWriter) -> Unit
) {
// TODO RUMM-0000 thread safety. Thread switch happens in Storage right now. Open questions:
// TODO RUM-1462 thread safety. Thread switch happens in Storage right now. Open questions:
// * what if caller wants to have a sync operation, without thread switch
// * should context read and write be on the dedicated thread? risk - time gap between
// caller and context
Expand Down Expand Up @@ -303,7 +303,6 @@ internal class SdkFeature(

// Used for nightly tests only
internal fun flushStoredData() {
// TODO RUMM-0000 should it just accept storage?
val flusher = DataFlusher(
coreFeature.contextProvider,
fileOrchestrator,
Expand All @@ -312,7 +311,7 @@ internal class SdkFeature(
FileMover(internalLogger),
internalLogger
)
@Suppress("ThreadSafety")
@Suppress("ThreadSafety") // TODO RUM-1462 address Thread safety
flusher.flush(uploader)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ internal class BroadcastReceiverNetworkInfoProvider(
private var networkInfo: NetworkInfo = NetworkInfo()
set(value) {
field = value
@Suppress("ThreadSafety") // TODO RUMM-1503 delegate to another thread
@Suppress("ThreadSafety") // TODO RUM-3756 delegate to another thread
dataWriter.write(field)
}

Expand All @@ -53,7 +53,11 @@ internal class BroadcastReceiverNetworkInfoProvider(

override fun register(context: Context) {
val filter = IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)
registerReceiver(context, filter).also { onReceive(context, it) }
registerReceiver(context, filter).also {
// TODO RUM-1462 address Thread safety
@Suppress("ThreadSafety") // Treatment should be fast enough
onReceive(context, it)
}
}

override fun unregister(context: Context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ internal class CallbackNetworkInfoProvider(
private var lastNetworkInfo: NetworkInfo = NetworkInfo()
set(value) {
field = value
@Suppress("ThreadSafety") // TODO RUMM-1503 delegate to another thread
@Suppress("ThreadSafety") // TODO RUM-3756 delegate to another thread
dataWriter.write(field)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ internal class AbstractStorage(
}

override fun dropAll() {
@Suppress("ThreadSafety")
@Suppress("ThreadSafety") // TODO RUM-1462 address Thread safety
executorService.submitSafe("Data drop", internalLogger) {
grantedPersistenceStrategy.dropAll()
pendingPersistenceStrategy.dropAll()
Expand All @@ -125,7 +125,7 @@ internal class AbstractStorage(
previousConsent: TrackingConsent,
newConsent: TrackingConsent
) {
@Suppress("ThreadSafety")
@Suppress("ThreadSafety") // TODO RUM-1462 address Thread safety
executorService.submitSafe("Data migration", internalLogger) {
if (previousConsent == TrackingConsent.PENDING) {
when (newConsent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ import com.datadog.tools.annotation.NoOpImplementation
@NoOpImplementation
internal interface Storage {

// TODO RUMM-0000 It seems only write part is useful to be async. Having upload part as async
// brings more complexity and is not really needed, because there is a dedicated upload
// thread anyway and upload part is not exposed as public API (except only data ->
// request transformation).
/**
* Utility to write data, asynchronously.
* @param datadogContext the context for the write operation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import java.io.FileFilter
import java.util.Locale
import kotlin.math.roundToLong

// TODO RUMM-3373 Improve this class: need to make it thread-safe and optimize work with file
// TODO RUM-438 Improve this class: need to make it thread-safe and optimize work with file
// system in order to reduce the number of syscalls (which are expensive) for files already seen
internal class BatchFileOrchestrator(
private val rootDir: File,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ internal class DatadogUserInfoProvider(
private var internalUserInfo = UserInfo()
set(value) {
field = value
@Suppress("ThreadSafety") // TODO RUMM-1503 delegate to another thread
@Suppress("ThreadSafety") // TODO RUM-3756 delegate to another thread
dataWriter.write(field)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

package com.datadog.android.core.internal.utils

// TODO RUMM-3004 public as hack, no other solution for now. Any?.toJsonElement relies on this
// TODO RUM-373 public as hack, no other solution for now. Any?.toJsonElement relies on this
// particular value. Maybe create something like (class NullMap) and check identity instead?
/**
* Special value for missing attribute.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ internal class DatadogExceptionHandler(
)
}

// TODO RUMM-0000 If DatadogExceptionHandler goes into dedicated module (module of 1 class
// TODO RUM-3794 If DatadogExceptionHandler goes into dedicated module (module of 1 class
// only?), we have to wait for the write in some other way
// give some time to the persistence executor service to finish its tasks
if (sdkCore is InternalSdkCore) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ internal class DatadogNdkCrashHandler(

override fun prepareData() {
dataPersistenceExecutorService.submitSafe("NDK crash check", internalLogger) {
@Suppress("ThreadSafety")
@Suppress("ThreadSafety") // TODO RUM-1462 address Thread safety
readCrashData()
}
}
Expand All @@ -61,7 +61,7 @@ internal class DatadogNdkCrashHandler(
reportTarget: NdkCrashHandler.ReportTarget
) {
dataPersistenceExecutorService.submitSafe("NDK crash report ", internalLogger) {
@Suppress("ThreadSafety")
@Suppress("ThreadSafety") // TODO RUM-1462 address Thread safety
checkAndHandleNdkCrashReport(sdkCore, reportTarget)
}
}
Expand All @@ -81,7 +81,7 @@ internal class DatadogNdkCrashHandler(

ndkCrashDataDirectory.listFilesSafe(internalLogger)?.forEach { file ->
when (file.name) {
// TODO RUMM-1944 Data from NDK should be also encrypted
// TODO RUM-639 Data from NDK should be also encrypted
CRASH_DATA_FILE_NAME ->
lastNdkCrashLog =
file.readTextSafe(internalLogger = internalLogger)?.let {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ package com.datadog.tools.annotation

/**
* Adding this annotation on an interface will generate a No-Op implementation class.
* @property publicNoOpImplementation if true, the NoOp implementation will be made public,
* otherwise it will be marked as Internal (default: false)
*/
@Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.BINARY)
annotation class NoOpImplementation
annotation class NoOpImplementation(
val publicNoOpImplementation: Boolean = false
)
5 changes: 5 additions & 0 deletions detekt_custom.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ datadog:
- '**/reliability/**'
- '**/sample/**'
- '**/tools/**'
TodoWithoutTask:
active: true
deprecatedPrefixes:
- "RUMM"
- "REPLAY"
UnsafeThirdPartyFunctionCall:
active: true
internalPackagePrefix: 'com.datadog'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import com.datadog.android.api.feature.StorageBackedFeature
import com.datadog.android.api.net.RequestFactory
import com.datadog.android.api.storage.DataWriter
import com.datadog.android.api.storage.FeatureStorageConfiguration
import com.datadog.android.api.storage.NoOpDataWriter
import com.datadog.android.core.feature.event.JvmCrash
import com.datadog.android.core.internal.utils.NULL_MAP_VALUE
import com.datadog.android.event.EventMapper
Expand All @@ -28,7 +29,6 @@ import com.datadog.android.log.internal.domain.event.LogEventMapperWrapper
import com.datadog.android.log.internal.domain.event.LogEventSerializer
import com.datadog.android.log.internal.net.LogsRequestFactory
import com.datadog.android.log.internal.storage.LogsDataWriter
import com.datadog.android.log.internal.storage.NoOpDataWriter
import com.datadog.android.log.model.LogEvent
import java.util.Locale
import java.util.concurrent.ConcurrentHashMap
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import fr.xgouchet.elmyr.annotation.StringForgery
import fr.xgouchet.elmyr.junit5.ForgeExtension
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.RepeatedTest
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith
Expand Down Expand Up @@ -62,13 +61,6 @@ internal class LogcatLogHandlerTest {
.isEqualTo(javaClass.canonicalName)
}

// TODO RUMM-1732
@Disabled(
"Check this test later. After update to Gradle 7 it seems there is some change to" +
" the test run mechanism, because .className returns parent enclosing class" +
" without any anonymous classes, and anonymous class itself is called \$lambda-0" +
" instead of \$1"
)
@Test
fun `resolves nested stack trace element from caller`() {
testedHandler = LogcatLogHandler(fakeServiceName, true, isDebug = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ object Rum {
sdkCore
)

// TODO RUM-0000 there is a small chance of application crashing between RUM monitor
// TODO RUM-3794 there is a small chance of application crashing between RUM monitor
// registration and the moment SDK init is processed, in this case we will miss this crash
// (it won't activate new session). Ideally we should start session when monitor is created
// and before it is registered, but with current code (internal RUM scopes using the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ package com.datadog.android.rum
/**
* This class holds constant rum attribute keys.
*/
// @Suppress("unused")
object RumAttributes {

// region Tags
Expand Down Expand Up @@ -284,7 +283,6 @@ object RumAttributes {

/**
* Total number of bytes transmitted from the client to the server. (Number)
* TODO RUMM-469 rename to v2
*/
const val NETWORK_BYTES_READ: String = "network.bytes_read"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import com.datadog.android.api.feature.StorageBackedFeature
import com.datadog.android.api.net.RequestFactory
import com.datadog.android.api.storage.DataWriter
import com.datadog.android.api.storage.FeatureStorageConfiguration
import com.datadog.android.api.storage.NoOpDataWriter
import com.datadog.android.core.InternalSdkCore
import com.datadog.android.core.feature.event.JvmCrash
import com.datadog.android.core.internal.system.BuildSdkVersionProvider
Expand Down Expand Up @@ -51,7 +52,6 @@ import com.datadog.android.rum.internal.instrumentation.gestures.DatadogGestures
import com.datadog.android.rum.internal.monitor.AdvancedRumMonitor
import com.datadog.android.rum.internal.monitor.DatadogRumMonitor
import com.datadog.android.rum.internal.net.RumRequestFactory
import com.datadog.android.rum.internal.storage.NoOpDataWriter
import com.datadog.android.rum.internal.thread.NoOpScheduledExecutorService
import com.datadog.android.rum.internal.tracking.JetpackViewAttributesProvider
import com.datadog.android.rum.internal.tracking.NoOpUserActionTrackingStrategy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ package com.datadog.android.rum.internal.domain.scope
import androidx.annotation.WorkerThread
import com.datadog.android.api.feature.Feature
import com.datadog.android.api.storage.DataWriter
import com.datadog.android.api.storage.NoOpDataWriter
import com.datadog.android.core.InternalSdkCore
import com.datadog.android.core.internal.net.FirstPartyHostHeaderTypeResolver
import com.datadog.android.rum.RumSessionListener
import com.datadog.android.rum.internal.domain.RumContext
import com.datadog.android.rum.internal.storage.NoOpDataWriter
import com.datadog.android.rum.internal.vitals.VitalMonitor
import com.datadog.android.rum.utils.percent
import java.security.SecureRandom
Expand Down
Loading
Loading