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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 33 additions & 30 deletions frontend/src/feature-flags/__tests__/FeatureFlagsProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,37 +155,40 @@ describe('given a feature flags provider and a list of rules', () => {
})
})

describe('when the version is at or above 3.9.0', () => {
it('should return the list of available features', async () => {
const features = await subject('3.9.0', region)
expect(features).toEqual<AvailableFeature[]>([
'multiuser_cluster',
'fsx_ontap',
'fsx_openzsf',
'lustre_persistent2',
'memory_based_scheduling',
'slurm_queue_update_strategy',
'ebs_deletion_policy',
'cost_monitoring',
'slurm_accounting',
'queues_multiple_instance_types',
'dynamic_fs_mount',
'efs_deletion_policy',
'lustre_deletion_policy',
'imds_support',
'multi_az',
'on_node_updated',
'rhel8',
'new_resources_limits',
'ubuntu2204',
'login_nodes',
'amazon_file_cache',
'job_exclusive_allocation',
'memory_based_scheduling_with_multiple_instance_types',
'rhel9',
])
for (const version of ["3.9.0", "3.10.0"]) {
describe(`when the version is ${version}`, () => {
it('should return the list of available features', async () => {
const features = await subject(version, region)
expect(features).toEqual<AvailableFeature[]>([
'multiuser_cluster',
'fsx_ontap',
'fsx_openzsf',
'lustre_persistent2',
'memory_based_scheduling',
'slurm_queue_update_strategy',
'ebs_deletion_policy',
'cost_monitoring',
'slurm_accounting',
'queues_multiple_instance_types',
'dynamic_fs_mount',
'efs_deletion_policy',
'lustre_deletion_policy',
'imds_support',
'multi_az',
'on_node_updated',
'rhel8',
'new_resources_limits',
'ubuntu2204',
'login_nodes',
'amazon_file_cache',
'job_exclusive_allocation',
'memory_based_scheduling_with_multiple_instance_types',
'rhel9',
])
})
})
})
}


describe('when an additional feature has been enabled through the browser session storage', () => {
beforeEach(() => {
Expand Down
8 changes: 6 additions & 2 deletions frontend/src/feature-flags/featureFlagsProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,16 @@ const featureToDeperecatedVersionMap: Partial<
ubuntu1804: '3.7.0',
}

function isVersionGreaterOrEqualThan(version: string, other: string): boolean {
return version != null && version.localeCompare(other, undefined, { numeric: true, sensitivity: 'base' }) >= 0
}

function isNotDeprecated(
feature: AvailableFeature,
currentVersion: string,
): boolean {
if (feature in featureToDeperecatedVersionMap) {
if (currentVersion >= featureToDeperecatedVersionMap[feature]!) {
if (isVersionGreaterOrEqualThan(currentVersion, featureToDeperecatedVersionMap[feature]!)) {
return false
}
}
Expand Down Expand Up @@ -86,7 +90,7 @@ function composeFlagsListByVersion(currentVersion: string): AvailableFeature[] {
let features: Set<AvailableFeature> = new Set([])

for (let version in versionToFeaturesMap) {
if (currentVersion >= version) {
if (isVersionGreaterOrEqualThan(currentVersion, version)) {
features = new Set([...features, ...versionToFeaturesMap[version]])
}
}
Expand Down
7 changes: 5 additions & 2 deletions frontend/src/feature-flags/useFeatureFlag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ export function isFeatureEnabled(
feature: AvailableFeature,
): boolean {
const features = new Set(featureFlagsProvider(version, region))

return features.has(feature)
const enabled = features.has(feature)
if (!enabled) {
console.log(`FEATURE FLAG: Feature ${feature} is disabled`)
}
return enabled
}
Loading