-
Notifications
You must be signed in to change notification settings - Fork 135
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-3462 refactor: Make FeatureScope
always available
#1744
RUM-3462 refactor: Make FeatureScope
always available
#1744
Conversation
5a8af72
to
bf04aeb
Compare
var dataStore: DataStore { | ||
// Data store is only available when core instance exists. | ||
return (core != nil) ? store : NOPDataStore() | ||
} |
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.
Is it possible to provide a new instance each time?
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.
FeatureDataStore
has class semantic, so it sounds reasonable to cache it. Also, I assume we will use it this way:
scope.dataStore.setValue(...)
scope.dataStore.value(...)
scope.dataStore.remove(...)
so the instance will be crated each time.
Alternatively we can change FeatureDataStore
to be struct
, but that would mean creating unnecessary copies each time, no?
5131f5f
to
739a872
Compare
internal let core: DatadogCoreProtocol | ||
internal weak var core: DatadogCoreProtocol? |
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.
let core: DatadogCoreProtocol | ||
weak var core: DatadogCoreProtocol? |
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.
be9e7e4
to
11678de
Compare
Datadog ReportBranch report: ✅ 0 Failed, 2944 Passed, 0 Skipped, 27m 44.74s Wall Time 🔻 Code Coverage Decreases vs Default Branch (13)
|
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.
Looks good!
I love how the introduction of the data store led to this refactor 💪
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.
Looks great, very nice improvement!
But I don't see the need for MessageSending
and BaggageSharing
🤔 backward-compatible apis only need to stay in DatadogCoreProtocol
, unless I'm missing something?
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.
LGTM
@maxep I only introduced Alternatively, I can copy & paste the code into |
@ncreated Ah yes, protocol extension was the piece I missed 👍 If we have a ticket to tackle the debt, lets add a note to remove the protocols. Thanks for the clarification! |
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.
👍
instead of core. This is to remove core reference and migrate towards short-term goals from #1744
What and why?
📦 This PR straightens the
FeatureScope
interface, proposing it to become the main (and in most cases the only) dependency for features implementation. Instead of spreading thecore
reference across features and managing it in aweak
manner, the implementation should take a strong dependency onFeatureScope
.There are 3 category of motivations behind this change:
DataStore
can be available inAppHangsObserver
beforeRUMFeature
is initialized.FeatureScope
rather than managing theDatadogCoreProtocol
reference by themselves. As this PR proves, manual management of the core reference is error-prone and may sometimes lead to memory leaks due to capturing strong ref that surpasses core's lifecycle. WithFeatureScope
abstracting theweak
reference we will enforce proper and safe implementation in all features 📈.DatadogCoreProtocol
dependency withFeatureScope
, feature unit tests will be vastly simplified and become properly segregated. Features will no longer be able to make side-effects on core in unit tests, hence tests of one feature expecting side-effects in another feature will have to be moved to the integration-unit target.How?
Changed the feature scope retrieval API:
FeatureScope
interface can be injected all across the feature implementation.FeatureScope
managesweak var core: DatadogCoreProtocol?
reference. It is no longer required for feature implementation to deal with core's ref safety.The
FeatureScope
interface was extended with all capabilities that feature needs to interact with the core. That includes baggage sharing, message sending (over MB) and an access to thetelemetry
endpoint:For backward-compatibility and to avoid large refactoring, all
FeatureScope
capabilities are still present inDatadogCoreProtocol
in this PR:This is done by adding two composition protocols:
MessageSending
andBaggageSharing
inDatadogInternal
for sharing these aspects between core and scope:After all features are migrated to depend on
FeatureScope
the conformance to both protocols will be removed fromDatadogCoreProtocol
.Review checklist
Custom CI job configuration (optional)
tools/