-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Logs UI] Create screen to set up analysis ML jobs (#43413)
* Add empty analysis tab * Add ml capabilities check * Add job status checking functionality * Add a loading page for the job status check * Change types / change method for deriving space ID / change setup requirement filtering check * Use new structure * Add module setup to log analysis jobs hook * Add ID to path * [Logs UI] Add analyis setup landing screen * Add function to set up ML module on click * Use partial type for start and end props * Add start and end time selection * Fix syntax * Change seconds timestamp to ms * Update wording * Use FormControlLayout to clear datepickers * Update wording about earlier start date * Remove specific point in time wording * Fix typechecking * Reload analysis page on successful job creation * Add error handling for setup failure * Update description ton of feature to reflect 7.4 feature set * Add toggleable default message * Revert to EuiFormControlLayout until eui changes are pushed * Remove sample data index if user has it set
- Loading branch information
Showing
7 changed files
with
492 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
x-pack/legacy/plugins/infra/public/containers/logs/log_analysis/api/ml_setup_module_api.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import * as rt from 'io-ts'; | ||
import { kfetch } from 'ui/kfetch'; | ||
|
||
import { getJobIdPrefix } from '../../../../../common/log_analysis'; | ||
import { throwErrors, createPlainError } from '../../../../../common/runtime_types'; | ||
|
||
const MODULE_ID = 'logs_ui_analysis'; | ||
|
||
// This is needed due to: https://github.com/elastic/kibana/issues/43671 | ||
const removeSampleDataIndex = (indexPattern: string) => { | ||
const SAMPLE_DATA_INDEX = 'kibana_sample_data_logs*'; | ||
const indices = indexPattern.split(','); | ||
const sampleDataIndex = indices.findIndex((index: string) => { | ||
return index === SAMPLE_DATA_INDEX; | ||
}); | ||
if (sampleDataIndex > -1) { | ||
indices.splice(sampleDataIndex, 1); | ||
return indices.join(','); | ||
} else { | ||
return indexPattern; | ||
} | ||
}; | ||
|
||
export const callSetupMlModuleAPI = async ( | ||
start: number | undefined, | ||
end: number | undefined, | ||
spaceId: string, | ||
sourceId: string, | ||
indexPattern: string, | ||
timeField: string, | ||
bucketSpan: number | ||
) => { | ||
const response = await kfetch({ | ||
method: 'POST', | ||
pathname: `/api/ml/modules/setup/${MODULE_ID}`, | ||
body: JSON.stringify( | ||
setupMlModuleRequestPayloadRT.encode({ | ||
start, | ||
end, | ||
indexPatternName: removeSampleDataIndex(indexPattern), | ||
prefix: getJobIdPrefix(spaceId, sourceId), | ||
startDatafeed: true, | ||
jobOverrides: [ | ||
{ | ||
job_id: 'log-entry-rate', | ||
analysis_config: { | ||
bucket_span: `${bucketSpan}ms`, | ||
}, | ||
data_description: { | ||
time_field: timeField, | ||
}, | ||
}, | ||
], | ||
datafeedOverrides: [ | ||
{ | ||
job_id: 'log-entry-rate', | ||
aggregations: { | ||
buckets: { | ||
date_histogram: { | ||
field: timeField, | ||
fixed_interval: `${bucketSpan}ms`, | ||
}, | ||
aggregations: { | ||
[timeField]: { | ||
max: { | ||
field: `${timeField}`, | ||
}, | ||
}, | ||
doc_count_per_minute: { | ||
bucket_script: { | ||
script: { | ||
params: { | ||
bucket_span_in_ms: bucketSpan, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
], | ||
}) | ||
), | ||
}); | ||
|
||
return setupMlModuleResponsePayloadRT.decode(response).getOrElseL(throwErrors(createPlainError)); | ||
}; | ||
|
||
const setupMlModuleTimeParamsRT = rt.partial({ | ||
start: rt.number, | ||
end: rt.number, | ||
}); | ||
|
||
const setupMlModuleRequestParamsRT = rt.type({ | ||
indexPatternName: rt.string, | ||
prefix: rt.string, | ||
startDatafeed: rt.boolean, | ||
jobOverrides: rt.array(rt.object), | ||
datafeedOverrides: rt.array(rt.object), | ||
}); | ||
|
||
const setupMlModuleRequestPayloadRT = rt.intersection([ | ||
setupMlModuleTimeParamsRT, | ||
setupMlModuleRequestParamsRT, | ||
]); | ||
|
||
const setupMlModuleResponsePayloadRT = rt.type({ | ||
datafeeds: rt.array( | ||
rt.type({ | ||
id: rt.string, | ||
started: rt.boolean, | ||
success: rt.boolean, | ||
}) | ||
), | ||
jobs: rt.array( | ||
rt.type({ | ||
id: rt.string, | ||
success: rt.boolean, | ||
}) | ||
), | ||
}); | ||
|
||
export type SetupMlModuleResponsePayload = rt.TypeOf<typeof setupMlModuleResponsePayloadRT>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.