From bfebe00f712fdbce2d32d71370eec372e6b5a0eb Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Wed, 25 Oct 2023 16:17:23 -0700 Subject: [PATCH] [Backport 2.7] Prevent empty task IDs passed to server side (#642) * Prevent empty task IDs passed to server side (#616) * Prevent empty task IDs passed to server side Signed-off-by: Tyler Ohlsen * add release notes Signed-off-by: Tyler Ohlsen --------- Signed-off-by: Tyler Ohlsen (cherry picked from commit 8c3ed817b29f90e9e55d29291631b1c81e1739b4) * Delete release-notes/opensearch-anomaly-detection-dashboards.release-notes-2.11.0.0.md Signed-off-by: Tyler Ohlsen --------- Signed-off-by: Tyler Ohlsen Co-authored-by: Tyler Ohlsen --- .../containers/AnomalyHistory.tsx | 45 ++++++++++--------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/public/pages/DetectorResults/containers/AnomalyHistory.tsx b/public/pages/DetectorResults/containers/AnomalyHistory.tsx index 8fec0696..e9a355df 100644 --- a/public/pages/DetectorResults/containers/AnomalyHistory.tsx +++ b/public/pages/DetectorResults/containers/AnomalyHistory.tsx @@ -173,6 +173,12 @@ export const AnomalyHistory = (props: AnomalyHistoryProps) => { const backgroundColor = darkModeEnabled() ? '#29017' : '#F7F7F7'; const resultIndex = get(props, 'detector.resultIndex', ''); + // Utility fn to only fetch data when either it is non-historical, or historical and + // there is a populated task ID which will be used to fetch the historical results + const isValidToFetch = () => { + return !props.isHistorical || (props.isHistorical && taskId.current); + }; + // Tracking which parent category fields the user has selected to filter by. const [selectedCategoryFields, setSelectedCategoryFields] = useState( getCategoryFieldOptions(detectorCategoryField) @@ -325,7 +331,8 @@ export const AnomalyHistory = (props: AnomalyHistoryProps) => { useEffect(() => { if ( !isEmpty(bucketizedAnomalyResults) && - !isDateRangeOversize(zoomRange, detectorInterval, MAX_ANOMALIES) + !isDateRangeOversize(zoomRange, detectorInterval, MAX_ANOMALIES) && + isValidToFetch() ) { setBucketizedAnomalyResults(undefined); if (isHCDetector && selectedHeatmapCell) { @@ -350,14 +357,16 @@ export const AnomalyHistory = (props: AnomalyHistoryProps) => { }, [zoomRange]); useEffect(() => { - fetchRawAnomalyResults(isHCDetector); - if ( - !isHCDetector && - isDateRangeOversize(dateRange, detectorInterval, MAX_ANOMALIES) - ) { - getBucketizedAnomalyResults(); - } else { - setBucketizedAnomalyResults(undefined); + if (isValidToFetch()) { + fetchRawAnomalyResults(isHCDetector); + if ( + !isHCDetector && + isDateRangeOversize(dateRange, detectorInterval, MAX_ANOMALIES) + ) { + getBucketizedAnomalyResults(); + } else { + setBucketizedAnomalyResults(undefined); + } } }, [dateRange, props.detector]); @@ -399,13 +408,7 @@ export const AnomalyHistory = (props: AnomalyHistoryProps) => { ); const detectorResultResponse = props.isHistorical ? await dispatch( - getDetectorResults( - taskId.current || '', - params, - true, - resultIndex, - true - ) + getDetectorResults(taskId.current, params, true, resultIndex, true) ).catch((error: any) => { setIsLoading(false); setIsLoadingAnomalyResults(false); @@ -457,17 +460,19 @@ export const AnomalyHistory = (props: AnomalyHistoryProps) => { useEffect(() => { // For any change, we will want to clear any selected heatmap cell to clear any populated charts / graphs setSelectedHeatmapCell(undefined); - fetchHCAnomalySummaries(); + if (isValidToFetch()) { + fetchHCAnomalySummaries(); + } }, [selectedCategoryFields]); useEffect(() => { - if (isHCDetector) { + if (isHCDetector && isValidToFetch()) { fetchHCAnomalySummaries(); } }, [dateRange, heatmapDisplayOption]); useEffect(() => { - if (selectedHeatmapCell) { + if (selectedHeatmapCell && isValidToFetch()) { if ( isMultiCategory && get(selectedCategoryFields, 'length', 0) < @@ -491,7 +496,7 @@ export const AnomalyHistory = (props: AnomalyHistoryProps) => { // Getting the latest sets of time series based on the selected parent + child entities useEffect(() => { - if (selectedHeatmapCell) { + if (selectedHeatmapCell && isValidToFetch()) { // Get a list of entity lists, where each list represents a unique entity combination of // all parent + child entities (a single model). And, for each one of these lists, fetch the time series data. const entityCombosToFetch = getAllEntityCombos(