From f13ab403d897819fe3d1867174c527f251687039 Mon Sep 17 00:00:00 2001 From: Mark Hopkin Date: Tue, 6 May 2025 10:04:02 +0100 Subject: [PATCH] [Entity Analytics] [bug-fix] Do not abort risk score search request (#219858) ## Summary Closes https://github.com/elastic/kibana/issues/219490 Fix an error toast appearing when changing an entities asset criticality from the entity flyout. See video on issue above for more detail. We were seeing the risk score request be aborted and this was creating the error toast. - Do not toast if an abort error is thrown - Do not abort the request unless the component receives `skip:true` ### Test Steps 1. Use the security document generator `yarn start entity-store` command to load entities and enable the risk engine 2. Enable the entity store 3. from the entities table open the entity flyout 4. Assign/change asset criticality 5. observe the error is not present ### Why did the bug happen? The risk score component stops rendering because the conditions for aborting and searching differ. So we aborted the HTTP call but didn't search again. I believe this PR https://github.com/elastic/kibana/pull/201810 introduced the bug --------- Co-authored-by: machadoum (cherry picked from commit 64d20bb00b9e314c9abe257c8453c2684bccc0a3) --- .../public/common/utils/exceptions/index.ts | 6 ++++++ .../public/entity_analytics/api/hooks/use_risk_score.tsx | 6 +++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/x-pack/solutions/security/plugins/security_solution/public/common/utils/exceptions/index.ts b/x-pack/solutions/security/plugins/security_solution/public/common/utils/exceptions/index.ts index 01e09eb683467..76a3e188162fd 100644 --- a/x-pack/solutions/security/plugins/security_solution/public/common/utils/exceptions/index.ts +++ b/x-pack/solutions/security/plugins/security_solution/public/common/utils/exceptions/index.ts @@ -5,6 +5,8 @@ * 2.0. */ +import type { IHttpFetchError } from '@kbn/core/public'; + export const isIndexNotFoundError = (error: unknown): boolean => { const castError = error as { attributes?: { @@ -17,3 +19,7 @@ export const isIndexNotFoundError = (error: unknown): boolean => { castError.attributes?.error?.caused_by?.type === 'index_not_found_exception' ); }; + +export const isAbortError = (error: unknown): boolean => { + return (error as IHttpFetchError)?.name === 'AbortError'; +}; diff --git a/x-pack/solutions/security/plugins/security_solution/public/entity_analytics/api/hooks/use_risk_score.tsx b/x-pack/solutions/security/plugins/security_solution/public/entity_analytics/api/hooks/use_risk_score.tsx index 1271af8e0edb3..95aa3172b524a 100644 --- a/x-pack/solutions/security/plugins/security_solution/public/entity_analytics/api/hooks/use_risk_score.tsx +++ b/x-pack/solutions/security/plugins/security_solution/public/entity_analytics/api/hooks/use_risk_score.tsx @@ -20,7 +20,7 @@ import type { import type { ESQuery } from '../../../../common/typed_json'; import type { InspectResponse } from '../../../types'; import { useAppToasts } from '../../../common/hooks/use_app_toasts'; -import { isIndexNotFoundError } from '../../../common/utils/exceptions'; +import { isIndexNotFoundError, isAbortError } from '../../../common/utils/exceptions'; import type { inputsModel } from '../../../common/store'; import { useSearchStrategy } from '../../../common/containers/use_search_strategy'; import { useGetDefaultRiskIndex } from '../../hooks/use_get_default_risk_index'; @@ -96,7 +96,7 @@ export const useRiskScore = ({ } = useSearchStrategy({ factoryQueryType, initialResult, - abort: skip || !hasEngineBeenInstalled || isStatusLoading || !isAuthorized, + abort: skip, showErrorToast: false, }); @@ -170,7 +170,7 @@ export const useRiskScore = ({ useEffect(() => { if (error) { - if (!isIndexNotFoundError(error)) { + if (!isIndexNotFoundError(error) && !isAbortError(error)) { addError(error, { title: i18n.translate('xpack.securitySolution.riskScore.failSearchDescription', { defaultMessage: `Failed to run search on risk score`,