1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-11 00:08:30 +01:00

chore: adds killswitch to scheduled per sec caches (#6291)

## About the changes

Adds killswitches to update revision id and publish unpublished events
This commit is contained in:
David Leek 2024-02-21 10:12:23 +01:00 committed by GitHub
parent c7182d8faf
commit 869e33138b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 42 additions and 4 deletions

View File

@ -85,6 +85,8 @@ exports[`should create default config 1`] = `
"disableBulkToggle": false,
"disableMetrics": false,
"disableNotifications": false,
"disablePublishUnannouncedEvents": false,
"disableUpdateMaxRevisionId": false,
"edgeBulkMetrics": false,
"embedProxy": true,
"embedProxyFrontend": true,

View File

@ -1,6 +1,11 @@
import { EventEmitter } from 'stream';
import { Logger } from '../../logger';
import { IEventStore, IUnleashConfig, IUnleashStores } from '../../types';
import {
IEventStore,
IFlagResolver,
IUnleashConfig,
IUnleashStores,
} from '../../types';
export const UPDATE_REVISION = 'UPDATE_REVISION';
@ -11,13 +16,19 @@ export default class ConfigurationRevisionService extends EventEmitter {
private revisionId: number;
private flagResolver: IFlagResolver;
constructor(
{ eventStore }: Pick<IUnleashStores, 'eventStore'>,
{ getLogger }: Pick<IUnleashConfig, 'getLogger'>,
{
getLogger,
flagResolver,
}: Pick<IUnleashConfig, 'getLogger' | 'flagResolver'>,
) {
super();
this.logger = getLogger('configuration-revision-service.ts');
this.eventStore = eventStore;
this.flagResolver = flagResolver;
this.revisionId = 0;
}
@ -30,6 +41,10 @@ export default class ConfigurationRevisionService extends EventEmitter {
}
async updateMaxRevisionId(): Promise<number> {
if (this.flagResolver.isEnabled('disableUpdateMaxRevisionId')) {
return 0;
}
const revisionId = await this.eventStore.getMaxRevisionId(
this.revisionId,
);

View File

@ -2,21 +2,32 @@ import { IUnleashConfig } from '../types/option';
import { IUnleashStores } from '../types/stores';
import { Logger } from '../logger';
import { IEventStore } from '../types/stores/event-store';
import { IFlagResolver } from '../types';
export default class EventAnnouncer {
private logger: Logger;
private eventStore: IEventStore;
private flagResolver: IFlagResolver;
constructor(
{ eventStore }: Pick<IUnleashStores, 'eventStore'>,
{ getLogger }: Pick<IUnleashConfig, 'getLogger'>,
{
getLogger,
flagResolver,
}: Pick<IUnleashConfig, 'getLogger' | 'flagResolver'>,
) {
this.logger = getLogger('services/event-service.ts');
this.flagResolver = flagResolver;
this.eventStore = eventStore;
}
async publishUnannouncedEvents(): Promise<void> {
return this.eventStore.publishUnannouncedEvents();
if (this.flagResolver.isEnabled('disablePublishUnannouncedEvents')) {
return Promise.resolve();
} else {
return this.eventStore.publishUnannouncedEvents();
}
}
}

View File

@ -50,6 +50,8 @@ export type IFlagKey =
| 'collectTrafficDataUsage'
| 'useMemoizedActiveTokens'
| 'userAccessUIEnabled'
| 'disableUpdateMaxRevisionId'
| 'disablePublishUnannouncedEvents'
| 'sdkReporting';
export type IFlags = Partial<{ [key in IFlagKey]: boolean | Variant }>;
@ -247,6 +249,14 @@ const flags: IFlags = {
process.env.UNLEASH_EXPERIMENTAL_USER_ACCESS_UI_ENABLED,
false,
),
disableUpdateMaxRevisionId: parseEnvVarBoolean(
process.env.UNLEASH_EXPERIMENTAL_DISABLE_SCHEDULED_CACHES,
false,
),
disablePublishUnannouncedEvents: parseEnvVarBoolean(
process.env.UNLEASH_EXPERIMENTAL_DISABLE_SCHEDULED_CACHES,
false,
),
};
export const defaultExperimentalOptions: IExperimentalOptions = {