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:
parent
e0b4e258dc
commit
54d6bd5b86
@ -39,6 +39,8 @@ import {
|
|||||||
CLIENT_METRICS_NAMEPREFIX,
|
CLIENT_METRICS_NAMEPREFIX,
|
||||||
CLIENT_METRICS_TAGS,
|
CLIENT_METRICS_TAGS,
|
||||||
} from '../../internals';
|
} from '../../internals';
|
||||||
|
import isEqual from 'lodash.isequal';
|
||||||
|
import { diff } from 'json-diff';
|
||||||
|
|
||||||
const version = 2;
|
const version = 2;
|
||||||
|
|
||||||
@ -180,10 +182,31 @@ export default class FeatureController extends Controller {
|
|||||||
featuresSize + segmentsSize,
|
featuresSize + segmentsSize,
|
||||||
);
|
);
|
||||||
|
|
||||||
await this.clientFeatureToggleService.getClientDelta(
|
const delta =
|
||||||
undefined,
|
await this.clientFeatureToggleService.getClientDelta(
|
||||||
query!,
|
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();
|
this.storeFootprint();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.logger.error('Delta diff failed', e);
|
this.logger.error('Delta diff failed', e);
|
||||||
@ -376,4 +399,14 @@ export default class FeatureController extends Controller {
|
|||||||
const jsonString = JSON.stringify(value);
|
const jsonString = JSON.stringify(value);
|
||||||
return Buffer.byteLength(jsonString, 'utf8');
|
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);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user