From 869e33138bb5bd3302cf29a8cfd5e158bbd9e049 Mon Sep 17 00:00:00 2001 From: David Leek Date: Wed, 21 Feb 2024 10:12:23 +0100 Subject: [PATCH] chore: adds killswitch to scheduled per sec caches (#6291) ## About the changes Adds killswitches to update revision id and publish unpublished events --- .../__snapshots__/create-config.test.ts.snap | 2 ++ .../configuration-revision-service.ts | 19 +++++++++++++++++-- src/lib/services/event-announcer-service.ts | 15 +++++++++++++-- src/lib/types/experimental.ts | 10 ++++++++++ 4 files changed, 42 insertions(+), 4 deletions(-) diff --git a/src/lib/__snapshots__/create-config.test.ts.snap b/src/lib/__snapshots__/create-config.test.ts.snap index 1750a7f480..1319d83d6e 100644 --- a/src/lib/__snapshots__/create-config.test.ts.snap +++ b/src/lib/__snapshots__/create-config.test.ts.snap @@ -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, diff --git a/src/lib/features/feature-toggle/configuration-revision-service.ts b/src/lib/features/feature-toggle/configuration-revision-service.ts index 3c145bc60a..7deaf447af 100644 --- a/src/lib/features/feature-toggle/configuration-revision-service.ts +++ b/src/lib/features/feature-toggle/configuration-revision-service.ts @@ -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, - { getLogger }: Pick, + { + getLogger, + flagResolver, + }: Pick, ) { 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 { + if (this.flagResolver.isEnabled('disableUpdateMaxRevisionId')) { + return 0; + } + const revisionId = await this.eventStore.getMaxRevisionId( this.revisionId, ); diff --git a/src/lib/services/event-announcer-service.ts b/src/lib/services/event-announcer-service.ts index 6cc5c5154d..0c744a7e25 100644 --- a/src/lib/services/event-announcer-service.ts +++ b/src/lib/services/event-announcer-service.ts @@ -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, - { getLogger }: Pick, + { + getLogger, + flagResolver, + }: Pick, ) { this.logger = getLogger('services/event-service.ts'); + this.flagResolver = flagResolver; this.eventStore = eventStore; } async publishUnannouncedEvents(): Promise { - return this.eventStore.publishUnannouncedEvents(); + if (this.flagResolver.isEnabled('disablePublishUnannouncedEvents')) { + return Promise.resolve(); + } else { + return this.eventStore.publishUnannouncedEvents(); + } } } diff --git a/src/lib/types/experimental.ts b/src/lib/types/experimental.ts index 5047f0f4a5..40b79313fe 100644 --- a/src/lib/types/experimental.ts +++ b/src/lib/types/experimental.ts @@ -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 = {