Skip to content

chore: Refactor FlagsProvider and FlagsClient into one#2899

Merged
dd-mergequeue[bot] merged 17 commits into
feature/feature-flaggingfrom
typo/FFL-1116-swap-classname-provider-client-client-client-manager-or-eliminate
Oct 7, 2025
Merged

chore: Refactor FlagsProvider and FlagsClient into one#2899
dd-mergequeue[bot] merged 17 commits into
feature/feature-flaggingfrom
typo/FFL-1116-swap-classname-provider-client-client-client-manager-or-eliminate

Conversation

@typotter

@typotter typotter commented Sep 25, 2025

Copy link
Copy Markdown
Contributor

Flags Feature - FlagsClient

Feature Flagging mobile SDK spike
stacked on #2896
FFL-1116

What does this PR do?

Refactors the WIP dd-sdk-android-flags package to consolidate FlagsProvider functionality into FlagsClient using an interface + companion object pattern. This provides cleaner static access (FlagsClient.instance()) while maintaining instance-based flag operations, aligning with mobile-api-spec.md requirements.

Motivation

The existing dual-class pattern (FlagsClient object + FlagsProvider interface) was confusing and didn't align with mobile-api-spec.md. The spec requires static access for client instances but instance methods for flag operations. This refactoring simplifies the API to a single FlagsClient class that provides both patterns cleanly and adheres to the agreed upon spec for mobile flags SDKs

Additional Notes

Out of scope

  • Creating/getting clients by name is tracked in FFL-1118

API Target

val client = FlagsClient.instance()
client.resolveBooleanValue("flag", false)

Key Changes Made

  1. Consolidated Classes: Eliminated FlagsProvider separate class
  2. Enhanced Interface: Added companion object with static registry to FlagsClient
  3. Simplified API: Single FlagsClient.instance() entry point
  4. Updated Tests: Rewrote tests to use interface + companion pattern
  5. Documentation: Added comprehensive KDoc for all methods and companion object

Review checklist (to be filled by reviewers)

  • Feature or bugfix MUST have appropriate tests (unit, integration, e2e)
  • Make sure you discussed the feature or bugfix with the maintaining team in an Issue
  • Make sure each commit and the PR mention the Issue number (cf the CONTRIBUTING doc)

@typotter typotter changed the title Typo/ffl 1116 swap classname provider client client client manager or eliminate chore: Refactor FlagsProvider and FlagsClient into one Sep 25, 2025
@typotter
typotter marked this pull request as ready for review September 25, 2025 21:45
@typotter
typotter requested review from a team as code owners September 25, 2025 21:45
@codecov-commenter

codecov-commenter commented Sep 25, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 79.48718% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.59%. Comparing base (f2fed1b) to head (b9406f1).
⚠️ Report is 305 commits behind head on feature/feature-flagging.

Files with missing lines Patch % Lines
.../datadog/android/flags/featureflags/FlagsClient.kt 71.43% 5 Missing and 3 partials ⚠️
.../flags/featureflags/internal/DatadogFlagsClient.kt 82.86% 1 Missing and 5 partials ⚠️
...src/main/kotlin/com/datadog/android/flags/Flags.kt 87.50% 1 Missing ⚠️
...oid/flags/featureflags/internal/NoOpFlagsClient.kt 85.71% 1 Missing ⚠️
Additional details and impacted files
@@                     Coverage Diff                      @@
##           feature/feature-flagging    #2899      +/-   ##
============================================================
- Coverage                     70.75%   70.59%   -0.16%     
============================================================
  Files                           826      826              
  Lines                         30078    30087       +9     
  Branches                       5009     5124     +115     
============================================================
- Hits                          21279    21238      -41     
- Misses                         7408     7410       +2     
- Partials                       1391     1439      +48     
Files with missing lines Coverage Δ
...ureflags/internal/evaluation/EvaluationsManager.kt 89.29% <ø> (ø)
...src/main/kotlin/com/datadog/android/flags/Flags.kt 88.68% <87.50%> (-1.12%) ⬇️
...oid/flags/featureflags/internal/NoOpFlagsClient.kt 85.71% <85.71%> (ø)
.../flags/featureflags/internal/DatadogFlagsClient.kt 82.86% <82.86%> (ø)
.../datadog/android/flags/featureflags/FlagsClient.kt 71.43% <71.43%> (-2.76%) ⬇️

... and 94 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread features/dd-sdk-android-flags/api/apiSurface Outdated
* in production code. It delegates to [clear] to remove all client registrations.
*/
@Suppress("unused")
private fun reset() {

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.

is it used anywhere? seems like redundant method if it delegates to another one anyway.

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.

good catch; no longer needed

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.

still there, can be removed

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.

done

@typotter typotter left a comment

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.

thanks for the review. PTAL

* in production code. It delegates to [clear] to remove all client registrations.
*/
@Suppress("unused")
private fun reset() {

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.

good catch; no longer needed

Comment thread features/dd-sdk-android-flags/api/apiSurface Outdated
@typotter
typotter requested a review from 0xnm October 1, 2025 20:27
0xnm
0xnm previously approved these changes Oct 3, 2025
@typotter

typotter commented Oct 3, 2025

Copy link
Copy Markdown
Contributor Author

/merge

@dd-devflow-routing-codex

dd-devflow-routing-codex Bot commented Oct 3, 2025

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2025-10-03 17:30:12 UTC ℹ️ Start processing command /merge


2025-10-03 17:30:17 UTC ℹ️ MergeQueue: pull request added to the queue

The expected merge time in typo/fixes is approximately 0s (p90).


2025-10-03 17:39:09 UTC ⚠️ MergeQueue: This merge request build was cancelled

[email protected] cancelled this merge request build

@dd-devflow-routing-codex

dd-devflow-routing-codex Bot commented Oct 3, 2025

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2025-10-03 18:06:37 UTC ℹ️ Start processing command /merge


2025-10-03 18:06:44 UTC ℹ️ MergeQueue: waiting for PR to be ready

This merge request is not mergeable yet, because of pending checks/missing approvals. It will be added to the queue as soon as checks pass and/or get approvals.
Note: if you pushed new commits since the last approval, you may need additional approval.
You can remove it from the waiting list with /remove command.


2025-10-03 19:17:41 UTC ⚠️ MergeQueue: This merge request was unqueued

[email protected] unqueued this merge request

…name-provider-client-client-client-manager-or-eliminate
@typotter

typotter commented Oct 3, 2025

Copy link
Copy Markdown
Contributor Author

/remove

@dd-devflow-routing-codex

dd-devflow-routing-codex Bot commented Oct 3, 2025

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2025-10-03 19:17:36 UTC ℹ️ Start processing command /remove


2025-10-03 19:17:39 UTC ℹ️ Devflow: /remove

jonathanmos
jonathanmos previously approved these changes Oct 5, 2025

@jonathanmos jonathanmos 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 on the whole - I left some minor comments

{ "Missing required configuration parameters: $missingParams" }
)

return null

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.

Do we prefer null here or a NoOpFlagsClient? Also, after this we could probably remove the TODO on line 82

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.

null here is fine; we are dropping this create-on-enable routine anyway and will guarantee a non-null Client from the create/get methods

* Must contain a valid targeting key; invalid contexts are logged and ignored.
*/
override fun setContext(context: EvaluationContext) {
// Validate targeting key is not blank

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.

nit: redundant comment

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.

fixed

0xnm
0xnm previously approved these changes Oct 6, 2025
Comment thread features/dd-sdk-android-flags/src/main/kotlin/com/datadog/android/flags/Flags.kt Outdated
* in production code. It delegates to [clear] to remove all client registrations.
*/
@Suppress("unused")
private fun reset() {

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.

still there, can be removed

*/
override fun resolveBooleanValue(flagKey: String, defaultValue: Boolean): Boolean {
val precomputedFlag = flagsRepository.getPrecomputedFlag(flagKey)
return precomputedFlag?.variationValue?.toBooleanStrictOrNull() ?: defaultValue

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.

do we want to use toBooleanStrictOrNull here or just toBooleanOrNull. The doc for the former is here https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.text/to-boolean-strict-or-null.html.

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.

hm. I think toBooleanOrNull makes more sense here, thanks.
Jonathan makes this change in #2895

Co-authored-by: Nikita Ogorodnikov <[email protected]>
Co-authored-by: Jonathan Moskovich <[email protected]>
@typotter
typotter dismissed stale reviews from 0xnm and jonathanmos via 666fbad October 6, 2025 17:31
@typotter
typotter requested review from 0xnm and jonathanmos October 6, 2025 17:57
@typotter

typotter commented Oct 7, 2025

Copy link
Copy Markdown
Contributor Author

/merge

@dd-devflow-routing-codex

dd-devflow-routing-codex Bot commented Oct 7, 2025

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2025-10-07 16:24:05 UTC ℹ️ Start processing command /merge


2025-10-07 16:24:09 UTC ℹ️ MergeQueue: pull request added to the queue

The expected merge time in feature/feature-flagging is approximately 1h (p90).


2025-10-07 17:27:10 UTC ℹ️ MergeQueue: This merge request was merged

@dd-mergequeue
dd-mergequeue Bot merged commit b641740 into feature/feature-flagging Oct 7, 2025
26 checks passed
@dd-mergequeue
dd-mergequeue Bot deleted the typo/FFL-1116-swap-classname-provider-client-client-client-manager-or-eliminate branch October 7, 2025 17:27
This was referenced Nov 4, 2025
@0xnm
0xnm restored the typo/FFL-1116-swap-classname-provider-client-client-client-manager-or-eliminate branch March 26, 2026 10:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants