Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add signal and abort controller to agent metadata and TakeAction button #103217

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,14 @@ export const getCaseIdsFromAlertId = async ({
*
* @param host id
*/
export const getHostMetadata = async ({ agentId }: { agentId: string }): Promise<HostInfo> =>
export const getHostMetadata = async ({
agentId,
signal,
}: {
agentId: string;
signal?: AbortSignal;
}): Promise<HostInfo> =>
KibanaServices.get().http.fetch<HostInfo>(
resolvePathVariables(HOST_METADATA_GET_ROUTE, { id: agentId }),
{ method: 'get' }
{ method: 'GET', signal }
);
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,21 @@ export const useHostIsolationStatus = ({
const { addError } = useAppToasts();

useEffect(() => {
const abortCtrl = new AbortController();
// isMounted tracks if a component is mounted before changing state
let isMounted = true;
const fetchData = async () => {
try {
const metadataResponse = await getHostMetadata({ agentId });
const metadataResponse = await getHostMetadata({ agentId, signal: abortCtrl.signal });
if (isMounted) {
setIsIsolated(isEndpointHostIsolated(metadataResponse.metadata));
setAgentStatus(metadataResponse.host_status);
}
} catch (error) {
// don't show self-aborted requests errors to the user
academo marked this conversation as resolved.
Show resolved Hide resolved
if (error.name === 'AbortError') {
return;
}
addError(error.message, { title: ISOLATION_STATUS_FAILURE });
}
if (isMounted) {
Expand All @@ -62,6 +67,7 @@ export const useHostIsolationStatus = ({
return () => {
// updates to show component is unmounted
isMounted = false;
abortCtrl.abort();
};
}, [addError, agentId]);
return { loading, isIsolated, agentStatus };
Expand Down