Skip to content
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

Merged

Conversation

bastiandoetsch
Copy link
Contributor

Description

Use the new FeatureFlagService in Visual Studio Code to get snykCodeInlineIgnore FF.

Checklist

  • Tests added and all succeed
  • Linted
  • CHANGELOG.md updated
  • README.md updated, if user-facing

Screenshots / GIFs

Visuals that may help the reviewer. Please add screenshots for any UI change. GIFs are most welcome!

@bastiandoetsch bastiandoetsch requested a review from a team as a code owner July 19, 2024 06:34
@bastiandoetsch bastiandoetsch changed the title feat: retrieve and store snykCodeInlineIgnore feature flag [IDE-440] feat: retrieve and store snykCodeInlineIgnore feature flag [IDE-440][IDE-441] Jul 19, 2024
Comment on lines 20 to 24

async fetchFeatureFlagWithoutErrorHandling(flagName: string): Promise<boolean> {
const ffStatus = await this.commandExecutor.executeCommand<FeatureFlagStatus>(SNYK_FEATURE_FLAG_COMMAND, flagName);
return ffStatus?.ok ?? false;
}
Copy link
Contributor

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 🙏

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good!

Comment on lines 53 to 67
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);
}
Copy link
Contributor

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);
    }
  }

Copy link
Contributor

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

Copy link
Contributor Author

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 :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OMW :)

@cat2608 cat2608 merged commit a81fded into main Jul 19, 2024
14 checks passed
@cat2608 cat2608 deleted the feat/IDE-440_retrieve-feature-flag-for-snykCodeInlineIgnore branch July 19, 2024 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants