Skip to content

Commit 34c71fc

Browse files
committed
[Feature Flag] Fix a bug in versions comparison that was disabling all PC 3.2.0+ features on PC 3.10.0+.
1 parent c77b415 commit 34c71fc

File tree

3 files changed

+44
-34
lines changed

3 files changed

+44
-34
lines changed

frontend/src/feature-flags/__tests__/FeatureFlagsProvider.test.ts

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -155,37 +155,40 @@ describe('given a feature flags provider and a list of rules', () => {
155155
})
156156
})
157157

158-
describe('when the version is at or above 3.9.0', () => {
159-
it('should return the list of available features', async () => {
160-
const features = await subject('3.9.0', region)
161-
expect(features).toEqual<AvailableFeature[]>([
162-
'multiuser_cluster',
163-
'fsx_ontap',
164-
'fsx_openzsf',
165-
'lustre_persistent2',
166-
'memory_based_scheduling',
167-
'slurm_queue_update_strategy',
168-
'ebs_deletion_policy',
169-
'cost_monitoring',
170-
'slurm_accounting',
171-
'queues_multiple_instance_types',
172-
'dynamic_fs_mount',
173-
'efs_deletion_policy',
174-
'lustre_deletion_policy',
175-
'imds_support',
176-
'multi_az',
177-
'on_node_updated',
178-
'rhel8',
179-
'new_resources_limits',
180-
'ubuntu2204',
181-
'login_nodes',
182-
'amazon_file_cache',
183-
'job_exclusive_allocation',
184-
'memory_based_scheduling_with_multiple_instance_types',
185-
'rhel9',
186-
])
158+
for (const version of ["3.9.0", "3.10.0"]) {
159+
describe(`when the version is ${version}`, () => {
160+
it('should return the list of available features', async () => {
161+
const features = await subject(version, region)
162+
expect(features).toEqual<AvailableFeature[]>([
163+
'multiuser_cluster',
164+
'fsx_ontap',
165+
'fsx_openzsf',
166+
'lustre_persistent2',
167+
'memory_based_scheduling',
168+
'slurm_queue_update_strategy',
169+
'ebs_deletion_policy',
170+
'cost_monitoring',
171+
'slurm_accounting',
172+
'queues_multiple_instance_types',
173+
'dynamic_fs_mount',
174+
'efs_deletion_policy',
175+
'lustre_deletion_policy',
176+
'imds_support',
177+
'multi_az',
178+
'on_node_updated',
179+
'rhel8',
180+
'new_resources_limits',
181+
'ubuntu2204',
182+
'login_nodes',
183+
'amazon_file_cache',
184+
'job_exclusive_allocation',
185+
'memory_based_scheduling_with_multiple_instance_types',
186+
'rhel9',
187+
])
188+
})
187189
})
188-
})
190+
}
191+
189192

190193
describe('when an additional feature has been enabled through the browser session storage', () => {
191194
beforeEach(() => {

frontend/src/feature-flags/featureFlagsProvider.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,16 @@ const featureToDeperecatedVersionMap: Partial<
5050
ubuntu1804: '3.7.0',
5151
}
5252

53+
function isVersionGraterOrEqualThan(version: string, other: string): boolean {
54+
return version != null && version.localeCompare(other, undefined, { numeric: true, sensitivity: 'base' }) >= 0
55+
}
56+
5357
function isNotDeprecated(
5458
feature: AvailableFeature,
5559
currentVersion: string,
5660
): boolean {
5761
if (feature in featureToDeperecatedVersionMap) {
58-
if (currentVersion >= featureToDeperecatedVersionMap[feature]!) {
62+
if (isVersionGraterOrEqualThan(currentVersion, featureToDeperecatedVersionMap[feature]!)) {
5963
return false
6064
}
6165
}
@@ -86,7 +90,7 @@ function composeFlagsListByVersion(currentVersion: string): AvailableFeature[] {
8690
let features: Set<AvailableFeature> = new Set([])
8791

8892
for (let version in versionToFeaturesMap) {
89-
if (currentVersion >= version) {
93+
if (isVersionGraterOrEqualThan(currentVersion, version)) {
9094
features = new Set([...features, ...versionToFeaturesMap[version]])
9195
}
9296
}

frontend/src/feature-flags/useFeatureFlag.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ export function isFeatureEnabled(
2424
feature: AvailableFeature,
2525
): boolean {
2626
const features = new Set(featureFlagsProvider(version, region))
27-
28-
return features.has(feature)
27+
const enabled = features.has(feature)
28+
if (!enabled) {
29+
console.log(`FEATURE FLAG: Feature ${feature} is disabled`)
30+
}
31+
return enabled
2932
}

0 commit comments

Comments
 (0)