Skip to content

Commit

Permalink
[Feature Flag] Fix a bug in versions comparison that was disabling al…
Browse files Browse the repository at this point in the history
…l PC 3.2.0+ features on PC 3.10.0+.
  • Loading branch information
gmarciani committed Jul 19, 2024
1 parent c77b415 commit 34c71fc
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 34 deletions.
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 isVersionGraterOrEqualThan(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 (isVersionGraterOrEqualThan(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 (isVersionGraterOrEqualThan(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
}

0 comments on commit 34c71fc

Please sign in to comment.