1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-02-09 00:18:00 +01:00

feat: log warning if there is diff between client/features and delta api (#9047)

Log out the diff and warn if there is gap between old logic and new
delta.
This commit is contained in:
Jaanus Sellin 2025-01-02 12:59:33 +02:00 committed by GitHub
parent e0b4e258dc
commit 54d6bd5b86
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -39,6 +39,8 @@ import {
CLIENT_METRICS_NAMEPREFIX,
CLIENT_METRICS_TAGS,
} from '../../internals';
import isEqual from 'lodash.isequal';
import { diff } from 'json-diff';
const version = 2;
@ -180,10 +182,31 @@ export default class FeatureController extends Controller {
featuresSize + segmentsSize,
);
await this.clientFeatureToggleService.getClientDelta(
undefined,
query!,
const delta =
await this.clientFeatureToggleService.getClientDelta(
undefined,
query!,
);
const sortedToggles = features.sort((a, b) =>
a.name.localeCompare(b.name),
);
const sortedNewToggles = delta?.updated.sort((a, b) =>
a.name.localeCompare(b.name),
);
if (
!this.deepEqualIgnoreOrder(sortedToggles, sortedNewToggles)
) {
this.logger.warn(
`old features and new features are different. Old count ${
features.length
}, new count ${delta?.updated.length}, query ${JSON.stringify(query)},
diff ${JSON.stringify(
diff(sortedToggles, sortedNewToggles),
)}`,
);
}
this.storeFootprint();
} catch (e) {
this.logger.error('Delta diff failed', e);
@ -376,4 +399,14 @@ export default class FeatureController extends Controller {
const jsonString = JSON.stringify(value);
return Buffer.byteLength(jsonString, 'utf8');
}
deepEqualIgnoreOrder = (obj1, obj2) => {
const sortedObj1 = JSON.parse(
JSON.stringify(obj1, Object.keys(obj1).sort()),
);
const sortedObj2 = JSON.parse(
JSON.stringify(obj2, Object.keys(obj2).sort()),
);
return isEqual(sortedObj1, sortedObj2);
};
}