mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
# Backport This will backport the following commits from `main` to `8.14`: - [[ML] Fixing issue with empty object creation (#186821)](https://github.com/elastic/kibana/pull/186821) <!--- Backport version: 9.4.3 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"James Gowdy","email":"jgowdy@elastic.co"},"sourceCommit":{"committedDate":"2024-06-25T15:23:25Z","message":"[ML] Fixing issue with empty object creation (#186821)\n\nUsing `Object.create(null)` when creating objects for the anomaly\r\nresults table.","sha":"8e76b0b113089c793e4dba77610f90540ec9b8da","branchLabelMapping":{"^v8.15.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix",":ml","Feature:Anomaly Detection","v8.15.0","v7.17.23","v8.14.2"],"title":"[ML] Fixing issue with empty object creation","number":186821,"url":"https://github.com/elastic/kibana/pull/186821","mergeCommit":{"message":"[ML] Fixing issue with empty object creation (#186821)\n\nUsing `Object.create(null)` when creating objects for the anomaly\r\nresults table.","sha":"8e76b0b113089c793e4dba77610f90540ec9b8da"}},"sourceBranch":"main","suggestedTargetBranches":["7.17","8.14"],"targetPullRequestStates":[{"branch":"main","label":"v8.15.0","branchLabelMappingKey":"^v8.15.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/186821","number":186821,"mergeCommit":{"message":"[ML] Fixing issue with empty object creation (#186821)\n\nUsing `Object.create(null)` when creating objects for the anomaly\r\nresults table.","sha":"8e76b0b113089c793e4dba77610f90540ec9b8da"}},{"branch":"7.17","label":"v7.17.23","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.14","label":"v8.14.2","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: James Gowdy <jgowdy@elastic.co>
This commit is contained in:
parent
f4511f7b0e
commit
e8004f843b
1 changed files with 12 additions and 7 deletions
|
@ -125,7 +125,7 @@ function aggregateAnomalies(anomalyRecords, interval, dateFormatTz) {
|
|||
return [];
|
||||
}
|
||||
|
||||
const aggregatedData = {};
|
||||
const aggregatedData = Object.create(null);
|
||||
anomalyRecords.forEach((record) => {
|
||||
// Use moment.js to get start of interval.
|
||||
const roundedTime =
|
||||
|
@ -133,27 +133,32 @@ function aggregateAnomalies(anomalyRecords, interval, dateFormatTz) {
|
|||
? moment(record.timestamp).tz(dateFormatTz).startOf(interval).valueOf()
|
||||
: moment(record.timestamp).startOf(interval).valueOf();
|
||||
if (aggregatedData[roundedTime] === undefined) {
|
||||
aggregatedData[roundedTime] = {};
|
||||
aggregatedData[roundedTime] = Object.create(null);
|
||||
}
|
||||
|
||||
// Aggregate by job, then detectorIndex.
|
||||
const jobId = record.job_id;
|
||||
const jobsAtTime = aggregatedData[roundedTime];
|
||||
if (jobsAtTime[jobId] === undefined) {
|
||||
jobsAtTime[jobId] = {};
|
||||
if (jobsAtTime[jobId] === undefined || Object.hasOwn(jobsAtTime, jobId) === false) {
|
||||
jobsAtTime[jobId] = Object.create(null);
|
||||
}
|
||||
|
||||
// Aggregate by detector - default to function_description if no description available.
|
||||
const detectorIndex = record.detector_index;
|
||||
if (typeof detectorIndex !== 'number') {
|
||||
return;
|
||||
}
|
||||
const detectorsForJob = jobsAtTime[jobId];
|
||||
if (detectorsForJob[detectorIndex] === undefined) {
|
||||
detectorsForJob[detectorIndex] = {};
|
||||
detectorsForJob[detectorIndex] = Object.create(null);
|
||||
}
|
||||
|
||||
// Now add an object for the anomaly with the highest anomaly score per entity.
|
||||
// For the choice of entity, look in order for byField, overField, partitionField.
|
||||
// If no by/over/partition, default to an empty String.
|
||||
const entitiesForDetector = detectorsForJob[detectorIndex];
|
||||
const entitiesForDetector = Object.hasOwn(detectorsForJob, detectorIndex)
|
||||
? detectorsForJob[detectorIndex]
|
||||
: Object.create(null);
|
||||
|
||||
// TODO - are we worried about different byFields having the same
|
||||
// value e.g. host=server1 and machine=server1?
|
||||
|
@ -163,7 +168,7 @@ function aggregateAnomalies(anomalyRecords, interval, dateFormatTz) {
|
|||
}
|
||||
if (entitiesForDetector[entity] === undefined) {
|
||||
entitiesForDetector[entity] = record;
|
||||
} else {
|
||||
} else if (Object.hasOwn(entitiesForDetector, entity)) {
|
||||
if (record.record_score > entitiesForDetector[entity].record_score) {
|
||||
entitiesForDetector[entity] = record;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue