Create a new feature-flag-controller #27254
Labels
external-contributor
INVALID-ISSUE-TEMPLATE
Issue's body doesn't match any issue template.
team-extension-platform
Objectives
The FeatureFlagController will be a specialized extension of
BaseController
with state management, caching, and feature flag fetching capabilities. It will useClientConfigApi
to retrieve feature flags from LaunchDarkly, applying caching to optimize API usage and ensuring user privacy through configurable settings.High-Level Architecture
The core controller will:
@metamask/feature-flag-controller
, detailed configuration forpackage.json
can refer topackages/address-book-controller/package.json
ClientConfigApi
profileId
to determine unique user-based flag values.Provide a fallback mechanism, either using cached values or default values in case of API unavailability, or a request is made during the updating, or no cache exists.
Implementation Details
Controller guideline:
https://github.com/MetaMask/core/blob/main/docs/writing-controllers.md
Best practice:
https://github.com/MetaMask/core/tree/0fc0396cbcaae95ea5c8bf3f92fef18adc496283/examples/example-controllers
Service guidance:
https://github.com/MetaMask/decisions/blob/main/decisions/core/0002-external-api-integrations.md
1. Define Initial State and Metadata
Set up the initial state and metadata for the
FeatureFlagController
to hold feature flags and cache details. This state will persist between sessions for reliability in offline scenarios.2. Implement Caching Mechanism
To reduce API calls, we’ll implement a cache with a validity period. Use
cacheTimestamp
to track when the last fetch occurred, and check this before fetching again. Also allow the caller to specify how frequently the API should be called by adding an optionalfetchInterval
parameter.3. Fetch Feature Flags from API in a service
The
feature-flag-service
will fetch feature flags fromClientConfigApi
. It should handle cases with and without aprofileId
for user-specific flags. Implement error handling to manage API failures and cache fallback if needed.and use in controller:
4. Apply Fallback Logic
In case of an API failure or offline status, fallback to either cached values (if available) or default hardcoded values.
**5. Handle Simultaneous Requests with In-Progress Tracking **
The feature-flag-controller will use in-progress flags (e.g., refer to #inProgressHotlistUpdate in
phishing-controller
) to ensure only one update of each type occurs at any time, waiting for completion if an update is already ongoing.This prevents redundant requests and allows the controller to be more resilient to concurrent updates, particularly helpful in a multithreaded or asynchronous environment.
6. Allow Manual Refresh on Demand
Add a
refreshFeatureFlags
method to allow immediate refreshing of flags. This is useful for specific actions that require the latest data immediately, bypassing the cache.7. Extend with Messaging and Registering Handlers
Set up message handlers to manage interactions and handle actions (e.g., requesting flag updates).
Scenario
No response
Design
No response
Technical Details
No response
Threat Modeling Framework
No response
Acceptance Criteria
feature-controller
is added to core and published to be used, following the recommended pattern: https://github.com/MetaMask/core/tree/0fc0396cbcaae95ea5c8bf3f92fef18adc496283/examples/example-controllersclientConfigAPI
based on client, distribution, environment and profileId (optional), and fetchInterval (optional, default 1 day)Stakeholder review needed before the work gets merged
References
No response
The text was updated successfully, but these errors were encountered: