mirror of
https://github.com/Unleash/unleash.git
synced 2025-06-09 01:17:06 +02:00
feat: compare feture definitions not evaluations (#6486)
This commit is contained in:
parent
48fa39c9fc
commit
17ea8b3734
@ -21,7 +21,6 @@ import NotImplementedError from '../error/not-implemented-error';
|
|||||||
import NotFoundError from '../error/notfound-error';
|
import NotFoundError from '../error/notfound-error';
|
||||||
import rateLimit from 'express-rate-limit';
|
import rateLimit from 'express-rate-limit';
|
||||||
import { minutesToMilliseconds } from 'date-fns';
|
import { minutesToMilliseconds } from 'date-fns';
|
||||||
import isEqual from 'lodash.isequal';
|
|
||||||
|
|
||||||
interface ApiUserRequest<
|
interface ApiUserRequest<
|
||||||
PARAM = any,
|
PARAM = any,
|
||||||
@ -175,34 +174,14 @@ export default class FrontendAPIController extends Controller {
|
|||||||
if (!this.config.flagResolver.isEnabled('embedProxy')) {
|
if (!this.config.flagResolver.isEnabled('embedProxy')) {
|
||||||
throw new NotFoundError();
|
throw new NotFoundError();
|
||||||
}
|
}
|
||||||
let toggles: ProxyFeatureSchema[];
|
const toggles: ProxyFeatureSchema[] =
|
||||||
let newToggles: ProxyFeatureSchema[];
|
await this.services.proxyService.getProxyFeatures(
|
||||||
|
req.user,
|
||||||
|
FrontendAPIController.createContext(req),
|
||||||
|
);
|
||||||
if (this.config.flagResolver.isEnabled('globalFrontendApiCache')) {
|
if (this.config.flagResolver.isEnabled('globalFrontendApiCache')) {
|
||||||
[toggles, newToggles] = await Promise.all([
|
// deliberately run comparison without blocking
|
||||||
this.services.proxyService.getProxyFeatures(
|
void this.services.proxyService.compareToggleDefinitions(req.user);
|
||||||
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(
|
|
||||||
req.user,
|
|
||||||
FrontendAPIController.createContext(req),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
res.set('Cache-control', 'no-cache');
|
res.set('Cache-control', 'no-cache');
|
||||||
|
@ -19,6 +19,7 @@ import { PROXY_REPOSITORY_CREATED } from '../metric-events';
|
|||||||
import { ProxyRepository } from './index';
|
import { ProxyRepository } from './index';
|
||||||
import { FrontendApiRepository } from './frontend-api-repository';
|
import { FrontendApiRepository } from './frontend-api-repository';
|
||||||
import { GlobalFrontendApiCache } from './global-frontend-api-cache';
|
import { GlobalFrontendApiCache } from './global-frontend-api-cache';
|
||||||
|
import isEqual from 'lodash.isequal';
|
||||||
|
|
||||||
export type Config = Pick<
|
export type Config = Pick<
|
||||||
IUnleashConfig,
|
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(
|
async getNewProxyFeatures(
|
||||||
token: IApiUser,
|
token: IApiUser,
|
||||||
context: Context,
|
context: Context,
|
||||||
|
Loading…
Reference in New Issue
Block a user