diff --git a/src/lib/__snapshots__/create-config.test.ts.snap b/src/lib/__snapshots__/create-config.test.ts.snap index 1f128f1e8c..d5f31a9271 100644 --- a/src/lib/__snapshots__/create-config.test.ts.snap +++ b/src/lib/__snapshots__/create-config.test.ts.snap @@ -72,7 +72,11 @@ Object { "db": true, "ttlHours": 48, }, - "ui": Object {}, + "ui": Object { + "flags": Object { + "E": true, + }, + }, "versionCheck": Object { "enable": true, "url": "https://version.unleash.run", diff --git a/src/lib/create-config.test.ts b/src/lib/create-config.test.ts index ff5eb185ea..688cf9439d 100644 --- a/src/lib/create-config.test.ts +++ b/src/lib/create-config.test.ts @@ -17,50 +17,3 @@ test('should create default config', async () => { expect(config).toMatchSnapshot(); }); - -test('should enabled metricsV2 via options', async () => { - const config = createConfig({ - experimental: { - metricsV2: { enabled: true }, - }, - }); - - expect(config.experimental.metricsV2.enabled).toBe(true); -}); - -test('should enabled metricsV2 via env variable', async () => { - process.env.EXP_METRICS_V2 = 'true'; - const config = createConfig({}); - - expect(config.experimental.metricsV2.enabled).toBe(true); - delete process.env.EXP_METRICS_V2; -}); - -test('should enabled metricsV2 when environments is enabled via env variable', async () => { - process.env.EXP_ENVIRONMENTS = 'true'; - const config = createConfig({}); - - expect(config.experimental.environments.enabled).toBe(true); - expect(config.experimental.metricsV2.enabled).toBe(true); - delete process.env.EXP_ENVIRONMENTS; -}); - -test('should enabled metricsV2 when environments is enabled via options', async () => { - const config = createConfig({ - experimental: { - environments: { enabled: true }, - }, - }); - - expect(config.experimental.environments.enabled).toBe(true); - expect(config.experimental.metricsV2.enabled).toBe(true); -}); - -test('should set UI flag when environments is enabled', async () => { - process.env.EXP_ENVIRONMENTS = 'true'; - const config = createConfig({}); - - expect(config.experimental.environments.enabled).toBe(true); - expect(config.ui.flags?.E).toBe(true); - delete process.env.EXP_ENVIRONMENTS; -}); diff --git a/src/lib/create-config.ts b/src/lib/create-config.ts index ddbe9bbd97..6aed392c48 100644 --- a/src/lib/create-config.ts +++ b/src/lib/create-config.ts @@ -56,30 +56,16 @@ function mergeAll(objects: Partial[]): T { function loadExperimental(options: IUnleashOptions): any { const experimental = options.experimental || {}; - if (safeBoolean(process.env.EXP_ENVIRONMENTS, false)) { - experimental.environments = { enabled: true }; - } - - if ( - safeBoolean(process.env.EXP_METRICS_V2, false) || - //@ts-ignore - experimental.environments?.enabled - ) { - experimental.metricsV2 = { enabled: true }; - } - return experimental; } -function loadUI(options: IUnleashOptions, experimental: any = {}): IUIConfig { +function loadUI(options: IUnleashOptions): IUIConfig { const uiO = options.ui || {}; const ui: IUIConfig = {}; - if (experimental.environments?.enabled) { - ui.flags = { - E: true, - }; - } + ui.flags = { + E: true, + }; return mergeAll([uiO, ui]); } @@ -254,7 +240,7 @@ export function createConfig(options: IUnleashOptions): IUnleashConfig { const experimental = loadExperimental(options); - const ui = loadUI(options, experimental); + const ui = loadUI(options); const email: IEmailOption = mergeAll([defaultEmail, options.email]); diff --git a/src/lib/routes/client-api/metrics.ts b/src/lib/routes/client-api/metrics.ts index 4e7f032946..9cbc3a7175 100644 --- a/src/lib/routes/client-api/metrics.ts +++ b/src/lib/routes/client-api/metrics.ts @@ -18,8 +18,6 @@ export default class ClientMetricsController extends Controller { metricsV2: ClientMetricsServiceV2; - newServiceEnabled: boolean = false; - constructor( { clientMetricsService, @@ -31,11 +29,7 @@ export default class ClientMetricsController extends Controller { config: IUnleashConfig, ) { super(config); - const { experimental, getLogger } = config; - if (experimental && experimental.metricsV2) { - //@ts-ignore - this.newServiceEnabled = experimental.metricsV2.enabled; - } + const { getLogger } = config; this.logger = getLogger('/api/client/metrics'); this.metrics = clientMetricsService; @@ -60,12 +54,8 @@ export default class ClientMetricsController extends Controller { data.environment = this.resolveEnvironment(user, data); await this.metrics.registerClientMetrics(data, clientIp); - if (this.newServiceEnabled) { - await this.metricsV2.registerClientMetrics(data, clientIp); - } + await this.metricsV2.registerClientMetrics(data, clientIp); return res.status(202).end(); } } - -module.exports = ClientMetricsController; diff --git a/src/lib/services/project-service.ts b/src/lib/services/project-service.ts index ac4d2c9fe4..29cd4ff9e6 100644 --- a/src/lib/services/project-service.ts +++ b/src/lib/services/project-service.ts @@ -60,8 +60,6 @@ export default class ProjectService { private featureToggleService: FeatureToggleService; - private environmentsEnabled: boolean = false; - constructor( { projectStore, @@ -92,8 +90,6 @@ export default class ProjectService { this.featureTypeStore = featureTypeStore; this.featureToggleService = featureToggleService; this.logger = config.getLogger('services/project-service.js'); - this.environmentsEnabled = - config.experimental.environments?.enabled || false; } async getProjects(query?: IProjectQuery): Promise { @@ -127,26 +123,19 @@ export default class ProjectService { await this.store.create(data); - if (this.environmentsEnabled) { - const enabledEnvironments = await this.environmentStore.getAll({ - enabled: true, - }); + const enabledEnvironments = await this.environmentStore.getAll({ + enabled: true, + }); - // TODO: Only if enabled! - await Promise.all( - enabledEnvironments.map(async (e) => { - await this.featureEnvironmentStore.connectProject( - e.name, - data.id, - ); - }), - ); - } else { - await this.featureEnvironmentStore.connectProject( - 'default', - data.id, - ); - } + // TODO: Only if enabled! + await Promise.all( + enabledEnvironments.map(async (e) => { + await this.featureEnvironmentStore.connectProject( + e.name, + data.id, + ); + }), + ); await this.accessService.createDefaultProjectRoles(user, data.id); diff --git a/src/migrations/20211126112551-disable-default-environment.js b/src/migrations/20211126112551-disable-default-environment.js new file mode 100644 index 0000000000..51eca50055 --- /dev/null +++ b/src/migrations/20211126112551-disable-default-environment.js @@ -0,0 +1,27 @@ +exports.up = function (db, cb) { + db.runSql( + ` + UPDATE environments + SET enabled = false + WHERE name = 'default' + AND NOT EXISTS (select * from features); + + DELETE FROM project_environments + WHERE environment_name = 'default' + AND NOT EXISTS (select * from features); + + INSERT INTO project_environments(project_id, environment_name) + SELECT 'default', 'development' + WHERE NOT EXISTS (select * from features); + + INSERT INTO project_environments(project_id, environment_name) + SELECT 'default', 'production' + WHERE NOT EXISTS (select * from features); + `, + cb, + ); +}; + +exports.down = function (db, cb) { + db.runSql('', cb); +}; diff --git a/src/test/e2e/services/project-service.e2e.test.ts b/src/test/e2e/services/project-service.e2e.test.ts index 951b459cf7..05e26f7f05 100644 --- a/src/test/e2e/services/project-service.e2e.test.ts +++ b/src/test/e2e/services/project-service.e2e.test.ts @@ -548,40 +548,3 @@ test('A newly created project only gets connected to enabled environments', asyn expect(connectedEnvs.some((e) => e === enabledEnv)).toBeTruthy(); expect(connectedEnvs.some((e) => e === disabledEnv)).toBeFalsy(); }); - -test('A newly created project only gets connected to default environment if experimental flag is disabled', async () => { - const config = createTestConfig({ - getLogger, - // @ts-ignore - experimental: { environments: { enabled: false } }, - }); - projectService = new ProjectService( - stores, - //@ts-ignore - config, - accessService, - featureToggleService, - ); - const project = { - id: 'environment-test-default', - name: 'New environment project', - description: 'Blah', - }; - const enabledEnv = 'connection_test'; - await db.stores.environmentStore.create({ - name: enabledEnv, - type: 'test', - }); - const disabledEnv = 'do_not_connect'; - await db.stores.environmentStore.create({ - name: disabledEnv, - type: 'test', - enabled: false, - }); - - await projectService.createProject(project, user); - const connectedEnvs = - await db.stores.projectStore.getEnvironmentsForProject(project.id); - expect(connectedEnvs).toHaveLength(1); // default, connection_test - expect(connectedEnvs[0]).toBe('default'); -});