-
Notifications
You must be signed in to change notification settings - Fork 29
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
feat: sdk 1008 manual session #404
base: feat/android
Are you sure you want to change the base?
Conversation
feat: removed json adapter out of configuration. feat: changed to lazy configuration initialization to help restoring it from storage. Signed-off-by: Debanjan Chatterjee <[email protected]>
if trackAutoSesssion is true, manual session will continue till timeout Signed-off-by: Debanjan Chatterjee <[email protected]>
Quality Gate passedIssues Measures |
session is not dependent on trackLifeCycle If previous session(manual or automatic) is not timed out, no new session will be created
# Conflicts: # android/src/main/java/com/rudderstack/android/RudderAnalytics.kt # android/src/main/java/com/rudderstack/android/compat/RudderAnalyticsBuilderCompat.java # android/src/test/java/com/rudderstack/android/android/RudderAnalyticsTest.kt # core/src/main/java/com/rudderstack/core/Analytics.kt # core/src/main/java/com/rudderstack/core/compat/AnalyticsBuilderCompat.java # core/src/main/java/com/rudderstack/core/compat/ConfigurationBuilder.java # core/src/test/java/com/rudderstack/core/internal/plugins/EventSizeFilterPluginTest.kt # core/src/test/java/com/rudderstack/core/internal/plugins/GDPRPluginTest.kt # samples/sample-kotlin-android/src/main/kotlin/com/rudderstack/android/sampleapp/analytics/RudderAnalyticsUtils.kt # samples/sample-kotlin-android/src/main/kotlin/com/rudderstack/android/sampleapp/analytics/Values.kt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great effort with the analytics test and TestAnalytics
provider!! But lets not create more generateTestAnalytics
methods.
In this patch file I have refactored both generateTestAnalytics
methods to one, the fun provideAnalytics(...)
:
feat__refactors_provideAnalytics_test_provider.patch
Take a look and let me know! This is way more organised and adjustable on all test/business logic cases.
Also I need us to merge the branch with the current feat/android
because there are conflicts that make me unsure on what to review. When we do this I will try to review once more!
const val WRITE_KEY = "2CYw61Oy8Wsrkh0ZHf65QDLYpDJ" | ||
const val DATA_PLANE_URL = "https://rudderstaclpl.dataplane.dev.rudderlabs.com/v1/batch" | ||
const val CONTROL_PLANE_URL = "https://api.dev.rudderlabs.com" | ||
const val BASE_URL = "https://BASE_URL" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't merge back this to feat/android
, as this has already been changed logic by using rudderstack.properties
.
@@ -52,6 +52,8 @@ class GDPRPluginTest { | |||
val optOutTestChain = CentralPluginChain(message, listOf(gdprPlugin, testPluginForOptOut) | |||
, originalMessage = message) | |||
//opted out | |||
// gdprPlugin.updateConfiguration(Configuration( | |||
// isOptOut = true)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this code is not needed, please let's remove.
|
||
class EventSizeFilterPluginTest { | ||
|
||
@get:Rule | ||
val mockkRule = MockKRule(this) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I remember we agreed as a team not to use Mockk
yet. What did change? In my opinion Mockk should be the only way to move forward, and there are not many counter arguments, but using Mockk
now seems very unaccountable and passes wrong messages to the team members. Let's change, or let's seriously evaluate this tools usage across the project.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was implemented prior to the discussion. Thanks for pointing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can remove these in separate PR
@@ -14,17 +16,24 @@ import java.util.concurrent.atomic.AtomicReference | |||
class EventSizeFilterPlugin : Plugin { | |||
|
|||
private val currentConfigurationAtomic = AtomicReference<Configuration?>() | |||
private var _analyticsRef = WeakReference<Analytics>(null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private val currentConfigurationAtomic = AtomicReference<Configuration?>()
private val currentConfiguration
get() = currentConfigurationAtomic.get()
These are two class members that do the same thing. It is advised to avoid having class members that consume memory without any particular reason. A simplification of the class like below would be preferable:
package com.rudderstack.core.internal.plugins
import com.rudderstack.core.Analytics
import com.rudderstack.core.Configuration
import com.rudderstack.core.Plugin
import com.rudderstack.core.RudderUtils.MAX_EVENT_SIZE
import com.rudderstack.core.RudderUtils.getUTF8Length
import com.rudderstack.models.Message
import com.rudderstack.rudderjsonadapter.RudderTypeAdapter
import java.lang.ref.WeakReference
import java.util.concurrent.atomic.AtomicReference
/**
* A plugin to filter out events that exceed the maximum size limit.
*/
class EventSizeFilterPlugin : Plugin {
private val currentConfiguration = AtomicReference<Configuration?>(null)
private var _analyticsRef = WeakReference<Analytics>(null)
override fun setup(analytics: Analytics) {
_analyticsRef = WeakReference(analytics)
}
override fun updateConfiguration(configuration: Configuration) {
currentConfiguration.set(configuration)
}
override fun intercept(chain: Plugin.Chain): Message {
currentConfiguration.get()?.let { config ->
val messageJSON = analyticsRef.get()?.jsonAdapter?.writeToJson(chain.message(), object :
RudderTypeAdapter<Message>() {})
val messageSize = messageJSON?.toString()?.getUTF8Length() ?: 0
if (messageSize > MAX_EVENT_SIZE) {
config.logger.error(log = "Event size exceeds the maximum size of $MAX_EVENT_SIZE bytes. Dropping the event.")
return chain.message()
}
}
return chain.proceed(chain.message())
}
override fun onShutDown() {
_analyticsRef.clear()
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for pointing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have not been through this plugin, this plugin was part of the event filtering task, can we deal with it in a separate PR?
You can create a linear ticket for improvements.
((currentConfigurationAndroid?.trackAutoSession != true) | ||
&& androidStorage.trackAutoSession) | ||
|
||
private fun Analytics.updateSessionLastActiveTimestamp() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can simplify and use directly the userSessionsState value, like that:
private fun Analytics.updateSessionLastActiveTimestamp() {
userSessionState?.value?.let {
it.copy(lastActiveTimestamp = defaultLastActiveTimestamp)
}
}
@@ -31,7 +32,8 @@ import java.util.concurrent.atomic.AtomicReference | |||
|
|||
internal class ConfigDownloadServiceImpl @JvmOverloads constructor( | |||
private val writeKey: String, | |||
webService: WebService? = null, | |||
private val jsonAdapter: JsonAdapter, | |||
webService: WebService? = null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private val webService: WebService? = null
// dataPlaneUrl = DATA_PLANE_URL, | ||
// controlPlaneUrl = CONTROL_PLANE_URL, | ||
// recordScreenViews = true, | ||
copy( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please would you like to explain more about this copy
method and that callback added here? Frankly, it does not look much user-friendly.
# Conflicts: # android/src/main/java/com/rudderstack/android/RudderAnalytics.kt # android/src/main/java/com/rudderstack/android/storage/RudderEntityFactory.kt # android/src/test/java/com/rudderstack/android/internal/plugins/ReinstatePluginTest.kt # core/src/main/java/com/rudderstack/core/internal/AnalyticsDelegate.kt # core/src/main/java/com/rudderstack/core/internal/DataUploadServiceImpl.kt # core/src/test/java/com/rudderstack/core/internal/ConfigDownloadServiceImplTest.kt # samples/sample-kotlin-android/src/main/kotlin/com/rudderstack/android/sampleapp/analytics/RudderAnalyticsUtils.kt
Quality Gate passedIssues Measures |
# Conflicts: # android/src/main/java/com/rudderstack/android/ConfigurationAndroid.kt # android/src/main/java/com/rudderstack/android/RudderAnalytics.kt # android/src/main/java/com/rudderstack/android/compat/ConfigurationAndroidBuilder.java # android/src/main/java/com/rudderstack/android/compat/RudderAnalyticsBuilderCompat.java # android/src/main/java/com/rudderstack/android/internal/plugins/PlatformInputsPlugin.kt # android/src/main/java/com/rudderstack/android/utilities/SessionUtils.kt # android/src/test/java/com/rudderstack/android/RudderAnalyticsTest.kt # android/src/test/java/com/rudderstack/android/internal/infrastructure/ReinstatePluginTest.kt # android/src/test/java/com/rudderstack/android/utilities/SessionUtilsTest.kt # core/src/main/java/com/rudderstack/core/Analytics.kt # core/src/main/java/com/rudderstack/core/Configuration.kt # core/src/main/java/com/rudderstack/core/compat/ConfigurationBuilder.java # core/src/main/java/com/rudderstack/core/internal/DataUploadServiceImpl.kt # core/src/test/java/com/rudderstack/core/AnalyticsTest.kt # core/src/test/java/com/rudderstack/core/compat/ConfigurationBuilderTest.java # samples/sample-kotlin-android/src/main/kotlin/com/rudderstack/android/sampleapp/analytics/RudderAnalyticsUtils.kt # samples/sample-kotlin-android/src/main/kotlin/com/rudderstack/android/sampleapp/mainview/MainViewModel.kt
# Conflicts: # android/src/main/java/com/rudderstack/android/ConfigurationAndroid.kt # android/src/main/java/com/rudderstack/android/compat/ConfigurationAndroidBuilder.java # android/src/main/java/com/rudderstack/android/storage/AndroidStorageImpl.kt # android/src/test/java/com/rudderstack/android/AndroidStorageTest.kt # android/src/test/java/com/rudderstack/android/RudderAnalyticsTest.kt # android/src/test/java/com/rudderstack/android/internal/infrastructure/ReinstatePluginTest.kt # android/src/test/java/com/rudderstack/android/plugins/PlatformInputsPluginTest.kt # android/src/test/java/com/rudderstack/android/utilities/SessionUtilsTest.kt # core/src/main/java/com/rudderstack/core/internal/AnalyticsDelegate.kt # core/src/test/java/com/rudderstack/core/compat/ConfigurationBuilderTest.java # samples/sample-kotlin-android/src/main/kotlin/com/rudderstack/android/sampleapp/analytics/RudderAnalyticsUtils.kt
chore: fix tests
configurationScope = { | ||
dataPlaneUrl = DATA_PLANE_URL | ||
controlPlaneUrl = CONTROL_PLANE_URL | ||
trackLifecycleEvents = true | ||
recordScreenViews = true | ||
isPeriodicFlushEnabled = true | ||
autoCollectAdvertisingId = true | ||
trackAutoSession = true | ||
logLevel = RudderLogger.LogLevel.DEBUG | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please revert this change for now?
I tried to disable the lifecycle
flag to false
and after that also I can see the lifecycle events in our dashboard.
feat: reset will now refresh the session id if it exists fix: manual session continuation
Quality Gate passedIssues Measures |
Fixes # (issue)
Type of change
Checklist: