Skip to content

Commit 8c3ed81

Browse files
authored
Prevent empty task IDs passed to server side (opensearch-project#616)
* Prevent empty task IDs passed to server side Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com> * add release notes Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com> --------- Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com>
1 parent de6e677 commit 8c3ed81

File tree

2 files changed

+29
-20
lines changed

2 files changed

+29
-20
lines changed

public/pages/DetectorResults/containers/AnomalyHistory.tsx

+25-20
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,12 @@ export const AnomalyHistory = (props: AnomalyHistoryProps) => {
173173
const backgroundColor = darkModeEnabled() ? '#29017' : '#F7F7F7';
174174
const resultIndex = get(props, 'detector.resultIndex', '');
175175

176+
// Utility fn to only fetch data when either it is non-historical, or historical and
177+
// there is a populated task ID which will be used to fetch the historical results
178+
const isValidToFetch = () => {
179+
return !props.isHistorical || (props.isHistorical && taskId.current);
180+
};
181+
176182
// Tracking which parent category fields the user has selected to filter by.
177183
const [selectedCategoryFields, setSelectedCategoryFields] = useState(
178184
getCategoryFieldOptions(detectorCategoryField)
@@ -325,7 +331,8 @@ export const AnomalyHistory = (props: AnomalyHistoryProps) => {
325331
useEffect(() => {
326332
if (
327333
!isEmpty(bucketizedAnomalyResults) &&
328-
!isDateRangeOversize(zoomRange, detectorInterval, MAX_ANOMALIES)
334+
!isDateRangeOversize(zoomRange, detectorInterval, MAX_ANOMALIES) &&
335+
isValidToFetch()
329336
) {
330337
setBucketizedAnomalyResults(undefined);
331338
if (isHCDetector && selectedHeatmapCell) {
@@ -350,14 +357,16 @@ export const AnomalyHistory = (props: AnomalyHistoryProps) => {
350357
}, [zoomRange]);
351358

352359
useEffect(() => {
353-
fetchRawAnomalyResults(isHCDetector);
354-
if (
355-
!isHCDetector &&
356-
isDateRangeOversize(dateRange, detectorInterval, MAX_ANOMALIES)
357-
) {
358-
getBucketizedAnomalyResults();
359-
} else {
360-
setBucketizedAnomalyResults(undefined);
360+
if (isValidToFetch()) {
361+
fetchRawAnomalyResults(isHCDetector);
362+
if (
363+
!isHCDetector &&
364+
isDateRangeOversize(dateRange, detectorInterval, MAX_ANOMALIES)
365+
) {
366+
getBucketizedAnomalyResults();
367+
} else {
368+
setBucketizedAnomalyResults(undefined);
369+
}
361370
}
362371
}, [dateRange, props.detector]);
363372

@@ -399,13 +408,7 @@ export const AnomalyHistory = (props: AnomalyHistoryProps) => {
399408
);
400409
const detectorResultResponse = props.isHistorical
401410
? await dispatch(
402-
getDetectorResults(
403-
taskId.current || '',
404-
params,
405-
true,
406-
resultIndex,
407-
true
408-
)
411+
getDetectorResults(taskId.current, params, true, resultIndex, true)
409412
).catch((error: any) => {
410413
setIsLoading(false);
411414
setIsLoadingAnomalyResults(false);
@@ -457,17 +460,19 @@ export const AnomalyHistory = (props: AnomalyHistoryProps) => {
457460
useEffect(() => {
458461
// For any change, we will want to clear any selected heatmap cell to clear any populated charts / graphs
459462
setSelectedHeatmapCell(undefined);
460-
fetchHCAnomalySummaries();
463+
if (isValidToFetch()) {
464+
fetchHCAnomalySummaries();
465+
}
461466
}, [selectedCategoryFields]);
462467

463468
useEffect(() => {
464-
if (isHCDetector) {
469+
if (isHCDetector && isValidToFetch()) {
465470
fetchHCAnomalySummaries();
466471
}
467472
}, [dateRange, heatmapDisplayOption]);
468473

469474
useEffect(() => {
470-
if (selectedHeatmapCell) {
475+
if (selectedHeatmapCell && isValidToFetch()) {
471476
if (
472477
isMultiCategory &&
473478
get(selectedCategoryFields, 'length', 0) <
@@ -491,7 +496,7 @@ export const AnomalyHistory = (props: AnomalyHistoryProps) => {
491496

492497
// Getting the latest sets of time series based on the selected parent + child entities
493498
useEffect(() => {
494-
if (selectedHeatmapCell) {
499+
if (selectedHeatmapCell && isValidToFetch()) {
495500
// Get a list of entity lists, where each list represents a unique entity combination of
496501
// all parent + child entities (a single model). And, for each one of these lists, fetch the time series data.
497502
const entityCombosToFetch = getAllEntityCombos(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Compatible with OpenSearch Dashboards 2.11.0.
2+
3+
### Bug Fixes
4+
* Prevent empty task IDs passed to server side ([#616](https://github.com/opensearch-project/anomaly-detection-dashboards-plugin/pull/616))

0 commit comments

Comments
 (0)