diff --git a/x-pack/legacy/plugins/ml/public/application/services/ml_api_service/index.d.ts b/x-pack/legacy/plugins/ml/public/application/services/ml_api_service/index.d.ts index d6eff08a5f3aa..5b6766c622424 100644 --- a/x-pack/legacy/plugins/ml/public/application/services/ml_api_service/index.d.ts +++ b/x-pack/legacy/plugins/ml/public/application/services/ml_api_service/index.d.ts @@ -125,7 +125,7 @@ declare interface Ml { results: { getMaxAnomalyScore: (jobIds: string[], earliestMs: number, latestMs: number) => Promise; fetchPartitionFieldsValues: ( - jobId: string, + criteriaFields: Array<{ fieldName: string; fieldValue: any }>, earliestMs: number, latestMs: number ) => Observable>; diff --git a/x-pack/legacy/plugins/ml/public/application/services/ml_api_service/results.js b/x-pack/legacy/plugins/ml/public/application/services/ml_api_service/results.js index e6585b0b7440f..0070020d67681 100644 --- a/x-pack/legacy/plugins/ml/public/application/services/ml_api_service/results.js +++ b/x-pack/legacy/plugins/ml/public/application/services/ml_api_service/results.js @@ -76,11 +76,11 @@ export const results = { }); }, - fetchPartitionFieldsValues(jobId, earliestMs, latestMs) { + fetchPartitionFieldsValues(criteriaFields, earliestMs, latestMs) { return http$(`${basePath}/results/partition_fields_values`, { method: 'POST', body: { - jobId, + criteriaFields, earliestMs, latestMs, }, diff --git a/x-pack/legacy/plugins/ml/public/application/services/results_service/result_service_rx.ts b/x-pack/legacy/plugins/ml/public/application/services/results_service/result_service_rx.ts index 3987b5b42e6d3..dafca37d680d9 100644 --- a/x-pack/legacy/plugins/ml/public/application/services/results_service/result_service_rx.ts +++ b/x-pack/legacy/plugins/ml/public/application/services/results_service/result_service_rx.ts @@ -15,7 +15,6 @@ import { Observable } from 'rxjs'; import { map } from 'rxjs/operators'; import _ from 'lodash'; import { ML_MEDIAN_PERCENTS } from '../../../../common/util/job_utils'; -import { JobId } from '../../jobs/new_job/common/job_creator/configs'; import { ml } from '../ml_api_service'; import { ML_RESULTS_INDEX_PATTERN } from '../../../../common/constants/index_patterns'; import { CriteriaField } from './index'; @@ -534,6 +533,10 @@ export function getScheduledEventsByBucket( ); } -export function fetchPartitionFieldsValues(jobId: JobId, earliestMs: number, latestMs: number) { - return ml.results.fetchPartitionFieldsValues(jobId, earliestMs, latestMs); +export function fetchPartitionFieldsValues( + criteriaFields: Array<{ fieldName: string; fieldValue: any }>, + earliestMs: number, + latestMs: number +) { + return ml.results.fetchPartitionFieldsValues(criteriaFields, earliestMs, latestMs); } diff --git a/x-pack/legacy/plugins/ml/public/application/timeseriesexplorer/timeseriesexplorer.js b/x-pack/legacy/plugins/ml/public/application/timeseriesexplorer/timeseriesexplorer.js index 3637b527faa1e..a7c3b364c1151 100644 --- a/x-pack/legacy/plugins/ml/public/application/timeseriesexplorer/timeseriesexplorer.js +++ b/x-pack/legacy/plugins/ml/public/application/timeseriesexplorer/timeseriesexplorer.js @@ -8,7 +8,7 @@ * React component for rendering Single Metric Viewer. */ -import { chain, difference, each, find, first, get, has, isEqual, without } from 'lodash'; +import { difference, each, find, first, get, has, isEqual, without } from 'lodash'; import moment from 'moment-timezone'; import { Subject, Subscription, forkJoin } from 'rxjs'; import { map, debounceTime, switchMap, tap, withLatestFrom } from 'rxjs/operators'; @@ -423,7 +423,7 @@ export class TimeSeriesExplorer extends React.Component { * Loads available entity values. * @param callback */ - loadEntityValues = (callback = () => {}) => { + loadEntityValues = async (callback = () => {}) => { const { timefilter } = this.props; const { detectorId, entities, selectedJob } = this.state; @@ -432,55 +432,44 @@ export class TimeSeriesExplorer extends React.Component { const bounds = timefilter.getActiveBounds(); const detectorIndex = +detectorId; - mlResultsService - .fetchPartitionFieldsValues(selectedJob.job_id, bounds.min.valueOf(), bounds.max.valueOf()) - .subscribe(v => { - console.info(v); - }); - - mlResultsService - .getRecordsForCriteria( - [selectedJob.job_id], - [{ fieldName: 'detector_index', fieldValue: detectorIndex }], - 0, + const { + partition_field: partitionField, + over_field: overField, + by_field: byField, + } = await mlResultsService + .fetchPartitionFieldsValues( + [ + { + fieldName: 'job_id', + fieldValue: selectedJob.job_id, + }, + { + fieldName: 'detector_index', + fieldValue: detectorIndex, + }, + ], bounds.min.valueOf(), - bounds.max.valueOf(), - ANOMALIES_TABLE_DEFAULT_QUERY_SIZE + bounds.max.valueOf() ) - .toPromise() - .then(resp => { - if (resp.records && resp.records.length > 0) { - const firstRec = resp.records[0]; + .toPromise(); - this.setState( - { - entities: entities.map(entity => { - const newEntity = { ...entity }; - if (firstRec.partition_field_name === newEntity.fieldName) { - newEntity.fieldValues = chain(resp.records) - .pluck('partition_field_value') - .uniq() - .value(); - } - if (firstRec.over_field_name === newEntity.fieldName) { - newEntity.fieldValues = chain(resp.records) - .pluck('over_field_value') - .uniq() - .value(); - } - if (firstRec.by_field_name === newEntity.fieldName) { - newEntity.fieldValues = chain(resp.records) - .pluck('by_field_value') - .uniq() - .value(); - } - return newEntity; - }), - }, - callback - ); - } - }); + this.setState( + { + entities: entities.map(entity => { + if (partitionField.name === entity.fieldName) { + entity.fieldValues = partitionField.values; + } + if (overField.name === entity.fieldName) { + entity.fieldValues = overField.values; + } + if (byField.name === entity.fieldName) { + entity.fieldValues = byField.values; + } + return entity; + }), + }, + callback + ); }; loadForForecastId = forecastId => {