Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "task: enabled in OSS." #8892

Merged
merged 1 commit into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/lib/__snapshots__/create-config.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ exports[`should create default config 1`] = `
},
"inlineSegmentConstraints": true,
"isEnterprise": false,
"isOss": false,
"listen": {
"host": undefined,
"port": 4242,
Expand Down
5 changes: 0 additions & 5 deletions src/lib/create-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -620,10 +620,6 @@ export function createConfig(options: IUnleashOptions): IUnleashConfig {
Boolean(options.enterpriseVersion) &&
ui.environment?.toLowerCase() !== 'pro';

const isTest = process.env.NODE_ENV === 'test';
const isOss = isTest
? options.isOss || false
: !isEnterprise && ui.environment !== 'pro';
const metricsRateLimiting = loadMetricsRateLimitingConfig(options);

const rateLimiting = loadRateLimitingConfig(options);
Expand Down Expand Up @@ -764,7 +760,6 @@ export function createConfig(options: IUnleashOptions): IUnleashConfig {
publicFolder: options.publicFolder,
disableScheduler: options.disableScheduler,
isEnterprise: isEnterprise,
isOss: isOss,
metricsRateLimiting,
rateLimiting,
feedbackUriPath,
Expand Down
31 changes: 2 additions & 29 deletions src/lib/db/feature-environment-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ import type {
FeatureEnvironmentKey,
IFeatureEnvironmentStore,
} from '../types/stores/feature-environment-store';
import type { Logger } from '../logger';
import type { Logger, LogProvider } from '../logger';
import metricsHelper from '../util/metrics-helper';
import { DB_TIME } from '../metric-events';
import type { IFeatureEnvironment, IVariant } from '../types/model';
import NotFoundError from '../error/notfound-error';
import { v4 as uuidv4 } from 'uuid';
import type { Db } from './db';
import type { IUnleashConfig } from '../types';

const T = {
featureEnvs: 'feature_environments',
Expand All @@ -37,20 +36,14 @@ export class FeatureEnvironmentStore implements IFeatureEnvironmentStore {

private readonly timer: Function;

private readonly isOss: boolean;
constructor(
db: Db,
eventBus: EventEmitter,
{ getLogger, isOss }: Pick<IUnleashConfig, 'getLogger' | 'isOss'>,
) {
constructor(db: Db, eventBus: EventEmitter, getLogger: LogProvider) {
this.db = db;
this.logger = getLogger('feature-environment-store.ts');
this.timer = (action) =>
metricsHelper.wrapTimer(eventBus, DB_TIME, {
store: 'feature-environments',
action,
});
this.isOss = isOss;
}

async delete({
Expand Down Expand Up @@ -103,30 +96,11 @@ export class FeatureEnvironmentStore implements IFeatureEnvironmentStore {
);
}

addOssFilterIfNeeded(queryBuilder) {
if (this.isOss) {
return queryBuilder
.join(
'environments',
'environments.name',
'=',
`${T.featureEnvs}.environment`,
)
.whereIn('environments.name', [
'default',
'development',
'production',
]);
}
return queryBuilder;
}

async getAll(query?: Object): Promise<IFeatureEnvironment[]> {
let rows = this.db(T.featureEnvs);
if (query) {
rows = rows.where(query);
}
this.addOssFilterIfNeeded(rows);
return (await rows).map((r) => ({
enabled: r.enabled,
featureName: r.feature_name,
Expand All @@ -145,7 +119,6 @@ export class FeatureEnvironmentStore implements IFeatureEnvironmentStore {
if (environment) {
rows = rows.where({ environment });
}
this.addOssFilterIfNeeded(rows);
return (await rows).map((r) => ({
enabled: r.enabled,
featureName: r.feature_name,
Expand Down
14 changes: 10 additions & 4 deletions src/lib/db/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,12 @@ export const createStores = (
settingStore: new SettingStore(db, getLogger),
userStore: new UserStore(db, getLogger, config.flagResolver),
accountStore: new AccountStore(db, getLogger),
projectStore: new ProjectStore(db, eventBus, config),
projectStore: new ProjectStore(
db,
eventBus,
getLogger,
config.flagResolver,
),
tagStore: new TagStore(db, eventBus, getLogger),
tagTypeStore: new TagTypeStore(db, eventBus, getLogger),
addonStore: new AddonStore(db, eventBus, getLogger),
Expand All @@ -117,14 +122,15 @@ export const createStores = (
clientFeatureToggleStore: new FeatureToggleClientStore(
db,
eventBus,
config,
getLogger,
config.flagResolver,
),
environmentStore: new EnvironmentStore(db, eventBus, config),
environmentStore: new EnvironmentStore(db, eventBus, getLogger),
featureTagStore: new FeatureTagStore(db, eventBus, getLogger),
featureEnvironmentStore: new FeatureEnvironmentStore(
db,
eventBus,
config,
getLogger,
),
userSplashStore: new UserSplashStore(db, eventBus, getLogger),
roleStore: new RoleStore(db, eventBus, getLogger),
Expand Down
2 changes: 1 addition & 1 deletion src/lib/features/access/createAccessService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const createAccessService = (
const groupStore = new GroupStore(db);
const accountStore = new AccountStore(db, getLogger);
const roleStore = new RoleStore(db, eventBus, getLogger);
const environmentStore = new EnvironmentStore(db, eventBus, config);
const environmentStore = new EnvironmentStore(db, eventBus, getLogger);
const accessStore = new AccessStore(db, eventBus, getLogger);
const eventService = createEventsService(db, config);
const groupService = new GroupService(
Expand Down
2 changes: 1 addition & 1 deletion src/lib/features/api-tokens/createApiTokenService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const createApiTokenService = (
getLogger,
config.flagResolver,
);
const environmentStore = new EnvironmentStore(db, eventBus, config);
const environmentStore = new EnvironmentStore(db, eventBus, getLogger);
const eventService = createEventsService(db, config);

return new ApiTokenService(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { Knex } from 'knex';
import metricsHelper from '../../util/metrics-helper';
import { DB_TIME } from '../../metric-events';
import type { Logger } from '../../logger';
import type { Logger, LogProvider } from '../../logger';
import type {
IFeatureToggleClient,
IFeatureToggleClientStore,
IFeatureToggleQuery,
IFlagResolver,
IStrategyConfig,
ITag,
IUnleashConfig,
PartialDeep,
} from '../../types';
import {
Expand Down Expand Up @@ -47,16 +46,11 @@ export default class FeatureToggleClientStore

private flagResolver: IFlagResolver;

private readonly isOss: boolean;

constructor(
db: Db,
eventBus: EventEmitter,
{
getLogger,
flagResolver,
isOss,
}: Pick<IUnleashConfig, 'getLogger' | 'flagResolver' | 'isOss'>,
getLogger: LogProvider,
flagResolver: IFlagResolver,
) {
this.db = db;
this.logger = getLogger('feature-toggle-client-store.ts');
Expand All @@ -66,7 +60,6 @@ export default class FeatureToggleClientStore
action,
});
this.flagResolver = flagResolver;
this.isOss = isOss;
}

private async getAll({
Expand All @@ -79,6 +72,7 @@ export default class FeatureToggleClientStore
const isPlayground = requestType === 'playground';
const environment = featureQuery?.environment || DEFAULT_ENV;
const stopTimer = this.timer(`getAllBy${requestType}`);

let selectColumns = [
'features.name as name',
'features.description as description',
Expand Down Expand Up @@ -109,10 +103,6 @@ export default class FeatureToggleClientStore

let query = this.db('features')
.modify(FeatureToggleStore.filterByArchived, archived)
.modify(
FeatureToggleStore.filterByProjectsAccessibleByOss,
this.isOss,
)
.leftJoin(
this.db('feature_strategies')
.select('*')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ export const createClientFeatureToggleService = (
db: Db,
config: IUnleashConfig,
): ClientFeatureToggleService => {
const { getLogger, eventBus, flagResolver } = config;

const featureToggleClientStore = new FeatureToggleClientStore(
db,
config.eventBus,
config,
eventBus,
getLogger,
flagResolver,
);

const segmentReadModel = new SegmentReadModel(db);
Expand All @@ -23,7 +26,7 @@ export const createClientFeatureToggleService = (
clientFeatureToggleStore: featureToggleClientStore,
},
segmentReadModel,
config,
{ getLogger, flagResolver },
);

return clientFeatureToggleService;
Expand All @@ -32,6 +35,8 @@ export const createClientFeatureToggleService = (
export const createFakeClientFeatureToggleService = (
config: IUnleashConfig,
): ClientFeatureToggleService => {
const { getLogger, flagResolver } = config;

const fakeClientFeatureToggleStore = new FakeClientFeatureToggleStore();

const fakeSegmentReadModel = new FakeSegmentReadModel();
Expand All @@ -41,7 +46,7 @@ export const createFakeClientFeatureToggleService = (
clientFeatureToggleStore: fakeClientFeatureToggleStore,
},
fakeSegmentReadModel,
config,
{ getLogger, flagResolver },
);

return clientFeatureToggleService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,12 @@ export const deferredExportImportTogglesService = (
);
const tagStore = new TagStore(db, eventBus, getLogger);
const tagTypeStore = new TagTypeStore(db, eventBus, getLogger);
const projectStore = new ProjectStore(db, eventBus, config);
const projectStore = new ProjectStore(
db,
eventBus,
getLogger,
flagResolver,
);
const featureTagStore = new FeatureTagStore(db, eventBus, getLogger);
const strategyStore = new StrategyStore(db, getLogger);
const contextFieldStore = new ContextFieldStore(
Expand All @@ -167,7 +172,7 @@ export const deferredExportImportTogglesService = (
const featureEnvironmentStore = new FeatureEnvironmentStore(
db,
eventBus,
config,
getLogger,
);
const eventStore = new EventStore(db, getLogger);
const accessService = createAccessService(db, config);
Expand Down
4 changes: 2 additions & 2 deletions src/lib/features/feature-lifecycle/createFeatureLifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ export const createFeatureLifecycleService =
const { eventBus, getLogger } = config;
const eventStore = new EventStore(db, getLogger);
const featureLifecycleStore = new FeatureLifecycleStore(db);
const environmentStore = new EnvironmentStore(db, eventBus, config);
const environmentStore = new EnvironmentStore(db, eventBus, getLogger);
const featureEnvironmentStore = new FeatureEnvironmentStore(
db,
eventBus,
config,
getLogger,
);
const eventService = createEventsService(db, config);
const featureLifecycleService = new FeatureLifecycleService(
Expand Down
14 changes: 10 additions & 4 deletions src/lib/features/feature-toggle/createFeatureToggleService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,19 @@ export const createFeatureToggleService = (
const featureToggleClientStore = new FeatureToggleClientStore(
db,
eventBus,
config,
getLogger,
flagResolver,
);
const projectStore = new ProjectStore(
db,
eventBus,
getLogger,
flagResolver,
);
const projectStore = new ProjectStore(db, eventBus, config);
const featureEnvironmentStore = new FeatureEnvironmentStore(
db,
eventBus,
config,
getLogger,
);
const contextFieldStore = new ContextFieldStore(
db,
Expand All @@ -99,7 +105,7 @@ export const createFeatureToggleService = (
const accessStore = new AccessStore(db, eventBus, getLogger);
const featureTagStore = new FeatureTagStore(db, eventBus, getLogger);
const roleStore = new RoleStore(db, eventBus, getLogger);
const environmentStore = new EnvironmentStore(db, eventBus, config);
const environmentStore = new EnvironmentStore(db, eventBus, getLogger);
const eventService = createEventsService(db, config);
const groupService = new GroupService(
{ groupStore, accountStore },
Expand Down
10 changes: 0 additions & 10 deletions src/lib/features/feature-toggle/feature-toggle-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,16 +439,6 @@ export default class FeatureToggleStore implements IFeatureToggleStore {
: queryBuilder.whereNull('archived_at');
};

static filterByProjectsAccessibleByOss: Knex.QueryCallbackWithArgs = (
queryBuilder: Knex.QueryBuilder,
isOss: boolean,
) => {
if (isOss) {
return queryBuilder.andWhere('project', '=', 'default');
}
return queryBuilder;
};

rowToFeature(row: FeaturesTable): FeatureToggle {
if (!row) {
throw new NotFoundError('No feature flag found');
Expand Down
9 changes: 7 additions & 2 deletions src/lib/features/instance-stats/createInstanceStatsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,13 @@ export const createInstanceStatsService = (db: Db, config: IUnleashConfig) => {
flagResolver,
);
const userStore = new UserStore(db, getLogger, flagResolver);
const projectStore = new ProjectStore(db, eventBus, config);
const environmentStore = new EnvironmentStore(db, eventBus, config);
const projectStore = new ProjectStore(
db,
eventBus,
getLogger,
flagResolver,
);
const environmentStore = new EnvironmentStore(db, eventBus, getLogger);
const strategyStore = new StrategyStore(db, getLogger);
const contextFieldStore = new ContextFieldStore(
db,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,21 @@ export const createEnvironmentService =
const featureEnvironmentStore = new FeatureEnvironmentStore(
db,
eventBus,
config,
getLogger,
);
const projectStore = new ProjectStore(
db,
eventBus,
getLogger,
flagResolver,
);
const projectStore = new ProjectStore(db, eventBus, config);
const featureStrategiesStore = new FeatureStrategiesStore(
db,
eventBus,
getLogger,
flagResolver,
);
const environmentStore = new EnvironmentStore(db, eventBus, config);
const environmentStore = new EnvironmentStore(db, eventBus, getLogger);
const eventService = createEventsService(db, config);
return new EnvironmentService(
{
Expand Down
Loading
Loading