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

[Feature Flag] Fix a bug in versions comparison that was disabling all PC 3.2.0+ features on PC 3.10.0+. #341

Merged

Conversation

gmarciani
Copy link
Collaborator

@gmarciani gmarciani commented Jul 19, 2024

Description

Fix a bug in feature flagging that was disabling of all PC 3.2.0+ features on PC 3.10.0+.
In particular, we needed to fix the logic that compares semantic versions.

Before this change 3.10.0 and 3.10.1 were considered lower than 3.2.0 and greater than 3.1.0, so every feature between 3.2.0 and 3.9.0 was disabled.
With this fix, feature flags are correct.

Example: the feature flexible instance type was disablòed for 3.10.0 because of the bug.
With the fix it is now enabled (see screenshot)

Screenshot 2024-07-19 at 17 05 45

Note
There is a package dedicated to semver comparison (semver), but it's not worth it to add an extra dependency for such an easy logic.

How Has This Been Tested?

  1. Unit tests (full suite + one new test covering the buggy case)
  2. Deployed in personal account and verified that feature flagging is working for 3.10.1

References

PR Quality Checklist

  • I added tests to new or existing code
  • I removed hardcoded strings and used react-i18next library (useTranslation hook and/or Trans component), see an example here
  • I made sure no sensitive info gets logged at any time in the codebase (see here) (e.g. no user info or details, no stacktraces, etc.)
  • I made sure that any GitHub issue solved by this PR is correctly linked
  • I checked that infrastructure/update_infrastructure.sh runs without any error
  • I checked that npm run build builds without any error
  • I checked that clusters are listed correctly
  • I checked that a new cluster can be created (config is produced and dry run passes)
  • I checked that login and logout work as expected

In order to increase the likelihood of your contribution being accepted, please make sure you have read both the Contributing Guidelines and the Project Guidelines

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@gmarciani gmarciani force-pushed the wip/mgiacomo/2024080/fix-feature-flag-0719-1 branch 2 times, most recently from d7f8568 to 34c71fc Compare July 19, 2024 15:10
@gmarciani gmarciani changed the title [Feature Flag] Fix a bug in feature flagging that was disabling of all PC 3.2.0+ features on PC 3.10.0+. [Feature Flag] Fix a bug in versions comparison that was disabling all PC 3.2.0+ features on PC 3.10.0+. Jul 19, 2024
Comment on lines 53 to 56
function isVersionGraterOrEqualThan(version: string, other: string): boolean {
return version != null && version.localeCompare(other, undefined, { numeric: true, sensitivity: 'base' }) >= 0
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we use an existing solution for this instead of writing it ourselves? https://www.npmjs.com/package/compare-versions

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

As per note in the PR description: I think it's overkilling to introduce a new dependency for a simple logic.
We should add env dependencies only if strictly required, otherwise we are introducing vector of vulns and consequently ops load.
What do you think?

Copy link
Collaborator

@dreambeyondorange dreambeyondorange Jul 19, 2024

Choose a reason for hiding this comment

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

I generally think its worth it to avoid adding extra logic that can create errors. Especially with something as deceptively complicated as versioning comparisons

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

An interesting reading about this: https://semaphoreci.com/blog/project-dependencies

In our case the simplicity of our project makes the article sound a bit overkilling, but it is still an interesting best practice reading.

frontend/src/feature-flags/featureFlagsProvider.ts Outdated Show resolved Hide resolved
@gmarciani gmarciani force-pushed the wip/mgiacomo/2024080/fix-feature-flag-0719-1 branch from 34c71fc to 44fc6ae Compare July 19, 2024 15:27
@gmarciani gmarciani merged commit d6def93 into aws:main Jul 22, 2024
2 checks passed
@gmarciani gmarciani deleted the wip/mgiacomo/2024080/fix-feature-flag-0719-1 branch July 22, 2024 08:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants