mirror of
https://github.com/Unleash/unleash.git
synced 2025-02-09 00:18:00 +01:00
chore: GA transactional decorator (#5020)
## About the changes After testing with the flag enabled and fixing a bug, this is ready to be GA
This commit is contained in:
parent
fd580c9539
commit
08116d008a
@ -114,7 +114,6 @@ exports[`should create default config 1`] = `
|
||||
"responseTimeWithAppNameKillSwitch": false,
|
||||
"separateAdminClientApi": false,
|
||||
"strictSchemaValidation": false,
|
||||
"transactionalDecorator": false,
|
||||
"useLastSeenRefactor": false,
|
||||
"variantTypeNumber": false,
|
||||
},
|
||||
@ -160,7 +159,6 @@ exports[`should create default config 1`] = `
|
||||
"responseTimeWithAppNameKillSwitch": false,
|
||||
"separateAdminClientApi": false,
|
||||
"strictSchemaValidation": false,
|
||||
"transactionalDecorator": false,
|
||||
"useLastSeenRefactor": false,
|
||||
"variantTypeNumber": false,
|
||||
},
|
||||
|
@ -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,
|
||||
@ -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',
|
||||
@ -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,
|
||||
@ -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();
|
||||
}
|
||||
|
||||
|
@ -161,7 +161,6 @@ beforeAll(async () => {
|
||||
featuresExportImport: true,
|
||||
featureNamingPattern: true,
|
||||
dependentFeatures: true,
|
||||
transactionalDecorator: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -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(
|
||||
|
@ -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) =>
|
||||
@ -413,7 +411,6 @@ export const createServices = (
|
||||
favoritesService,
|
||||
maintenanceService,
|
||||
exportService: exportImportService,
|
||||
transactionalExportImportService,
|
||||
importService,
|
||||
schedulerService,
|
||||
configurationRevisionService,
|
||||
|
@ -33,7 +33,6 @@ export type IFlagKey =
|
||||
| 'dependentFeatures'
|
||||
| 'datadogJsonTemplate'
|
||||
| 'disableMetrics'
|
||||
| 'transactionalDecorator'
|
||||
| 'useLastSeenRefactor'
|
||||
| 'internalMessageBanners'
|
||||
| 'internalMessageBanner'
|
||||
@ -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,
|
||||
|
@ -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;
|
||||
@ -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;
|
||||
|
@ -46,7 +46,6 @@ process.nextTick(async () => {
|
||||
accessOverview: true,
|
||||
datadogJsonTemplate: true,
|
||||
dependentFeatures: true,
|
||||
transactionalDecorator: true,
|
||||
useLastSeenRefactor: true,
|
||||
separateAdminClientApi: true,
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user