[ML] Explain Log Rate Spikes: Fix item set post processing. (#147499)

Fixes cases where the item set post processing would end up with duplicate entries.
This commit is contained in:
Walter Rafelsberger 2022-12-16 09:21:47 +01:00 committed by GitHub
parent de68ffa036
commit 6a87f7e844
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 4 deletions

View file

@ -6,6 +6,7 @@
*/
import { queue } from 'async';
import { uniqWith, isEqual } from 'lodash';
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
@ -477,8 +478,8 @@ export const defineExplainLogRateSpikesRoute = (
// field/value pairs that are not part of the original list of significant change points.
// This cleans up groups and removes those unrelated field/value pairs.
const filteredDf = df
.map((fi) => {
fi.set = Object.entries(fi.set).reduce<ItemsetResult['set']>(
.map((fi, fiIndex) => {
const updatedSet = Object.entries(fi.set).reduce<ItemsetResult['set']>(
(set, [field, value]) => {
if (
changePoints.some(
@ -491,7 +492,16 @@ export const defineExplainLogRateSpikesRoute = (
},
{}
);
// only assign the updated reduced set if it doesn't already match
// an existing set. if there's a match just add an empty set
// so it will be filtered in the last step.
fi.set = df.some((d, dIndex) => fiIndex !== dIndex && isEqual(fi.set, d.set))
? {}
: updatedSet;
fi.size = Object.keys(fi.set).length;
return fi;
})
.filter((fi) => fi.size > 1);
@ -540,7 +550,7 @@ export const defineExplainLogRateSpikesRoute = (
return {
...g,
group,
group: uniqWith(group, (a, b) => isEqual(a, b)),
};
}
);

View file

@ -138,7 +138,6 @@ export const explainLogRateSpikesTestData: TestData[] = [
group: [
{ fieldName: 'response_code', fieldValue: '500', duplicate: false },
{ fieldName: 'url', fieldValue: 'home.php', duplicate: false },
{ fieldName: 'url', fieldValue: 'home.php', duplicate: false },
{ fieldName: 'url', fieldValue: 'login.php', duplicate: false },
],
docCount: 792,