mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-20 00:08:02 +01: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 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[];
|
||||
const toggles: ProxyFeatureSchema[] =
|
||||
await this.services.proxyService.getProxyFeatures(
|
||||
req.user,
|
||||
FrontendAPIController.createContext(req),
|
||||
);
|
||||
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(
|
||||
req.user,
|
||||
FrontendAPIController.createContext(req),
|
||||
);
|
||||
// deliberately run comparison without blocking
|
||||
void this.services.proxyService.compareToggleDefinitions(req.user);
|
||||
}
|
||||
|
||||
res.set('Cache-control', 'no-cache');
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user