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

RUM-7337: Adjust Webview Replay storage configuration limits #2400

Merged
merged 1 commit into from
Nov 20, 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
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ internal class WebViewReplayFeature(
}

override val storageConfiguration: FeatureStorageConfiguration =
FeatureStorageConfiguration.DEFAULT
STORAGE_CONFIGURATION

override fun onStop() {
dataWriter = NoOpDataWriter()
Expand All @@ -55,5 +55,18 @@ internal class WebViewReplayFeature(

companion object {
internal const val WEB_REPLAY_FEATURE_NAME = "web-replay"

/**
* Storage configuration with the following parameters:
* max item size = 10 MB,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious what can generate item with 10 MB size

* max items per batch = 500,
* max batch size = 10 MB, SR intake batch limit is 10MB
* old batch threshold = 18 hours.
*/
internal val STORAGE_CONFIGURATION: FeatureStorageConfiguration =
FeatureStorageConfiguration.DEFAULT.copy(
maxItemSize = 10 * 1024 * 1024,
maxBatchSize = 10 * 1024 * 1024
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
* This product includes software developed at Datadog (https://www.datadoghq.com/).
* Copyright 2016-Present Datadog, Inc.
*/

package com.datadog.android.webview.internal.replay

import android.content.Context
import com.datadog.android.api.feature.FeatureSdkCore
import com.datadog.android.api.net.RequestFactory
import com.datadog.android.api.storage.NoOpDataWriter
import com.datadog.android.utils.forge.Configurator
import com.datadog.android.webview.internal.storage.WebViewDataWriter
import fr.xgouchet.elmyr.junit5.ForgeConfiguration
import fr.xgouchet.elmyr.junit5.ForgeExtension
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith
import org.junit.jupiter.api.extension.Extensions
import org.mockito.Mock
import org.mockito.Mockito.mock
import org.mockito.junit.jupiter.MockitoExtension
import org.mockito.junit.jupiter.MockitoSettings
import org.mockito.kotlin.doReturn
import org.mockito.kotlin.whenever
import org.mockito.quality.Strictness

@Extensions(
ExtendWith(MockitoExtension::class),
ExtendWith(ForgeExtension::class)
)
@MockitoSettings(strictness = Strictness.LENIENT)
@ForgeConfiguration(Configurator::class)
internal class WebViewReplayFeatureTest {

private lateinit var testedFeature: WebViewReplayFeature

@Mock
lateinit var mockRequestFactory: RequestFactory

@Mock
lateinit var mockSdkCore: FeatureSdkCore

@Mock
lateinit var mockAppContext: Context

@BeforeEach
fun `set up`() {
testedFeature = WebViewReplayFeature(mockSdkCore, mockRequestFactory)
whenever(mockSdkCore.internalLogger) doReturn mock()
}

@Test
fun `M provide feature name W name()`() {
// Then
assertThat(testedFeature.name)
.isEqualTo(WebViewReplayFeature.WEB_REPLAY_FEATURE_NAME)
}

@Test
fun `M provide correct storage configuration W storageConfiguration()`() {
// Then
assertThat(testedFeature.storageConfiguration)
.isEqualTo(WebViewReplayFeature.STORAGE_CONFIGURATION)
}

@Test
fun `M unregister writer W onStop()`() {
// Given
testedFeature.onInitialize(mockAppContext)

// When
testedFeature.onStop()

// Then
assertThat(testedFeature.initialized).isFalse
assertThat(testedFeature.dataWriter)
.isInstanceOf(NoOpDataWriter::class.java)
}

@Test
fun `M initialize writer W initialize()`() {
// When
testedFeature.onInitialize(mockAppContext)

// Then
assertThat(testedFeature.dataWriter)
.isInstanceOf(WebViewDataWriter::class.java)
assertThat(testedFeature.initialized).isTrue
}
}