mirror of
https://github.com/Unleash/unleash.git
synced 2024-12-22 19:07:54 +01:00
fix: Configuration revision service singleton (#6493)
This commit is contained in:
parent
c841e72244
commit
eae373f386
@ -1,4 +1,3 @@
|
|||||||
import { EventEmitter } from 'stream';
|
|
||||||
import { Logger } from '../../logger';
|
import { Logger } from '../../logger';
|
||||||
import {
|
import {
|
||||||
IEventStore,
|
IEventStore,
|
||||||
@ -6,10 +5,13 @@ import {
|
|||||||
IUnleashConfig,
|
IUnleashConfig,
|
||||||
IUnleashStores,
|
IUnleashStores,
|
||||||
} from '../../types';
|
} from '../../types';
|
||||||
|
import EventEmitter from 'events';
|
||||||
|
|
||||||
export const UPDATE_REVISION = 'UPDATE_REVISION';
|
export const UPDATE_REVISION = 'UPDATE_REVISION';
|
||||||
|
|
||||||
export default class ConfigurationRevisionService extends EventEmitter {
|
export default class ConfigurationRevisionService extends EventEmitter {
|
||||||
|
private static instance: ConfigurationRevisionService;
|
||||||
|
|
||||||
private logger: Logger;
|
private logger: Logger;
|
||||||
|
|
||||||
private eventStore: IEventStore;
|
private eventStore: IEventStore;
|
||||||
@ -18,7 +20,7 @@ export default class ConfigurationRevisionService extends EventEmitter {
|
|||||||
|
|
||||||
private flagResolver: IFlagResolver;
|
private flagResolver: IFlagResolver;
|
||||||
|
|
||||||
constructor(
|
private constructor(
|
||||||
{ eventStore }: Pick<IUnleashStores, 'eventStore'>,
|
{ eventStore }: Pick<IUnleashStores, 'eventStore'>,
|
||||||
{
|
{
|
||||||
getLogger,
|
getLogger,
|
||||||
@ -32,6 +34,23 @@ export default class ConfigurationRevisionService extends EventEmitter {
|
|||||||
this.revisionId = 0;
|
this.revisionId = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static getInstance(
|
||||||
|
{ eventStore }: Pick<IUnleashStores, 'eventStore'>,
|
||||||
|
{
|
||||||
|
getLogger,
|
||||||
|
flagResolver,
|
||||||
|
}: Pick<IUnleashConfig, 'getLogger' | 'flagResolver'>,
|
||||||
|
) {
|
||||||
|
if (!ConfigurationRevisionService.instance) {
|
||||||
|
ConfigurationRevisionService.instance =
|
||||||
|
new ConfigurationRevisionService(
|
||||||
|
{ eventStore },
|
||||||
|
{ getLogger, flagResolver },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return ConfigurationRevisionService.instance;
|
||||||
|
}
|
||||||
|
|
||||||
async getMaxRevisionId(): Promise<number> {
|
async getMaxRevisionId(): Promise<number> {
|
||||||
if (this.revisionId > 0) {
|
if (this.revisionId > 0) {
|
||||||
return this.revisionId;
|
return this.revisionId;
|
||||||
|
@ -10,12 +10,10 @@ import {
|
|||||||
createFeatureToggleService,
|
createFeatureToggleService,
|
||||||
} from '../features';
|
} from '../features';
|
||||||
import ConfigurationRevisionService from '../features/feature-toggle/configuration-revision-service';
|
import ConfigurationRevisionService from '../features/feature-toggle/configuration-revision-service';
|
||||||
import EventStore from '../features/events/event-store';
|
|
||||||
import { GlobalFrontendApiCache } from './global-frontend-api-cache';
|
import { GlobalFrontendApiCache } from './global-frontend-api-cache';
|
||||||
import ClientFeatureToggleReadModel from './client-feature-toggle-read-model';
|
import ClientFeatureToggleReadModel from './client-feature-toggle-read-model';
|
||||||
import { FakeSegmentReadModel } from '../features/segment/fake-segment-read-model';
|
import { FakeSegmentReadModel } from '../features/segment/fake-segment-read-model';
|
||||||
import FakeSettingStore from '../../test/fixtures/fake-setting-store';
|
import FakeSettingStore from '../../test/fixtures/fake-setting-store';
|
||||||
import FakeEventStore from '../../test/fixtures/fake-event-store';
|
|
||||||
import FakeClientFeatureToggleReadModel from './fake-client-feature-toggle-read-model';
|
import FakeClientFeatureToggleReadModel from './fake-client-feature-toggle-read-model';
|
||||||
import { IUnleashConfig } from '../types';
|
import { IUnleashConfig } from '../types';
|
||||||
import { Db } from '../db/db';
|
import { Db } from '../db/db';
|
||||||
@ -25,6 +23,7 @@ export const createProxyService = (
|
|||||||
config: IUnleashConfig,
|
config: IUnleashConfig,
|
||||||
// client metrics service needs to be shared because it uses in-memory cache
|
// client metrics service needs to be shared because it uses in-memory cache
|
||||||
clientMetricsServiceV2: ClientMetricsServiceV2,
|
clientMetricsServiceV2: ClientMetricsServiceV2,
|
||||||
|
configurationRevisionService: ConfigurationRevisionService,
|
||||||
): ProxyService => {
|
): ProxyService => {
|
||||||
const segmentReadModel = new SegmentReadModel(db);
|
const segmentReadModel = new SegmentReadModel(db);
|
||||||
const settingStore = new SettingStore(db, config.getLogger);
|
const settingStore = new SettingStore(db, config.getLogger);
|
||||||
@ -36,15 +35,6 @@ export const createProxyService = (
|
|||||||
);
|
);
|
||||||
// TODO: remove this dependency after we migrate frontend API
|
// TODO: remove this dependency after we migrate frontend API
|
||||||
const featureToggleServiceV2 = createFeatureToggleService(db, config);
|
const featureToggleServiceV2 = createFeatureToggleService(db, config);
|
||||||
const eventStore = new EventStore(
|
|
||||||
db,
|
|
||||||
config.getLogger,
|
|
||||||
config.flagResolver,
|
|
||||||
);
|
|
||||||
const configurationRevisionService = new ConfigurationRevisionService(
|
|
||||||
{ eventStore },
|
|
||||||
config,
|
|
||||||
);
|
|
||||||
const clientFeatureToggleReadModel = new ClientFeatureToggleReadModel(
|
const clientFeatureToggleReadModel = new ClientFeatureToggleReadModel(
|
||||||
db,
|
db,
|
||||||
config.eventBus,
|
config.eventBus,
|
||||||
@ -71,6 +61,7 @@ export const createProxyService = (
|
|||||||
export const createFakeProxyService = (
|
export const createFakeProxyService = (
|
||||||
config: IUnleashConfig,
|
config: IUnleashConfig,
|
||||||
clientMetricsServiceV2: ClientMetricsServiceV2,
|
clientMetricsServiceV2: ClientMetricsServiceV2,
|
||||||
|
configurationRevisionService: ConfigurationRevisionService,
|
||||||
): ProxyService => {
|
): ProxyService => {
|
||||||
const segmentReadModel = new FakeSegmentReadModel();
|
const segmentReadModel = new FakeSegmentReadModel();
|
||||||
const settingStore = new FakeSettingStore();
|
const settingStore = new FakeSettingStore();
|
||||||
@ -82,11 +73,6 @@ export const createFakeProxyService = (
|
|||||||
);
|
);
|
||||||
// TODO: remove this dependency after we migrate frontend API
|
// TODO: remove this dependency after we migrate frontend API
|
||||||
const featureToggleServiceV2 = createFakeFeatureToggleService(config);
|
const featureToggleServiceV2 = createFakeFeatureToggleService(config);
|
||||||
const eventStore = new FakeEventStore();
|
|
||||||
const configurationRevisionService = new ConfigurationRevisionService(
|
|
||||||
{ eventStore },
|
|
||||||
config,
|
|
||||||
);
|
|
||||||
const clientFeatureToggleReadModel = new FakeClientFeatureToggleReadModel();
|
const clientFeatureToggleReadModel = new FakeClientFeatureToggleReadModel();
|
||||||
const globalFrontendApiCache = new GlobalFrontendApiCache(
|
const globalFrontendApiCache = new GlobalFrontendApiCache(
|
||||||
config,
|
config,
|
||||||
|
@ -111,9 +111,10 @@ import {
|
|||||||
import { InactiveUsersService } from '../users/inactive/inactive-users-service';
|
import { InactiveUsersService } from '../users/inactive/inactive-users-service';
|
||||||
import { SegmentReadModel } from '../features/segment/segment-read-model';
|
import { SegmentReadModel } from '../features/segment/segment-read-model';
|
||||||
import { FakeSegmentReadModel } from '../features/segment/fake-segment-read-model';
|
import { FakeSegmentReadModel } from '../features/segment/fake-segment-read-model';
|
||||||
import ClientFeatureToggleReadModel from '../proxy/client-feature-toggle-read-model';
|
import {
|
||||||
import FakeClientFeatureToggleReadModel from '../proxy/fake-client-feature-toggle-read-model';
|
createFakeProxyService,
|
||||||
import { GlobalFrontendApiCache } from '../proxy/global-frontend-api-cache';
|
createProxyService,
|
||||||
|
} from '../proxy/createProxyService';
|
||||||
|
|
||||||
export const createServices = (
|
export const createServices = (
|
||||||
stores: IUnleashStores,
|
stores: IUnleashStores,
|
||||||
@ -287,35 +288,24 @@ export const createServices = (
|
|||||||
segmentReadModel,
|
segmentReadModel,
|
||||||
);
|
);
|
||||||
|
|
||||||
const configurationRevisionService = new ConfigurationRevisionService(
|
const configurationRevisionService =
|
||||||
stores,
|
ConfigurationRevisionService.getInstance(stores, config);
|
||||||
config,
|
|
||||||
);
|
|
||||||
|
|
||||||
const clientFeatureToggleService = db
|
const clientFeatureToggleService = db
|
||||||
? createClientFeatureToggleService(db, config)
|
? createClientFeatureToggleService(db, config)
|
||||||
: createFakeClientFeatureToggleService(config);
|
: createFakeClientFeatureToggleService(config);
|
||||||
|
|
||||||
const clientFeatureToggleReadModel = db
|
const proxyService = db
|
||||||
? new ClientFeatureToggleReadModel(db, config.eventBus)
|
? createProxyService(
|
||||||
: new FakeClientFeatureToggleReadModel();
|
db,
|
||||||
const globalFrontendApiCache = new GlobalFrontendApiCache(
|
config,
|
||||||
|
clientMetricsServiceV2,
|
||||||
|
configurationRevisionService,
|
||||||
|
)
|
||||||
|
: createFakeProxyService(
|
||||||
config,
|
config,
|
||||||
segmentReadModel,
|
|
||||||
clientFeatureToggleReadModel,
|
|
||||||
configurationRevisionService,
|
|
||||||
);
|
|
||||||
|
|
||||||
const proxyService = new ProxyService(
|
|
||||||
config,
|
|
||||||
stores,
|
|
||||||
{
|
|
||||||
featureToggleServiceV2,
|
|
||||||
clientMetricsServiceV2,
|
clientMetricsServiceV2,
|
||||||
settingService,
|
|
||||||
configurationRevisionService,
|
configurationRevisionService,
|
||||||
},
|
|
||||||
globalFrontendApiCache,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
const edgeService = new EdgeService({ apiTokenService }, config);
|
const edgeService = new EdgeService({ apiTokenService }, config);
|
||||||
|
Loading…
Reference in New Issue
Block a user