-
-
Notifications
You must be signed in to change notification settings - Fork 188
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
feat(27254): implement new remote-feature-flag-controller #4931
base: main
Are you sure you want to change the base?
Conversation
78af7f4
to
cd93f7a
Compare
No dependency changes detected. Learn more about Socket for GitHub ↗︎ 👍 No dependency changes detected in pull request |
cd93f7a
to
82f7997
Compare
78ca22b
to
a7a3cf1
Compare
0519340
to
fcc71a0
Compare
@metamaskbot publish-preview |
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions.
|
153ebc9
to
0fab160
Compare
977ddbf
to
276357d
Compare
276357d
to
b25f847
Compare
7f893dc
to
a09cd92
Compare
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.
Everything looks good to me, except I have those last questions about the approach to error handling.
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.
Some more suggestions. After that I think we are good here.
packages/remote-feature-flag-controller/src/remote-feature-flag-controller.test.ts
Outdated
Show resolved
Hide resolved
packages/remote-feature-flag-controller/src/remote-feature-flag-controller.test.ts
Outdated
Show resolved
Hide resolved
packages/remote-feature-flag-controller/src/remote-feature-flag-controller.test.ts
Outdated
Show resolved
Hide resolved
...es/remote-feature-flag-controller/src/client-config-api-service/client-config-api-service.ts
Outdated
Show resolved
Hide resolved
...es/remote-feature-flag-controller/src/client-config-api-service/client-config-api-service.ts
Outdated
Show resolved
Hide resolved
...es/remote-feature-flag-controller/src/client-config-api-service/client-config-api-service.ts
Outdated
Show resolved
Hide resolved
...mote-feature-flag-controller/src/client-config-api-service/client-config-api-service.test.ts
Outdated
Show resolved
Hide resolved
...mote-feature-flag-controller/src/client-config-api-service/client-config-api-service.test.ts
Outdated
Show resolved
Hide resolved
...es/remote-feature-flag-controller/src/client-config-api-service/client-config-api-service.ts
Outdated
Show resolved
Hide resolved
...es/remote-feature-flag-controller/src/client-config-api-service/client-config-api-service.ts
Outdated
Show resolved
Hide resolved
...es/remote-feature-flag-controller/src/client-config-api-service/client-config-api-service.ts
Outdated
Show resolved
Hide resolved
...es/remote-feature-flag-controller/src/client-config-api-service/client-config-api-service.ts
Outdated
Show resolved
Hide resolved
f13e7b4
to
6ea8e51
Compare
I've coded a proposed alternative to service error handling, can be found here #4995 |
6ea8e51
to
e5e0b5c
Compare
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.
A few more things, but this is looking pretty good otherwise!
export const incomingTransactionsLogger = createModuleLogger( | ||
projectLogger, | ||
'remote-feature-flag', | ||
); |
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.
Hmm, I see that you copied this pattern from transaction-controller
. It seems that they are putting all of their logger objects in this file. I guess that is okay — there isn't clear guidance on this. But should we at least name this variable and the scope appropriately?
export const incomingTransactionsLogger = createModuleLogger( | |
projectLogger, | |
'remote-feature-flag', | |
); | |
export const remoteFeatureFlagControllerLogger = createModuleLogger( | |
projectLogger, | |
'remote-feature-flag-controller', | |
); |
As an alternative to this, you could put this variable at the top of remote-feature-flag-controller.ts
itself and name it log
, with the scope named after the class
/function
/file
that's being logged. Here is another example to demonstrate this approach:
const log = createModuleLogger(projectLogger, 'etherscan'); |
And so you could have a similar one for remote-feature-flag-controller
like so:
export const log = createModuleLogger(projectLogger, 'RemoteFeatureFlagController');
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.
Your second suggestion has been applied here 440d170
// === STATE === | ||
|
||
export type RemoteFeatureFlagControllerState = { | ||
remoteFeatureFlag: FeatureFlags; |
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.
I see that this was changed recently. Just want to double-check, should this be remoteFeatureFlags
instead of remoteFeatureFlag
, since there could be multiple?
remoteFeatureFlag: FeatureFlags; | |
remoteFeatureFlags: FeatureFlags; |
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.
Done in 8f3c4d5
} catch (error) { | ||
log('Remote feature flag API request failed: %o', error); | ||
reject(error); | ||
throw error; |
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.
It seems that we are returning the promise in the successful case but not the error case. So I see why you added this line. But since we have a promise that we are rejecting, it seems that we ought to be able to use it somehow for all cases...
What if instead of a try
/catch
we add this when we set up the promise above:
const { promise, resolve, reject } = createDeferredPromise<FeatureFlags>({
suppressUnhandledRejection: true,
});
this.#inProgressFlagUpdate = promise;
promise.finally(() => {
this.#inProgressFlagUpdate = undefined;
});
And now we can put return await promise
as the very last thing in this method.
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.
done in 9454a8f
|
||
export const controllerName = 'RemoteFeatureFlagController'; | ||
export const DEFAULT_CACHE_DURATION = 24 * 60 * 60 * 1000; // 1 day | ||
const log = createModuleLogger(projectLogger, 'ClientConfigApiService'); |
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.
Ah, I just noticed this. Perhaps we don't need the additional logger in logger.ts
? Maybe we just need projectLogger
there, and we can correct the scope of this logger:
const log = createModuleLogger(projectLogger, 'ClientConfigApiService'); | |
const log = createModuleLogger(projectLogger, 'RemoteFeatureFlagController'); |
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.
this was addressed in 440d170
* | ||
* @returns A promise that resolves to the current set of feature flags. | ||
*/ | ||
async getRemoteFeatureFlag(): Promise<FeatureFlags> { |
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.
Similar to a previous comment, did we want to use getRemoteFeatureFlags
since we're potentially grabbing multiple? Or is this fine? Just wanted to double-check the API is the way we want it.
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.
Pluralized in 8f3c4d5
…private: true` Co-authored-by: Elliot Winkler <[email protected]>
… name passed to createProjectLogger Co-authored-by: Elliot Winkler <[email protected]>
Explanation
Following the ADR here
Adds a new controller,
remote-feature-flag-controller
that fetches the remote feature flags and provide cache solution for consumers.References
Related to #27254
Changelog
@metamask/remote-feature-flag-controller
ADDED: Initial release
Checklist