mirror of
https://github.com/Unleash/unleash.git
synced 2025-02-14 00:19:16 +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,
|
"responseTimeWithAppNameKillSwitch": false,
|
||||||
"separateAdminClientApi": false,
|
"separateAdminClientApi": false,
|
||||||
"strictSchemaValidation": false,
|
"strictSchemaValidation": false,
|
||||||
"transactionalDecorator": false,
|
|
||||||
"useLastSeenRefactor": false,
|
"useLastSeenRefactor": false,
|
||||||
"variantTypeNumber": false,
|
"variantTypeNumber": false,
|
||||||
},
|
},
|
||||||
@ -160,7 +159,6 @@ exports[`should create default config 1`] = `
|
|||||||
"responseTimeWithAppNameKillSwitch": false,
|
"responseTimeWithAppNameKillSwitch": false,
|
||||||
"separateAdminClientApi": false,
|
"separateAdminClientApi": false,
|
||||||
"strictSchemaValidation": false,
|
"strictSchemaValidation": false,
|
||||||
"transactionalDecorator": false,
|
|
||||||
"useLastSeenRefactor": false,
|
"useLastSeenRefactor": false,
|
||||||
"variantTypeNumber": false,
|
"variantTypeNumber": false,
|
||||||
},
|
},
|
||||||
|
@ -1,16 +1,9 @@
|
|||||||
import { Response } from 'express';
|
import { Response } from 'express';
|
||||||
import Controller from '../../routes/controller';
|
import Controller from '../../routes/controller';
|
||||||
import { Logger } from '../../logger';
|
import { Logger } from '../../logger';
|
||||||
import ExportImportService, {
|
import { IExportService, IImportService } from './export-import-service';
|
||||||
IExportService,
|
|
||||||
IImportService,
|
|
||||||
} from './export-import-service';
|
|
||||||
import { OpenApiService } from '../../services';
|
import { OpenApiService } from '../../services';
|
||||||
import {
|
import { WithTransactional } from '../../db/transaction';
|
||||||
TransactionCreator,
|
|
||||||
UnleashTransaction,
|
|
||||||
WithTransactional,
|
|
||||||
} from '../../db/transaction';
|
|
||||||
import {
|
import {
|
||||||
IUnleashConfig,
|
IUnleashConfig,
|
||||||
IUnleashServices,
|
IUnleashServices,
|
||||||
@ -37,41 +30,25 @@ class ExportImportController extends Controller {
|
|||||||
|
|
||||||
private exportService: IExportService;
|
private exportService: IExportService;
|
||||||
|
|
||||||
/** @deprecated gradually rolling out importService */
|
|
||||||
private transactionalExportImportService: (
|
|
||||||
db: UnleashTransaction,
|
|
||||||
) => IImportService;
|
|
||||||
|
|
||||||
private importService: WithTransactional<IImportService>;
|
private importService: WithTransactional<IImportService>;
|
||||||
|
|
||||||
private openApiService: OpenApiService;
|
private openApiService: OpenApiService;
|
||||||
|
|
||||||
/** @deprecated gradually rolling out importService */
|
|
||||||
private readonly startTransaction: TransactionCreator<UnleashTransaction>;
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
config: IUnleashConfig,
|
config: IUnleashConfig,
|
||||||
{
|
{
|
||||||
exportService,
|
exportService,
|
||||||
transactionalExportImportService,
|
|
||||||
importService,
|
importService,
|
||||||
openApiService,
|
openApiService,
|
||||||
}: Pick<
|
}: Pick<
|
||||||
IUnleashServices,
|
IUnleashServices,
|
||||||
| 'exportService'
|
'exportService' | 'importService' | 'openApiService'
|
||||||
| 'importService'
|
|
||||||
| 'openApiService'
|
|
||||||
| 'transactionalExportImportService'
|
|
||||||
>,
|
>,
|
||||||
startTransaction: TransactionCreator<UnleashTransaction>,
|
|
||||||
) {
|
) {
|
||||||
super(config);
|
super(config);
|
||||||
this.logger = config.getLogger('/admin-api/export-import.ts');
|
this.logger = config.getLogger('/admin-api/export-import.ts');
|
||||||
this.exportService = exportService;
|
this.exportService = exportService;
|
||||||
this.transactionalExportImportService =
|
|
||||||
transactionalExportImportService;
|
|
||||||
this.importService = importService;
|
this.importService = importService;
|
||||||
this.startTransaction = startTransaction;
|
|
||||||
this.openApiService = openApiService;
|
this.openApiService = openApiService;
|
||||||
this.route({
|
this.route({
|
||||||
method: 'post',
|
method: 'post',
|
||||||
@ -161,16 +138,9 @@ class ExportImportController extends Controller {
|
|||||||
const dto = req.body;
|
const dto = req.body;
|
||||||
const { user } = req;
|
const { user } = req;
|
||||||
|
|
||||||
const useTransactionalDecorator = this.config.flagResolver.isEnabled(
|
const validation = await this.importService.transactional((service) =>
|
||||||
'transactionalDecorator',
|
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(
|
this.openApiService.respondWithValidation(
|
||||||
200,
|
200,
|
||||||
@ -195,20 +165,10 @@ class ExportImportController extends Controller {
|
|||||||
|
|
||||||
const dto = req.body;
|
const dto = req.body;
|
||||||
|
|
||||||
const useTransactionalDecorator = this.config.flagResolver.isEnabled(
|
await this.importService.transactional((service) =>
|
||||||
'transactionalDecorator',
|
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();
|
res.status(200).end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,7 +161,6 @@ beforeAll(async () => {
|
|||||||
featuresExportImport: true,
|
featuresExportImport: true,
|
||||||
featureNamingPattern: true,
|
featureNamingPattern: true,
|
||||||
dependentFeatures: 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('/state', new StateController(config, services).router);
|
||||||
this.app.use(
|
this.app.use(
|
||||||
'/features-batch',
|
'/features-batch',
|
||||||
new ExportImportController(
|
new ExportImportController(config, services).router,
|
||||||
config,
|
|
||||||
services,
|
|
||||||
createKnexTransactionStarter(db),
|
|
||||||
).router,
|
|
||||||
);
|
);
|
||||||
this.app.use('/tags', new TagController(config, services).router);
|
this.app.use('/tags', new TagController(config, services).router);
|
||||||
this.app.use(
|
this.app.use(
|
||||||
|
@ -307,8 +307,6 @@ export const createServices = (
|
|||||||
const importService = db
|
const importService = db
|
||||||
? withTransactional(deferredExportImportTogglesService(config), db)
|
? withTransactional(deferredExportImportTogglesService(config), db)
|
||||||
: withFakeTransactional(createFakeExportImportTogglesService(config));
|
: withFakeTransactional(createFakeExportImportTogglesService(config));
|
||||||
const transactionalExportImportService = (txDb: Knex.Transaction) =>
|
|
||||||
createExportImportTogglesService(txDb, config);
|
|
||||||
const transactionalFeatureToggleService = (txDb: Knex.Transaction) =>
|
const transactionalFeatureToggleService = (txDb: Knex.Transaction) =>
|
||||||
createFeatureToggleService(txDb, config);
|
createFeatureToggleService(txDb, config);
|
||||||
const transactionalGroupService = (txDb: Knex.Transaction) =>
|
const transactionalGroupService = (txDb: Knex.Transaction) =>
|
||||||
@ -413,7 +411,6 @@ export const createServices = (
|
|||||||
favoritesService,
|
favoritesService,
|
||||||
maintenanceService,
|
maintenanceService,
|
||||||
exportService: exportImportService,
|
exportService: exportImportService,
|
||||||
transactionalExportImportService,
|
|
||||||
importService,
|
importService,
|
||||||
schedulerService,
|
schedulerService,
|
||||||
configurationRevisionService,
|
configurationRevisionService,
|
||||||
|
@ -33,7 +33,6 @@ export type IFlagKey =
|
|||||||
| 'dependentFeatures'
|
| 'dependentFeatures'
|
||||||
| 'datadogJsonTemplate'
|
| 'datadogJsonTemplate'
|
||||||
| 'disableMetrics'
|
| 'disableMetrics'
|
||||||
| 'transactionalDecorator'
|
|
||||||
| 'useLastSeenRefactor'
|
| 'useLastSeenRefactor'
|
||||||
| 'internalMessageBanners'
|
| 'internalMessageBanners'
|
||||||
| 'internalMessageBanner'
|
| 'internalMessageBanner'
|
||||||
@ -159,10 +158,6 @@ const flags: IFlags = {
|
|||||||
process.env.UNLEASH_EXPERIMENTAL_DISABLE_METRICS,
|
process.env.UNLEASH_EXPERIMENTAL_DISABLE_METRICS,
|
||||||
false,
|
false,
|
||||||
),
|
),
|
||||||
transactionalDecorator: parseEnvVarBoolean(
|
|
||||||
process.env.UNLEASH_EXPERIMENTAL_TRANSACTIONAL_DECORATOR,
|
|
||||||
false,
|
|
||||||
),
|
|
||||||
useLastSeenRefactor: parseEnvVarBoolean(
|
useLastSeenRefactor: parseEnvVarBoolean(
|
||||||
process.env.UNLEASH_EXPERIMENTAL_USE_LAST_SEEN_REFACTOR,
|
process.env.UNLEASH_EXPERIMENTAL_USE_LAST_SEEN_REFACTOR,
|
||||||
false,
|
false,
|
||||||
|
@ -65,7 +65,8 @@ export interface IUnleashServices {
|
|||||||
edgeService: EdgeService;
|
edgeService: EdgeService;
|
||||||
featureTagService: FeatureTagService;
|
featureTagService: FeatureTagService;
|
||||||
featureToggleService: FeatureToggleService;
|
featureToggleService: FeatureToggleService;
|
||||||
featureToggleServiceV2: FeatureToggleService; // deprecated
|
/** @deprecated use featureToggleService instead, both are interchangeable */
|
||||||
|
featureToggleServiceV2: FeatureToggleService;
|
||||||
featureTypeService: FeatureTypeService;
|
featureTypeService: FeatureTypeService;
|
||||||
groupService: GroupService;
|
groupService: GroupService;
|
||||||
healthService: HealthService;
|
healthService: HealthService;
|
||||||
@ -98,8 +99,6 @@ export interface IUnleashServices {
|
|||||||
configurationRevisionService: ConfigurationRevisionService;
|
configurationRevisionService: ConfigurationRevisionService;
|
||||||
schedulerService: SchedulerService;
|
schedulerService: SchedulerService;
|
||||||
eventAnnouncerService: EventAnnouncerService;
|
eventAnnouncerService: EventAnnouncerService;
|
||||||
/** @deprecated prefer exportImportServiceV2, we're doing a gradual rollout */
|
|
||||||
transactionalExportImportService: (db: Knex.Transaction) => IImportService;
|
|
||||||
transactionalFeatureToggleService: (
|
transactionalFeatureToggleService: (
|
||||||
db: Knex.Transaction,
|
db: Knex.Transaction,
|
||||||
) => FeatureToggleService;
|
) => FeatureToggleService;
|
||||||
|
@ -46,7 +46,6 @@ process.nextTick(async () => {
|
|||||||
accessOverview: true,
|
accessOverview: true,
|
||||||
datadogJsonTemplate: true,
|
datadogJsonTemplate: true,
|
||||||
dependentFeatures: true,
|
dependentFeatures: true,
|
||||||
transactionalDecorator: true,
|
|
||||||
useLastSeenRefactor: true,
|
useLastSeenRefactor: true,
|
||||||
separateAdminClientApi: true,
|
separateAdminClientApi: true,
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user