Skip to content

Commit

Permalink
Fix PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
xgouchet committed Dec 9, 2022
1 parent 32a07a0 commit 10deac9
Show file tree
Hide file tree
Showing 14 changed files with 36 additions and 31 deletions.
7 changes: 4 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ The whole project is covered by a set of static analysis tools, linters and test
./gradlew instrumentTestAll

# launches the detekt static analysis for all modules
# the detekt client needs to be installed on your machine via Homebrew
# the configuration files are stored in the dd-source repository
detekt --config {dd-source}/domains/mobile/config/android/gitlab/detekt/detekt-common.yml
# the detekt client needs to be installed on your machine as stated in the official documentation
# https://detekt.dev/docs/gettingstarted/cli
# the configuration files are stored in Datadog's dd-source repository
detekt --config {dd-source}/domains/mobile/config/android/gitlab/detekt/detekt-common.yml
detekt --config {dd-source}/domains/mobile/config/android/gitlab/detekt/detekt-public-api.yml

# launches the ktlint check and formatter for all Kotlin files
# the ktlint client needs to be installed on your machine
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import com.datadog.android.core.internal.net.FirstPartyHostDetector
import com.datadog.android.core.internal.net.identifyRequest
import com.datadog.android.core.internal.sampling.RateBasedSampler
import com.datadog.android.core.internal.sampling.Sampler
import com.datadog.android.core.internal.utils.HUNDRED
import com.datadog.android.core.internal.utils.devLogger
import com.datadog.android.core.internal.utils.percent
import com.datadog.android.core.internal.utils.sdkLogger
import com.datadog.android.rum.GlobalRum
import com.datadog.android.rum.NoOpRumResourceAttributesProvider
Expand Down Expand Up @@ -104,7 +104,6 @@ internal constructor(
* be kept, `100.0` means all traces will be kept (default value is `20.0`).
*/
@JvmOverloads
@Suppress("MagicNumber")
constructor(
firstPartyHosts: List<String>,
tracedRequestListener: TracedRequestListener = NoOpTracedRequestListener(),
Expand All @@ -116,7 +115,7 @@ internal constructor(
tracedRequestListener = tracedRequestListener,
firstPartyHostDetector = getGlobalFirstPartyHostDetector(),
rumResourceAttributesProvider = rumResourceAttributesProvider,
traceSampler = RateBasedSampler(traceSamplingRate / HUNDRED),
traceSampler = RateBasedSampler(traceSamplingRate.percent()),
localTracerFactory = { AndroidTracer.Builder().build() }
)

Expand All @@ -143,7 +142,7 @@ internal constructor(
tracedRequestListener = tracedRequestListener,
firstPartyHostDetector = getGlobalFirstPartyHostDetector(),
rumResourceAttributesProvider = rumResourceAttributesProvider,
traceSampler = RateBasedSampler(traceSamplingRate / HUNDRED),
traceSampler = RateBasedSampler(traceSamplingRate.percent()),
localTracerFactory = { AndroidTracer.Builder().build() }
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ internal open class BatchFileDataWriter<T : Any>(
/**
* Called whenever data is written successfully.
* @param data the data written
* @param rawData the data written (as the actual ByteArray written on disk)
* @param rawData the data written (as the actual [ByteArray] written on disk)
*/
@WorkerThread
internal open fun onDataWritten(data: T, rawData: ByteArray) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ internal fun Long.toHexString() = toString(HEX_RADIX)
internal fun BigInteger.toHexString(): String {
return toLong().toHexString()
}

internal fun Float.percent() = this / HUNDRED
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import androidx.annotation.FloatRange
import androidx.fragment.app.Fragment
import com.datadog.android.Datadog
import com.datadog.android.core.internal.sampling.RateBasedSampler
import com.datadog.android.core.internal.utils.HUNDRED
import com.datadog.android.core.internal.utils.devLogger
import com.datadog.android.core.internal.utils.percent
import com.datadog.android.rum.internal.monitor.DatadogRumMonitor
import com.datadog.android.telemetry.internal.TelemetryEventHandler
import com.datadog.android.v2.core.DatadogCore
Expand Down Expand Up @@ -308,7 +308,7 @@ interface RumMonitor {
telemetryEventHandler = TelemetryEventHandler(
sdkCore = datadogCore,
coreFeature.timeProvider,
RateBasedSampler(rumFeature.telemetrySamplingRate / HUNDRED)
RateBasedSampler(rumFeature.telemetrySamplingRate.percent())
),
firstPartyHostDetector = coreFeature.firstPartyHostDetector,
cpuVitalMonitor = rumFeature.cpuVitalMonitor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import androidx.annotation.WorkerThread
import com.datadog.android.core.internal.net.FirstPartyHostDetector
import com.datadog.android.core.internal.system.BuildSdkVersionProvider
import com.datadog.android.core.internal.system.DefaultBuildSdkVersionProvider
import com.datadog.android.core.internal.utils.HUNDRED
import com.datadog.android.core.internal.utils.percent
import com.datadog.android.rum.RumSessionListener
import com.datadog.android.rum.internal.RumFeature
import com.datadog.android.rum.internal.domain.RumContext
Expand Down Expand Up @@ -144,7 +144,7 @@ internal class RumSessionScope(
}

private fun renewSession(nanoTime: Long) {
val keepSession = (random.nextFloat() * HUNDRED) < samplingRate
val keepSession = random.nextFloat() < samplingRate.percent()
sessionState = if (keepSession) State.TRACKED else State.NOT_TRACKED
sessionId = UUID.randomUUID().toString()
sessionStartNs.set(nanoTime)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import com.datadog.android.core.configuration.Configuration
import com.datadog.android.core.internal.net.FirstPartyHostDetector
import com.datadog.android.core.internal.sampling.RateBasedSampler
import com.datadog.android.core.internal.sampling.Sampler
import com.datadog.android.core.internal.utils.HUNDRED
import com.datadog.android.core.internal.utils.devLogger
import com.datadog.android.core.internal.utils.loggableStackTrace
import com.datadog.android.core.internal.utils.percent
import com.datadog.android.core.internal.utils.sdkLogger
import com.datadog.android.log.internal.utils.warningWithTelemetry
import com.datadog.android.v2.core.DatadogCore
Expand Down Expand Up @@ -105,7 +105,7 @@ internal constructor(
tracedRequestListener,
getGlobalFirstPartyHostDetector(),
null,
RateBasedSampler(traceSamplingRate / HUNDRED),
RateBasedSampler(traceSamplingRate.percent()),
{ AndroidTracer.Builder().build() }
)

Expand All @@ -126,7 +126,7 @@ internal constructor(
tracedRequestListener,
getGlobalFirstPartyHostDetector(),
null,
RateBasedSampler(traceSamplingRate / HUNDRED),
RateBasedSampler(traceSamplingRate.percent()),
{ AndroidTracer.Builder().build() }
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ internal class BatchFileOrchestratorTest {
assumeTrue(fakeRootDir.listFiles().isNullOrEmpty())
var previousFile = testedOrchestrator.getWritableFile()

repeat(5) {
repeat(4) {
checkNotNull(previousFile)

val previousData = forge.aList(MAX_ITEM_PER_BATCH) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@
package com.datadog.android.nightly.activities

internal const val HUNDRED_PERCENT = 100f
internal const val DATA_SIZE = 200L
internal const val REPEATED_TESTS = 100
internal const val FAKE_RESOURCE_DOWNLOADED_BYTES = 200L
internal const val CRASH_DELAY_MS = 1000L
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ internal class ResourceTrackingTraceSamplingActivity : AppCompatActivity() {

override fun onResume() {
super.onResume()
val countDownLatch = CountDownLatch(REPEATED_TESTS)
val countDownLatch = CountDownLatch(REQUEST_COUNT)
localServer.start { it.respond(HttpStatusCode.OK, "{}") }
repeat(REPEATED_TESTS) {
repeat(REQUEST_COUNT) {
okHttpClient
.newCall(
Request.Builder()
Expand All @@ -76,4 +76,8 @@ internal class ResourceTrackingTraceSamplingActivity : AppCompatActivity() {
localServer.stop()
super.onPause()
}

companion object {
internal const val REQUEST_COUNT = 100
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ internal class UserInteractionCustomTargetActivity : AppCompatActivity() {
GlobalRum.get().stopResource(
key,
HttpURLConnection.HTTP_OK,
DATA_SIZE,
FAKE_RESOURCE_DOWNLOADED_BYTES,
RumResourceKind.IMAGE,
emptyMap()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ internal class UserInteractionTrackingActivity : AppCompatActivity() {
GlobalRum.get().stopResource(
key,
HttpURLConnection.HTTP_OK,
DATA_SIZE,
FAKE_RESOURCE_DOWNLOADED_BYTES,
RumResourceKind.IMAGE,
emptyMap()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
*/
import com.datadog.gradle.plugin.gitclone.GitCloneDependenciesTask

val sessionReplayRepo = "https://github.com/DataDog/rum-events-format.git"
val sessionReplayVersion = "master"
val eventFormatRepo = "https://github.com/DataDog/rum-events-format.git"
val eventFormatVersion = "master"

tasks.register<GitCloneDependenciesTask>("cloneSessionReplayRootSchemas") {
extension.apply {
clone(
sessionReplayRepo,
eventFormatRepo,
"schemas/",
destinationFolder = "src/main/json/schemas",
excludedPrefixes = listOf(
Expand All @@ -22,29 +22,29 @@ tasks.register<GitCloneDependenciesTask>("cloneSessionReplayRootSchemas") {
"session-replay-schema",
"session-replay-browser-schema"
),
ref = sessionReplayVersion
ref = eventFormatVersion
)
}
}

tasks.register<GitCloneDependenciesTask>("cloneSessionReplayMobileSchemas") {
extension.apply {
clone(
sessionReplayRepo,
eventFormatRepo,
"schemas/session-replay/mobile",
destinationFolder = "src/main/json/schemas/session-replay/mobile",
ref = sessionReplayVersion
ref = eventFormatVersion
)
}
}

tasks.register<GitCloneDependenciesTask>("cloneSessionReplayCommonSchemas") {
extension.apply {
clone(
sessionReplayRepo,
eventFormatRepo,
"schemas/session-replay/common",
destinationFolder = "src/main/json/schemas/session-replay/common",
ref = sessionReplayVersion
ref = eventFormatVersion
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class ConditionWatcher(
}

private fun reportTimeout(timeoutMs: Long, assertionError: AssertionError?) {
val message = "Waiting took more than $timeoutMs millisseconds. Test stopped."
val message = "Waiting took more than $timeoutMs milliseconds. Test stopped."
if (assertionError == null) {
throw TimeoutException(message)
} else {
Expand Down

0 comments on commit 10deac9

Please sign in to comment.