[ML] Edit job_service jobsExist call to query ML Get Jobs endpoint (#38649)

This commit is contained in:
Pete Harverson 2019-06-11 15:02:35 +01:00 committed by GitHub
parent cac41c3eae
commit 41d74498e8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 18 deletions

View file

@ -8,6 +8,5 @@ export const ML_ANNOTATIONS_INDEX_ALIAS_READ = '.ml-annotations-read';
export const ML_ANNOTATIONS_INDEX_ALIAS_WRITE = '.ml-annotations-write';
export const ML_ANNOTATIONS_INDEX_PATTERN = '.ml-annotations-6';
export const ML_CONFIG_INDEX_PATTERN = '.ml-config';
export const ML_RESULTS_INDEX_PATTERN = '.ml-anomalies-*';
export const ML_NOTIFICATION_INDEX_PATTERN = '.ml-notifications';

View file

@ -6,7 +6,6 @@
import { i18n } from '@kbn/i18n';
import { ML_CONFIG_INDEX_PATTERN } from '../../../common/constants/index_patterns';
import { JOB_STATE, DATAFEED_STATE } from '../../../common/constants/states';
import { datafeedsProvider } from './datafeeds';
import { jobAuditMessagesProvider } from '../job_audit_messages';
@ -328,24 +327,11 @@ export function jobsProvider(callWithRequest) {
// e.g. *_low_request_rate_ecs
async function jobsExist(jobIds = []) {
// Get the list of job IDs.
// Use size of 10000, matching anomaly_detectors endpoint.
const maxJobsSize = 10000;
const resp = await callWithRequest('search', {
index: ML_CONFIG_INDEX_PATTERN,
size: maxJobsSize,
body: {
_source: 'job_id',
query: {
term: { job_type: 'anomaly_detector' }
}
}
});
const jobsInfo = await callWithRequest('ml.jobs', { jobId: jobIds });
const results = {};
let allJobIds = [];
if (resp.hits.total.value > 0) {
const hits = resp.hits.hits;
allJobIds = hits.map(hit => hit._source.job_id);
if (jobsInfo.count > 0) {
const allJobIds = jobsInfo.jobs.map(job => job.job_id);
// Check if each of the supplied IDs match existing jobs.
jobIds.forEach((jobId) => {