Skip to content

RUMM-2138 make SDK Features simple classes#928

Merged
xgouchet merged 1 commit into
feature/sdkv2from
xgouchet/RUMM-2138/SDK_Features
May 10, 2022
Merged

RUMM-2138 make SDK Features simple classes#928
xgouchet merged 1 commit into
feature/sdkv2from
xgouchet/RUMM-2138/SDK_Features

Conversation

@xgouchet

@xgouchet xgouchet commented May 9, 2022

Copy link
Copy Markdown
Contributor

What does this PR do?

Converts all SdkFeature objects to classes.

NOTE: tests were not updated at this stage, this is a transitional state that will be followed by more refactoring.

@xgouchet
xgouchet requested a review from a team as a code owner May 9, 2022 08:43
@xgouchet
xgouchet force-pushed the xgouchet/RUMM-2138/SDK_Features branch from eeabb5c to ca7a978 Compare May 9, 2022 09:44

@mariusc83 mariusc83 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@0xnm 0xnm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I've added some questions/concerns, but overall lgtm and these are non-blocking.

With this change we have quite a lot of usages of ?. operator and null checks, but I hope later it will go away (otherwise we need to think how to we check invariants of the SDK state - for example for A to work we should have B created, and if it is not the case, we should report this violation).

/** @inheritdoc */
override fun intercept(chain: Interceptor.Chain): Response {
if (RumFeature.isInitialized()) {
val rumFeature = (Datadog.globalSDKCore as? DatadogCore)?.rumFeature

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

How do we make sure that we won't forget parts of the code like this (getting the feature with nullable chain with casting)? Maybe add TODO item?

I think we need to add some method which will encapsulate that, or maybe such chains will go away once we finish the rewrite.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

A lot of the dependencies will be reversed.
In v1 we had something like :

class SomethingUsingFeatureA {
    fun foo() {
        get FeatureA.component
    }
}

In v2 we'll have:

class SomethingUsingFeatureA(component: FeatureAComponent)

class FeatureA {
    buildSomething(): SomethingUsingFeatureA
}

// endregion

companion object {
internal var processImportance: Int =

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Shouldn't this field be a class member? I understand why we would want to keep it in the companion (the value will always be the same for the whole process for any instance of CoreFeature), but my concern is what if we have call to this field from different threads (say each instance of CoreFeature is running on the dedicated thread).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

In the end it'll be in the SDKContext, I kept it there to minimize the impact of the current feature

uploadAllBatches(
RumFeature.persistenceStrategy.getReader(),
RumFeature.uploader
val globalSDKCore: DatadogCore? = (Datadog.globalSDKCore as? DatadogCore)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

minor: why do we need an explicit type here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not necessary, it'll disappear eventually

val rumApplicationId = CoreFeature.rumApplicationId
return if (!RumFeature.isInitialized()) {
val datadogCore = Datadog.globalSDKCore as? DatadogCore
val coreFeature = datadogCore?.coreFeature

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A thought: if rumFeature (and any other feature) takes non-null coreFeature in the constructor, can we get coreFeature through rumFeature? This would eliminate checking coreFeature for null here and other places in the codebase where we access coreFeature near the specific feature.

Because otherwise they are independent code-wise (while in reality they are dependent) and for example blocks like check for if (rumFeature == null || coreFeature == null) below look strange: we cannot have a rumFeature without having a coreFeature.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

In the end yes, it'll be that way


override fun onMenuItemSelected(featureId: Int, item: MenuItem): Boolean {
val resourceId = resourceIdName(item.itemId)
val resourceId = windowReference.get()?.context.resourceIdName(item.itemId)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

can be replaced with extension function created

timeProvider = CoreFeature.timeProvider

if (coreFeature == null || webViewLogsFeature == null || webViewRumFeature == null) {
return NoOpWebViewEventConsumer()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

should we add the warning?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It'll disappear before the end of the v2 refactor

@xgouchet
xgouchet merged commit 5504289 into feature/sdkv2 May 10, 2022
@xgouchet
xgouchet deleted the xgouchet/RUMM-2138/SDK_Features branch May 10, 2022 04:44
@xgouchet xgouchet added this to the 1.16.0 milestone Dec 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants