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

feat: sdk 1008 manual session #404

Open
wants to merge 18 commits into
base: feat/android
Choose a base branch
from

Conversation

itsdebs
Copy link
Contributor

@itsdebs itsdebs commented Mar 11, 2024

Fixes # (issue)

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist:

  • Version upgraded (project, README, gradle, podspec etc)
  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added unit tests for the code
  • I have made corresponding changes to the documentation

itsdebs added 2 commits March 7, 2024 19:57
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]>
Copy link

sonarcloud bot commented Mar 11, 2024

Quality Gate Passed Quality Gate passed

Issues
4 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

session is not dependent on trackLifeCycle
If previous session(manual or automatic) is not timed out,
 no new session will be created
@ChryssaAliferi ChryssaAliferi marked this pull request as ready for review April 29, 2024 07:54
# 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
Copy link
Contributor

@ChryssaAliferi ChryssaAliferi left a 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"
Copy link
Contributor

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))
Copy link
Contributor

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)
Copy link
Contributor

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.

Copy link
Contributor Author

@itsdebs itsdebs May 2, 2024

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.

Copy link
Contributor Author

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)
Copy link
Contributor

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()
    }
}


Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for pointing

Copy link
Contributor Author

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() {
Copy link
Contributor

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
Copy link
Contributor

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(
Copy link
Contributor

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.

itsdebs added 5 commits May 9, 2024 12:55
# 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
Copy link

sonarcloud bot commented May 13, 2024

Quality Gate Passed Quality Gate passed

Issues
1 New issue
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@itsdebs itsdebs added the v2 label Jun 18, 2024
itsdebs added 5 commits June 19, 2024 14:51
# 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
@1abhishekpandey 1abhishekpandey requested review from 1abhishekpandey and removed request for desusai7 June 25, 2024 15:05
Comment on lines 37 to 46
configurationScope = {
dataPlaneUrl = DATA_PLANE_URL
controlPlaneUrl = CONTROL_PLANE_URL
trackLifecycleEvents = true
recordScreenViews = true
isPeriodicFlushEnabled = true
autoCollectAdvertisingId = true
trackAutoSession = true
logLevel = RudderLogger.LogLevel.DEBUG
}
Copy link
Contributor

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.

itsdebs added 3 commits June 26, 2024 16:03
feat: reset will now refresh the session id if it exists
fix: manual session continuation
Copy link

sonarcloud bot commented Jun 28, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants