diff --git a/src/lib/proxy/proxy-controller.ts b/src/lib/proxy/proxy-controller.ts index fd8ac1d68e..3d233aa3f3 100644 --- a/src/lib/proxy/proxy-controller.ts +++ b/src/lib/proxy/proxy-controller.ts @@ -21,7 +21,6 @@ import NotImplementedError from '../error/not-implemented-error'; import NotFoundError from '../error/notfound-error'; import rateLimit from 'express-rate-limit'; import { minutesToMilliseconds } from 'date-fns'; -import isEqual from 'lodash.isequal'; interface ApiUserRequest< PARAM = any, @@ -175,34 +174,14 @@ export default class FrontendAPIController extends Controller { if (!this.config.flagResolver.isEnabled('embedProxy')) { throw new NotFoundError(); } - let toggles: ProxyFeatureSchema[]; - let newToggles: ProxyFeatureSchema[]; - if (this.config.flagResolver.isEnabled('globalFrontendApiCache')) { - [toggles, newToggles] = await Promise.all([ - this.services.proxyService.getProxyFeatures( - req.user, - FrontendAPIController.createContext(req), - ), - this.services.proxyService.getNewProxyFeatures( - req.user, - FrontendAPIController.createContext(req), - ), - ]); - if ( - !isEqual( - toggles.sort((a, b) => a.name.localeCompare(b.name)), - newToggles.sort((a, b) => a.name.localeCompare(b.name)), - ) - ) { - this.logger.warn( - `old features and new features are different. Old count ${toggles.length}, new count ${newToggles.length}`, - ); - } - } else { - toggles = await this.services.proxyService.getProxyFeatures( + const toggles: ProxyFeatureSchema[] = + await this.services.proxyService.getProxyFeatures( req.user, FrontendAPIController.createContext(req), ); + if (this.config.flagResolver.isEnabled('globalFrontendApiCache')) { + // deliberately run comparison without blocking + void this.services.proxyService.compareToggleDefinitions(req.user); } res.set('Cache-control', 'no-cache'); diff --git a/src/lib/proxy/proxy-service.ts b/src/lib/proxy/proxy-service.ts index eb6c6bfaef..9a88df2a7c 100644 --- a/src/lib/proxy/proxy-service.ts +++ b/src/lib/proxy/proxy-service.ts @@ -19,6 +19,7 @@ import { PROXY_REPOSITORY_CREATED } from '../metric-events'; import { ProxyRepository } from './index'; import { FrontendApiRepository } from './frontend-api-repository'; import { GlobalFrontendApiCache } from './global-frontend-api-cache'; +import isEqual from 'lodash.isequal'; export type Config = Pick< IUnleashConfig, @@ -94,6 +95,25 @@ export class ProxyService { })); } + async compareToggleDefinitions(token: IApiUser) { + const oldClient = await this.clientForProxyToken(token); + const oldDefinitions = oldClient.getFeatureToggleDefinitions() || []; + + const newClient = await this.newClientForProxyToken(token); + const newDefinitions = newClient.getFeatureToggleDefinitions() || []; + + if ( + !isEqual( + oldDefinitions.sort((a, b) => a.name.localeCompare(b.name)), + newDefinitions.sort((a, b) => a.name.localeCompare(b.name)), + ) + ) { + this.logger.warn( + `old features definitions and new features definitions are different. Old definitions count ${oldDefinitions.length}, new count ${newDefinitions.length}`, + ); + } + } + async getNewProxyFeatures( token: IApiUser, context: Context,