-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Logs UI] Create screen to set up analysis ML jobs #43413
Changes from all commits
de0499e
8d06a54
0ba9cca
84248c2
31be96e
6c0bac5
98a9fa9
83330d7
916c167
6951bde
fe9c76a
705577a
1beb78c
f6594e3
fb139df
c36586f
2569444
c4a2c0a
fab784e
3104d10
7ec64cd
895cb3f
69d7a7b
b20e018
5ca200f
5bb9e35
09efec9
4908922
c7a33dc
4871bad
c13eb2f
41ca5e4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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; | ||
} | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would this work with a return indices.filter(index => index !== SAMPLE_DATA_INDEX).join(',') There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 I'll change this on the "cleanup / bug fixing" PR so I don't need to trigger another build cycle. |
||
|
||
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>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can someone explain to me why io-ts gets called
rt
?