From 4c7f963ee4b1371e1ca947412b336b92c3791f7d Mon Sep 17 00:00:00 2001 From: Quynh Nguyen Date: Thu, 19 Nov 2020 18:45:46 -0600 Subject: [PATCH 1/4] [ML] Fix metric job not loading for job with no partition --- .../plot_function_controls/plot_function_controls.tsx | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/x-pack/plugins/ml/public/application/timeseriesexplorer/components/plot_function_controls/plot_function_controls.tsx b/x-pack/plugins/ml/public/application/timeseriesexplorer/components/plot_function_controls/plot_function_controls.tsx index 8e26a912a6051..e5a7783f65a79 100644 --- a/x-pack/plugins/ml/public/application/timeseriesexplorer/components/plot_function_controls/plot_function_controls.tsx +++ b/x-pack/plugins/ml/public/application/timeseriesexplorer/components/plot_function_controls/plot_function_controls.tsx @@ -73,12 +73,7 @@ export const PlotByFunctionControls = ({ return; } const selectedJob = mlJobService.getJob(selectedJobId); - if ( - // set if only entity controls are picked - selectedEntities !== undefined && - functionDescription === undefined && - isMetricDetector(selectedJob, selectedDetectorIndex) - ) { + if (functionDescription === undefined && isMetricDetector(selectedJob, selectedDetectorIndex)) { const detector = selectedJob.analysis_config.detectors[selectedDetectorIndex]; if (detector?.function === ML_JOB_AGGREGATION.METRIC) { getFunctionDescriptionToPlot( From ff1f4316b9c00b51a91dcc27f045d3593f09f4f9 Mon Sep 17 00:00:00 2001 From: Quynh Nguyen Date: Thu, 19 Nov 2020 20:55:41 -0600 Subject: [PATCH 2/4] [ML] Move controls inside series controls so we know how many entityControls there are --- .../plot_function_controls.tsx | 10 +++++++++- .../components/series_controls/series_controls.tsx | 14 ++++++++++++++ .../timeseriesexplorer/timeseriesexplorer.js | 11 ++--------- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/x-pack/plugins/ml/public/application/timeseriesexplorer/components/plot_function_controls/plot_function_controls.tsx b/x-pack/plugins/ml/public/application/timeseriesexplorer/components/plot_function_controls/plot_function_controls.tsx index e5a7783f65a79..b4461130df927 100644 --- a/x-pack/plugins/ml/public/application/timeseriesexplorer/components/plot_function_controls/plot_function_controls.tsx +++ b/x-pack/plugins/ml/public/application/timeseriesexplorer/components/plot_function_controls/plot_function_controls.tsx @@ -38,12 +38,14 @@ export const PlotByFunctionControls = ({ selectedDetectorIndex, selectedJobId, selectedEntities, + numEntityControls, }: { functionDescription: undefined | string; setFunctionDescription: (func: string) => void; selectedDetectorIndex: number; selectedJobId: string; selectedEntities: Record; + numEntityControls: number; }) => { const toastNotificationService = useToastNotificationService(); @@ -73,7 +75,13 @@ export const PlotByFunctionControls = ({ return; } const selectedJob = mlJobService.getJob(selectedJobId); - if (functionDescription === undefined && isMetricDetector(selectedJob, selectedDetectorIndex)) { + const validEntities = + numEntityControls === 0 || (numEntityControls > 0 && selectedEntities !== undefined); + if ( + validEntities && + functionDescription === undefined && + isMetricDetector(selectedJob, selectedDetectorIndex) + ) { const detector = selectedJob.analysis_config.detectors[selectedDetectorIndex]; if (detector?.function === ML_JOB_AGGREGATION.METRIC) { getFunctionDescriptionToPlot( diff --git a/x-pack/plugins/ml/public/application/timeseriesexplorer/components/series_controls/series_controls.tsx b/x-pack/plugins/ml/public/application/timeseriesexplorer/components/series_controls/series_controls.tsx index 37a637e2c1446..56a111ab9d1fd 100644 --- a/x-pack/plugins/ml/public/application/timeseriesexplorer/components/series_controls/series_controls.tsx +++ b/x-pack/plugins/ml/public/application/timeseriesexplorer/components/series_controls/series_controls.tsx @@ -28,6 +28,7 @@ import { useStorage } from '../../../contexts/ml/use_storage'; import { EntityFieldType } from '../../../../../common/types/anomalies'; import { FieldDefinition } from '../../../services/results_service/result_service_rx'; import { getViewableDetectors } from '../../timeseriesexplorer_utils/get_viewable_detectors'; +import { PlotByFunctionControls } from '../plot_function_controls'; function getEntityControlOptions(fieldValues: FieldDefinition['values']): ComboBoxOption[] { if (!Array.isArray(fieldValues)) { @@ -67,6 +68,8 @@ interface SeriesControlsProps { bounds: any; appStateHandler: Function; selectedEntities: Record; + functionDescription: string; + setFunctionDescription: (func: string) => void; } /** @@ -79,6 +82,8 @@ export const SeriesControls: FC = ({ appStateHandler, children, selectedEntities, + functionDescription, + setFunctionDescription, }) => { const { services: { @@ -306,6 +311,15 @@ export const SeriesControls: FC = ({ /> ); })} + + {children} diff --git a/x-pack/plugins/ml/public/application/timeseriesexplorer/timeseriesexplorer.js b/x-pack/plugins/ml/public/application/timeseriesexplorer/timeseriesexplorer.js index f22cc191ef844..47d0f25857b03 100644 --- a/x-pack/plugins/ml/public/application/timeseriesexplorer/timeseriesexplorer.js +++ b/x-pack/plugins/ml/public/application/timeseriesexplorer/timeseriesexplorer.js @@ -81,7 +81,6 @@ import { ANOMALY_DETECTION_DEFAULT_TIME_RANGE } from '../../../common/constants/ import { getControlsForDetector } from './get_controls_for_detector'; import { SeriesControls } from './components/series_controls'; import { TimeSeriesChartWithTooltips } from './components/timeseries_chart/timeseries_chart_with_tooltip'; -import { PlotByFunctionControls } from './components/plot_function_controls'; import { aggregationTypeTransform } from '../../../common/util/anomaly_utils'; import { isMetricDetector } from './get_function_description'; import { getViewableDetectors } from './timeseriesexplorer_utils/get_viewable_detectors'; @@ -1013,15 +1012,9 @@ export class TimeSeriesExplorer extends React.Component { selectedDetectorIndex={selectedDetectorIndex} selectedEntities={this.props.selectedEntities} bounds={bounds} + functionDescription={this.props.functionDescription} + setFunctionDescription={this.setFunctionDescription} > - - {arePartitioningFieldsProvided && ( From f56316982f1c86157da2e6741b8058a48d48de5b Mon Sep 17 00:00:00 2001 From: Quynh Nguyen Date: Thu, 19 Nov 2020 21:16:03 -0600 Subject: [PATCH 3/4] [ML] Update entityControlsCnt --- .../plot_function_controls/plot_function_controls.tsx | 9 ++++++--- .../components/series_controls/series_controls.tsx | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/x-pack/plugins/ml/public/application/timeseriesexplorer/components/plot_function_controls/plot_function_controls.tsx b/x-pack/plugins/ml/public/application/timeseriesexplorer/components/plot_function_controls/plot_function_controls.tsx index b4461130df927..cd2cdbe42b5a2 100644 --- a/x-pack/plugins/ml/public/application/timeseriesexplorer/components/plot_function_controls/plot_function_controls.tsx +++ b/x-pack/plugins/ml/public/application/timeseriesexplorer/components/plot_function_controls/plot_function_controls.tsx @@ -38,14 +38,14 @@ export const PlotByFunctionControls = ({ selectedDetectorIndex, selectedJobId, selectedEntities, - numEntityControls, + entityControlsCnt, }: { functionDescription: undefined | string; setFunctionDescription: (func: string) => void; selectedDetectorIndex: number; selectedJobId: string; selectedEntities: Record; - numEntityControls: number; + entityControlsCnt: number; }) => { const toastNotificationService = useToastNotificationService(); @@ -75,8 +75,10 @@ export const PlotByFunctionControls = ({ return; } const selectedJob = mlJobService.getJob(selectedJobId); + // if no controls, it's okay to fetch + // if there are series controls, only fetch if user has selected something const validEntities = - numEntityControls === 0 || (numEntityControls > 0 && selectedEntities !== undefined); + entityControlsCnt === 0 || (entityControlsCnt > 0 && selectedEntities !== undefined); if ( validEntities && functionDescription === undefined && @@ -98,6 +100,7 @@ export const PlotByFunctionControls = ({ selectedEntities, selectedJobId, functionDescription, + entityControlsCnt, ]); if (functionDescription === undefined) return null; diff --git a/x-pack/plugins/ml/public/application/timeseriesexplorer/components/series_controls/series_controls.tsx b/x-pack/plugins/ml/public/application/timeseriesexplorer/components/series_controls/series_controls.tsx index 56a111ab9d1fd..d0e98d41e788f 100644 --- a/x-pack/plugins/ml/public/application/timeseriesexplorer/components/series_controls/series_controls.tsx +++ b/x-pack/plugins/ml/public/application/timeseriesexplorer/components/series_controls/series_controls.tsx @@ -317,7 +317,7 @@ export const SeriesControls: FC = ({ selectedEntities={selectedEntities} functionDescription={functionDescription} setFunctionDescription={setFunctionDescription} - numEntityControls={entityControls.length} + entityControlsCnt={entityControls.length} /> {children} From be00afceeeeafe573c77aaf853a746c7eeacbc20 Mon Sep 17 00:00:00 2001 From: Quynh Nguyen Date: Thu, 19 Nov 2020 21:23:51 -0600 Subject: [PATCH 4/4] [ML] Rename entityControlsCount --- .../plot_function_controls/plot_function_controls.tsx | 8 ++++---- .../components/series_controls/series_controls.tsx | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/x-pack/plugins/ml/public/application/timeseriesexplorer/components/plot_function_controls/plot_function_controls.tsx b/x-pack/plugins/ml/public/application/timeseriesexplorer/components/plot_function_controls/plot_function_controls.tsx index cd2cdbe42b5a2..78c0cb97cb889 100644 --- a/x-pack/plugins/ml/public/application/timeseriesexplorer/components/plot_function_controls/plot_function_controls.tsx +++ b/x-pack/plugins/ml/public/application/timeseriesexplorer/components/plot_function_controls/plot_function_controls.tsx @@ -38,14 +38,14 @@ export const PlotByFunctionControls = ({ selectedDetectorIndex, selectedJobId, selectedEntities, - entityControlsCnt, + entityControlsCount, }: { functionDescription: undefined | string; setFunctionDescription: (func: string) => void; selectedDetectorIndex: number; selectedJobId: string; selectedEntities: Record; - entityControlsCnt: number; + entityControlsCount: number; }) => { const toastNotificationService = useToastNotificationService(); @@ -78,7 +78,7 @@ export const PlotByFunctionControls = ({ // if no controls, it's okay to fetch // if there are series controls, only fetch if user has selected something const validEntities = - entityControlsCnt === 0 || (entityControlsCnt > 0 && selectedEntities !== undefined); + entityControlsCount === 0 || (entityControlsCount > 0 && selectedEntities !== undefined); if ( validEntities && functionDescription === undefined && @@ -100,7 +100,7 @@ export const PlotByFunctionControls = ({ selectedEntities, selectedJobId, functionDescription, - entityControlsCnt, + entityControlsCount, ]); if (functionDescription === undefined) return null; diff --git a/x-pack/plugins/ml/public/application/timeseriesexplorer/components/series_controls/series_controls.tsx b/x-pack/plugins/ml/public/application/timeseriesexplorer/components/series_controls/series_controls.tsx index d0e98d41e788f..c1f35e68e43c6 100644 --- a/x-pack/plugins/ml/public/application/timeseriesexplorer/components/series_controls/series_controls.tsx +++ b/x-pack/plugins/ml/public/application/timeseriesexplorer/components/series_controls/series_controls.tsx @@ -317,7 +317,7 @@ export const SeriesControls: FC = ({ selectedEntities={selectedEntities} functionDescription={functionDescription} setFunctionDescription={setFunctionDescription} - entityControlsCnt={entityControls.length} + entityControlsCount={entityControls.length} /> {children}