Skip to content

Commit

Permalink
chore: GA transactional decorator (#5020)
Browse files Browse the repository at this point in the history
## About the changes
After testing with the flag enabled and fixing a bug, this is ready to
be GA
  • Loading branch information
gastonfournier committed Oct 17, 2023
1 parent fd580c9 commit 08116d0
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 67 deletions.
2 changes: 0 additions & 2 deletions src/lib/__snapshots__/create-config.test.ts.snap
Expand Up @@ -114,7 +114,6 @@ exports[`should create default config 1`] = `
"responseTimeWithAppNameKillSwitch": false,
"separateAdminClientApi": false,
"strictSchemaValidation": false,
"transactionalDecorator": false,
"useLastSeenRefactor": false,
"variantTypeNumber": false,
},
Expand Down Expand Up @@ -160,7 +159,6 @@ exports[`should create default config 1`] = `
"responseTimeWithAppNameKillSwitch": false,
"separateAdminClientApi": false,
"strictSchemaValidation": false,
"transactionalDecorator": false,
"useLastSeenRefactor": false,
"variantTypeNumber": false,
},
Expand Down
54 changes: 7 additions & 47 deletions src/lib/features/export-import-toggles/export-import-controller.ts
@@ -1,16 +1,9 @@
import { Response } from 'express';
import Controller from '../../routes/controller';
import { Logger } from '../../logger';
import ExportImportService, {
IExportService,
IImportService,
} from './export-import-service';
import { IExportService, IImportService } from './export-import-service';
import { OpenApiService } from '../../services';
import {
TransactionCreator,
UnleashTransaction,
WithTransactional,
} from '../../db/transaction';
import { WithTransactional } from '../../db/transaction';
import {
IUnleashConfig,
IUnleashServices,
Expand All @@ -37,41 +30,25 @@ class ExportImportController extends Controller {

private exportService: IExportService;

/** @deprecated gradually rolling out importService */
private transactionalExportImportService: (
db: UnleashTransaction,
) => IImportService;

private importService: WithTransactional<IImportService>;

private openApiService: OpenApiService;

/** @deprecated gradually rolling out importService */
private readonly startTransaction: TransactionCreator<UnleashTransaction>;

constructor(
config: IUnleashConfig,
{
exportService,
transactionalExportImportService,
importService,
openApiService,
}: Pick<
IUnleashServices,
| 'exportService'
| 'importService'
| 'openApiService'
| 'transactionalExportImportService'
'exportService' | 'importService' | 'openApiService'
>,
startTransaction: TransactionCreator<UnleashTransaction>,
) {
super(config);
this.logger = config.getLogger('/admin-api/export-import.ts');
this.exportService = exportService;
this.transactionalExportImportService =
transactionalExportImportService;
this.importService = importService;
this.startTransaction = startTransaction;
this.openApiService = openApiService;
this.route({
method: 'post',
Expand Down Expand Up @@ -161,16 +138,9 @@ class ExportImportController extends Controller {
const dto = req.body;
const { user } = req;

const useTransactionalDecorator = this.config.flagResolver.isEnabled(
'transactionalDecorator',
const validation = await this.importService.transactional((service) =>
service.validate(dto, user),
);
const validation = useTransactionalDecorator
? await this.importService.transactional((service) =>
service.validate(dto, user),
)
: await this.startTransaction(async (tx) =>
this.transactionalExportImportService(tx).validate(dto, user),
);

this.openApiService.respondWithValidation(
200,
Expand All @@ -195,20 +165,10 @@ class ExportImportController extends Controller {

const dto = req.body;

const useTransactionalDecorator = this.config.flagResolver.isEnabled(
'transactionalDecorator',
await this.importService.transactional((service) =>
service.import(dto, user),
);

if (useTransactionalDecorator) {
await this.importService.transactional((service) =>
service.import(dto, user),
);
} else {
await this.startTransaction(async (tx) =>
this.transactionalExportImportService(tx).import(dto, user),
);
}

res.status(200).end();
}

Expand Down
Expand Up @@ -161,7 +161,6 @@ beforeAll(async () => {
featuresExportImport: true,
featureNamingPattern: true,
dependentFeatures: true,
transactionalDecorator: true,
},
},
},
Expand Down
6 changes: 1 addition & 5 deletions src/lib/routes/admin-api/index.ts
Expand Up @@ -88,11 +88,7 @@ class AdminApi extends Controller {
this.app.use('/state', new StateController(config, services).router);
this.app.use(
'/features-batch',
new ExportImportController(
config,
services,
createKnexTransactionStarter(db),
).router,
new ExportImportController(config, services).router,
);
this.app.use('/tags', new TagController(config, services).router);
this.app.use(
Expand Down
3 changes: 0 additions & 3 deletions src/lib/services/index.ts
Expand Up @@ -307,8 +307,6 @@ export const createServices = (
const importService = db
? withTransactional(deferredExportImportTogglesService(config), db)
: withFakeTransactional(createFakeExportImportTogglesService(config));
const transactionalExportImportService = (txDb: Knex.Transaction) =>
createExportImportTogglesService(txDb, config);
const transactionalFeatureToggleService = (txDb: Knex.Transaction) =>
createFeatureToggleService(txDb, config);
const transactionalGroupService = (txDb: Knex.Transaction) =>
Expand Down Expand Up @@ -413,7 +411,6 @@ export const createServices = (
favoritesService,
maintenanceService,
exportService: exportImportService,
transactionalExportImportService,
importService,
schedulerService,
configurationRevisionService,
Expand Down
5 changes: 0 additions & 5 deletions src/lib/types/experimental.ts
Expand Up @@ -33,7 +33,6 @@ export type IFlagKey =
| 'dependentFeatures'
| 'datadogJsonTemplate'
| 'disableMetrics'
| 'transactionalDecorator'
| 'useLastSeenRefactor'
| 'internalMessageBanners'
| 'internalMessageBanner'
Expand Down Expand Up @@ -159,10 +158,6 @@ const flags: IFlags = {
process.env.UNLEASH_EXPERIMENTAL_DISABLE_METRICS,
false,
),
transactionalDecorator: parseEnvVarBoolean(
process.env.UNLEASH_EXPERIMENTAL_TRANSACTIONAL_DECORATOR,
false,
),
useLastSeenRefactor: parseEnvVarBoolean(
process.env.UNLEASH_EXPERIMENTAL_USE_LAST_SEEN_REFACTOR,
false,
Expand Down
5 changes: 2 additions & 3 deletions src/lib/types/services.ts
Expand Up @@ -65,7 +65,8 @@ export interface IUnleashServices {
edgeService: EdgeService;
featureTagService: FeatureTagService;
featureToggleService: FeatureToggleService;
featureToggleServiceV2: FeatureToggleService; // deprecated
/** @deprecated use featureToggleService instead, both are interchangeable */
featureToggleServiceV2: FeatureToggleService;
featureTypeService: FeatureTypeService;
groupService: GroupService;
healthService: HealthService;
Expand Down Expand Up @@ -98,8 +99,6 @@ export interface IUnleashServices {
configurationRevisionService: ConfigurationRevisionService;
schedulerService: SchedulerService;
eventAnnouncerService: EventAnnouncerService;
/** @deprecated prefer exportImportServiceV2, we're doing a gradual rollout */
transactionalExportImportService: (db: Knex.Transaction) => IImportService;
transactionalFeatureToggleService: (
db: Knex.Transaction,
) => FeatureToggleService;
Expand Down
1 change: 0 additions & 1 deletion src/server-dev.ts
Expand Up @@ -46,7 +46,6 @@ process.nextTick(async () => {
accessOverview: true,
datadogJsonTemplate: true,
dependentFeatures: true,
transactionalDecorator: true,
useLastSeenRefactor: true,
separateAdminClientApi: true,
},
Expand Down

0 comments on commit 08116d0

Please sign in to comment.