-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Create a new feature-flag-controller #27254
Comments
It should be I have two questions / suggestions:
|
hey @joaoloureirop thanks for reviewing,
Yes indeed, the one is the expected path
If API is down, the controller actually returns a cache value from previous fetch; further more, if there's no cache available in the storage, an empty object is returned, and we can have customization in extension of mobile to decide which is the default value we want to return.
definitely ! The code snippet above will act as an example for some critical logics, when implementing, we have some best practice to follow, include strict types |
Thanks for clarifying @DDDDDanica !
Ah yes, it is up to the client (mobile, extension) to handle the empty cache return. |
Thanks for this technical refinement of feature flags. Here are some comments:
=>
=> The default cache duration should be 1 hour rather than 30 days because if there’s a bug in a feature that requires disabling, we want it to be disabled quickly. |
Hey @gauthierpetetin thanks for reviewing:
Good catch, gonna remove this feature
Updated to daily update, to be decided until we get an answer of capacity of config api |
@joaoloureirop thanks for pointing out the
|
Sorry, I wasn't very clear about the question about failed fetches. I meant if the controller would handle failed requests with a retry logic. |
@joaoloureirop That's a very valid point, I will refer the retry system applied to codify service here as
|
## Explanation Following the ADR [here](https://github.com/MetaMask/decisions/blob/1312f2326adeee7ebef1b7cedf98549940fa690d/decisions/wallet-platform/0001-remote-rollout-feature-flags.md) Adds a new controller, `remote-feature-flag-controller` that fetches the remote feature flags and provide cache solution for consumers. ## References Related to [#27254](MetaMask/metamask-extension#27254) ## Changelog <!-- If you're making any consumer-facing changes, list those changes here as if you were updating a changelog, using the template below as a guide. (CATEGORY is one of BREAKING, ADDED, CHANGED, DEPRECATED, REMOVED, or FIXED. For security-related issues, follow the Security Advisory process.) Please take care to name the exact pieces of the API you've added or changed (e.g. types, interfaces, functions, or methods). If there are any breaking changes, make sure to offer a solution for consumers to follow once they upgrade to the changes. Finally, if you're only making changes to development scripts or tests, you may replace the template below with "None". --> ### `@metamask/remote-feature-flag-controller` ADDED: Initial release ## Checklist - [ ] I've updated the test suite for new or updated code as appropriate - [ ] I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate - [ ] I've highlighted breaking changes using the "BREAKING" category above as appropriate - [ ] I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes --------- Co-authored-by: Dan J Miller <danjm.com@gmail.com> Co-authored-by: Elliot Winkler <elliot.winkler@gmail.com>
<!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** - Consume feature-flag-controller built in #27254. - And When Basic Functionality toggle is OFF, feature flag request should not be made, not call getFeatureFlags, which can be aligned with MetaMask/mobile-planning#1975 <!-- Write a short description of the changes included in this pull request, also include relevant motivation and context. Have in mind the following questions: 1. What is the reason for the change? 2. What is the improvement/solution? --> [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/28684?quickstart=1) ## **Related issues** Fixes: #27256 ## **Manual testing steps** 1. Load the extension 2. Option 1: input `chrome.storage.local.get(console.log)` in dev tools console, and you'll find in `data` => `RemoteFeatureFlagController` => contains 2 dataset, `cacheTimestamp` and `remoteFeatureFlags` with value 3. Option 2: go to settings => advanced, and click `download stage logs` button, you'll find `remoteFeatureFlags` with cached value in your state. 4. Option 3: Settings => about page, if you open console in dev tools, there's a log after `Feature flag fetched successfully`, which will be removed after we implement 1st feature flag in production ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> ### **After** <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [ ] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md). - [ ] I've completed the PR template to the best of my ability - [ ] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. --------- Co-authored-by: Mark Stacey <markjstacey@gmail.com> Co-authored-by: MetaMask Bot <metamaskbot@users.noreply.github.com> Co-authored-by: Dan J Miller <danjm.com@gmail.com>
<!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** - Consume feature-flag-controller built in #27254. - And When Basic Functionality toggle is OFF, feature flag request should not be made, not call getFeatureFlags, which can be aligned with MetaMask/mobile-planning#1975 <!-- Write a short description of the changes included in this pull request, also include relevant motivation and context. Have in mind the following questions: 1. What is the reason for the change? 2. What is the improvement/solution? --> [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/28684?quickstart=1) ## **Related issues** Fixes: #27256 ## **Manual testing steps** 1. Load the extension 2. Option 1: input `chrome.storage.local.get(console.log)` in dev tools console, and you'll find in `data` => `RemoteFeatureFlagController` => contains 2 dataset, `cacheTimestamp` and `remoteFeatureFlags` with value 3. Option 2: go to settings => advanced, and click `download stage logs` button, you'll find `remoteFeatureFlags` with cached value in your state. 4. Option 3: Settings => about page, if you open console in dev tools, there's a log after `Feature flag fetched successfully`, which will be removed after we implement 1st feature flag in production ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> ### **After** <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [ ] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md). - [ ] I've completed the PR template to the best of my ability - [ ] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. --------- Co-authored-by: Mark Stacey <markjstacey@gmail.com> Co-authored-by: MetaMask Bot <metamaskbot@users.noreply.github.com> Co-authored-by: Dan J Miller <danjm.com@gmail.com>
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
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. 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 30 days)Stakeholder review needed before the work gets merged
References
No response
The text was updated successfully, but these errors were encountered: