Skip to content

Commit

Permalink
chore: remove detectSegmentUsageInChangeRequests flag (#6080)
Browse files Browse the repository at this point in the history
What it says on the tin. Removes all uses of the
detectSegmentUsageInChangeRequests flag.
  • Loading branch information
thomasheartman committed Jan 31, 2024
1 parent d7eb950 commit 73322f1
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 49 deletions.
1 change: 0 additions & 1 deletion src/lib/__snapshots__/create-config.test.ts.snap
Expand Up @@ -82,7 +82,6 @@ exports[`should create default config 1`] = `
"createdByUserIdDataMigration": false,
"customRootRolesKillSwitch": false,
"demo": false,
"detectSegmentUsageInChangeRequests": false,
"disableBulkToggle": false,
"disableMetrics": false,
"disableNotifications": false,
Expand Down
4 changes: 1 addition & 3 deletions src/lib/db/segment-store.test.ts
Expand Up @@ -11,9 +11,7 @@ let segmentStore: ISegmentStore;
beforeAll(async () => {
db = await dbInit('segment_store_serial', getLogger, {
experimental: {
flags: {
detectSegmentUsageInChangeRequests: true,
},
flags: {},
},
});
stores = db.stores;
Expand Down
5 changes: 1 addition & 4 deletions src/lib/db/segment-store.ts
Expand Up @@ -115,10 +115,7 @@ export default class SegmentStore implements ISegmentStore {
async getAll(
includeChangeRequestUsageData: boolean = false,
): Promise<ISegment[]> {
if (
includeChangeRequestUsageData &&
this.flagResolver.isEnabled('detectSegmentUsageInChangeRequests')
) {
if (includeChangeRequestUsageData) {
const pendingCRs = await this.db
.select('id', 'project')
.from('change_requests')
Expand Down
40 changes: 16 additions & 24 deletions src/lib/features/segment/segment-controller.ts
Expand Up @@ -362,24 +362,21 @@ export class SegmentsController extends Controller {
environment: strategy.environment,
}));

if (this.flagResolver.isEnabled('detectSegmentUsageInChangeRequests')) {
const changeRequestStrategies =
strategies.changeRequestStrategies.map((strategy) => ({
...('id' in strategy ? { id: strategy.id } : {}),
projectId: strategy.projectId,
featureName: strategy.featureName,
strategyName: strategy.strategyName,
environment: strategy.environment,
changeRequest: strategy.changeRequest,
}));

res.json({
strategies: segmentStrategies,
changeRequestStrategies,
});
} else {
res.json({ strategies: segmentStrategies });
}
const changeRequestStrategies = strategies.changeRequestStrategies.map(
(strategy) => ({
...('id' in strategy ? { id: strategy.id } : {}),
projectId: strategy.projectId,
featureName: strategy.featureName,
strategyName: strategy.strategyName,
environment: strategy.environment,
changeRequest: strategy.changeRequest,
}),
);

res.json({
strategies: segmentStrategies,
changeRequestStrategies,
});
}

async removeSegment(
Expand All @@ -389,12 +386,7 @@ export class SegmentsController extends Controller {
const id = Number(req.params.id);

let segmentIsInUse = false;
if (this.flagResolver.isEnabled('detectSegmentUsageInChangeRequests')) {
segmentIsInUse = await this.segmentService.isInUse(id);
} else {
const strategies = await this.segmentService.getAllStrategies(id);
segmentIsInUse = strategies.strategies.length > 0;
}
segmentIsInUse = await this.segmentService.isInUse(id);

if (segmentIsInUse) {
res.status(409).send();
Expand Down
5 changes: 1 addition & 4 deletions src/lib/services/segment-service.ts
Expand Up @@ -115,10 +115,7 @@ export class SegmentService implements ISegmentService {
const strategies =
await this.featureStrategiesStore.getStrategiesBySegment(id);

if (
this.flagResolver.isEnabled('detectSegmentUsageInChangeRequests') &&
this.config.isEnterprise
) {
if (this.config.isEnterprise) {
const changeRequestStrategies =
await this.changeRequestSegmentUsageReadModel.getStrategiesUsedInActiveChangeRequests(
id,
Expand Down
6 changes: 0 additions & 6 deletions src/lib/types/experimental.ts
Expand Up @@ -28,7 +28,6 @@ export type IFlagKey =
| 'customRootRolesKillSwitch'
| 'disableMetrics'
| 'scheduledConfigurationChanges'
| 'detectSegmentUsageInChangeRequests'
| 'stripClientHeadersOn304'
| 'newStrategyConfiguration'
| 'stripHeadersOnAPI'
Expand Down Expand Up @@ -133,11 +132,6 @@ const flags: IFlags = {
process.env.UNLEASH_EXPERIMENTAL_SCHEDULED_CONFIGURATION_CHANGES,
false,
),
detectSegmentUsageInChangeRequests: parseEnvVarBoolean(
process.env
.UNLEASH_EXPERIMENTAL_DETECT_SEGMENT_USAGE_IN_CHANGE_REQUESTS,
false,
),
stripClientHeadersOn304: parseEnvVarBoolean(
process.env
.UNLEASH_EXPERIMENTAL_DETECT_SEGMENT_USAGE_IN_CHANGE_REQUESTS,
Expand Down
5 changes: 1 addition & 4 deletions src/test/e2e/api/admin/segment.e2e.test.ts
Expand Up @@ -106,7 +106,6 @@ beforeAll(async () => {
experimental: {
flags: {
anonymiseEventLog: true,
detectSegmentUsageInChangeRequests: true,
},
},
};
Expand Down Expand Up @@ -588,9 +587,7 @@ describe('detect strategy usage in change requests', () => {
ui: { environment: 'Enterprise' },
isEnterprise: true,
experimental: {
flags: {
detectSegmentUsageInChangeRequests: true,
},
flags: {},
},
},
db.rawDatabase,
Expand Down
4 changes: 1 addition & 3 deletions src/test/e2e/api/client/segment.e2e.test.ts
Expand Up @@ -188,9 +188,7 @@ beforeAll(async () => {
db.stores,
{
experimental: {
flags: {
detectSegmentUsageInChangeRequests: true,
},
flags: {},
},
},
db.rawDatabase,
Expand Down

0 comments on commit 73322f1

Please sign in to comment.