-
Notifications
You must be signed in to change notification settings - Fork 31
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: retrieve and store snykCodeInlineIgnore feature flag [IDE-440][IDE-441] #492
feat: retrieve and store snykCodeInlineIgnore feature flag [IDE-440][IDE-441] #492
Conversation
|
||
async fetchFeatureFlagWithoutErrorHandling(flagName: string): Promise<boolean> { | ||
const ffStatus = await this.commandExecutor.executeCommand<FeatureFlagStatus>(SNYK_FEATURE_FLAG_COMMAND, flagName); | ||
return ffStatus?.ok ?? false; | ||
} |
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.
What if we provide a fallback values instead so we don't need this extra function?
async fetchFeatureFlag(flagName: string, fallbackValue = false): Promise<boolean> {
try {
const ffStatus = await this.commandExecutor.executeCommand<FeatureFlagStatus>(
SNYK_FEATURE_FLAG_COMMAND,
flagName,
);
return ffStatus?.ok ?? false;
} catch (error) {
console.warn(`Failed to fetch feature flag ${flagName}: ${error}`);
return fallbackValue;
}
}
The we change the setupFeatureFlags
to handle multiple asynchronous operations concurrently with allSettled
. I'll add and example in that bit, one sec 🙏
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.
Sounds good!
src/snyk/base/modules/snykLib.ts
Outdated
async setupFeatureFlags(): Promise<void> { | ||
const isEnabled = await this.featureFlagService.fetchFeatureFlag(FEATURE_FLAGS.consistentIgnores); | ||
let isEnabled = await this.featureFlagService.fetchFeatureFlag(FEATURE_FLAGS.consistentIgnores); | ||
configuration.setFeatureFlag(FEATURE_FLAGS.consistentIgnores, isEnabled); | ||
|
||
try { | ||
isEnabled = await this.featureFlagService.fetchFeatureFlagWithoutErrorHandling( | ||
FEATURE_FLAGS.snykCodeInlineIgnore, | ||
); | ||
} catch (err) { | ||
// if we cannot get the feature flag, we default to true for | ||
// minimal disruption of the existing customer feature | ||
isEnabled = true; | ||
} | ||
configuration.setFeatureFlag(FEATURE_FLAGS.snykCodeInlineIgnore, isEnabled); | ||
} |
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 just saw that if we provide a fallback to fetchFeatureFlag
as commented before and we don't mind concurrency, instead of allSettle we go:
async setupFeatureFlags(): Promise<void> {
const flags = [
{ flag: FEATURE_FLAGS.consistentIgnores, fallback: false },
{ flag: FEATURE_FLAGS.snykCodeInlineIgnore, fallback: true },
];
for (const { flag, fallback } of flags) {
const isEnabled = await this.featureFlagService.fetchFeatureFlag(flag, fallback);
configuration.setFeatureFlag(flag, isEnabled);
}
}
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 tried with allSettle but the code gets a bit more complicated because we need to loop the array of results and assert the fulfilled
value
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.
concurrency should actually be the default here - feel free to push your suggestion :)
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.
OMW :)
Description
Use the new FeatureFlagService in Visual Studio Code to get snykCodeInlineIgnore FF.
Checklist
Screenshots / GIFs
Visuals that may help the reviewer. Please add screenshots for any UI change. GIFs are most welcome!