-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[Fleet] moving action batching to async #138870
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
Merged
juliaElastic
merged 50 commits into
elastic:main
from
juliaElastic:feat/action-batch-async
Sep 12, 2022
Merged
Changes from 13 commits
Commits
Show all changes
50 commits
Select commit
Hold shift + click to select a range
c23db52
moving action batching to async
juliaElastic 6cdbf4e
created new api for action status
juliaElastic d9da608
fix types
juliaElastic d8e968f
fix types
juliaElastic e7fd443
added time measurement
juliaElastic 8e5667a
added action status component, refactored reassign logic
juliaElastic 3c94459
refactored retry task to be reusable by other actions
juliaElastic 8a31e6c
refactored action runner to class
juliaElastic 8d705a6
changed bulk update tags
juliaElastic 8d692d2
Merge branch 'main' into feat/action-batch-async
juliaElastic 8da6894
build fixes
juliaElastic 1afb694
fix checks
juliaElastic 1137591
passing retry options
juliaElastic 6de094e
fixed action status
juliaElastic 07f3283
improvements to action status api
juliaElastic 83fe4b6
improvements to action status api
juliaElastic ec22cbc
removed timed out status
juliaElastic ddca370
simplified code around retry tasks
juliaElastic 0fb109c
added missing unenroll params
juliaElastic a117ba3
Merge branch 'main' into feat/action-batch-async
juliaElastic dab606f
fix checks
juliaElastic f4653e2
increased upgrade action expiration to 2h for immediately
juliaElastic e38afd0
moved getActionStatusHandler to handlers, using its own response type
juliaElastic edd2ab5
capturing failures with error message in a new .fleet-actions-status …
juliaElastic 0bf645a
renamed status index so it doesn't get the same alias as .fleet-actions
juliaElastic 88a6362
cleaned up action and retry params
juliaElastic a59df36
refactored to simplify passing params
juliaElastic 92db446
Merge branch 'main' into feat/action-batch-async
kibanamachine 53c55c4
added script to generate agent docs, fixed bugs
juliaElastic dc10593
renamed action_status response props
juliaElastic 76a87fd
Merge branch 'main' into feat/action-batch-async
kibanamachine abea983
Merge branch 'main' into feat/action-batch-async
juliaElastic 32579ff
Merge branch 'main' into feat/action-batch-async
juliaElastic 6d73425
Merge branch 'main' into feat/action-batch-async
juliaElastic 6c81a64
small cleanup
juliaElastic 6978057
refactor, cleanup
juliaElastic f02b268
added tests
juliaElastic 5525dc1
fixed tests
juliaElastic 97b1edd
upgrade api test
juliaElastic 951566c
Merge branch 'main' into feat/action-batch-async
kibanamachine f1eb373
renamed CurrentAction to ActionStatus model object
juliaElastic be50c8f
moved out action status UI and .fleet-action-status changes to simpli…
juliaElastic c0b02d7
fixed toast message for single agent actions
juliaElastic f26a1f5
added comments
juliaElastic 9e3c01c
Merge branch 'main' into feat/action-batch-async
juliaElastic fa9bb47
fixed conflict resolution
juliaElastic 7e95311
reverted refreshAgents change
juliaElastic 1d7643b
Merge branch 'main' into feat/action-batch-async
kibanamachine 921e96c
review comments
juliaElastic c303407
Merge branch 'main' into feat/action-batch-async
kibanamachine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
...et/public/applications/fleet/sections/agents/agent_list_page/components/action_status.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| import React, { useEffect } from 'react'; | ||
| import { FormattedMessage } from '@kbn/i18n-react'; | ||
| import { | ||
| EuiCallOut, | ||
| EuiFlexGroup, | ||
| EuiFlexItem, | ||
| EuiSpacer, | ||
| EuiLoadingSpinner, | ||
| EuiIcon, | ||
| } from '@elastic/eui'; | ||
|
|
||
| import type { CurrentAction } from '../../../../types'; | ||
| import { useActionStatus } from '../hooks'; | ||
|
|
||
| export const ActionStatusCallout: React.FunctionComponent<{ refreshActionStatus: boolean }> = ({ | ||
|
||
| refreshActionStatus, | ||
| }) => { | ||
| const { currentActions, refreshActions } = useActionStatus(); | ||
|
|
||
| useEffect(() => { | ||
| setTimeout(refreshActions, 10000); | ||
| }, [refreshActionStatus, refreshActions]); | ||
|
|
||
| const actionNames: { [key: string]: string } = { | ||
| POLICY_REASSIGN: 'Reassign', | ||
| UPGRADE: 'Upgrade', | ||
| UNENROLL: 'Unenroll', | ||
| CANCEL: 'Cancel', | ||
| ACTION: 'Action', | ||
| }; | ||
|
|
||
| const calloutTitle = (currentAction: CurrentAction) => ( | ||
| <FormattedMessage | ||
| id="xpack.fleet.currentAction.calloutTitle" | ||
| defaultMessage="{type} {status}, {total} actioned, {nbAgentsAck} acknowledged, {failed} failed, actionId: {actionId}" | ||
| values={{ | ||
| status: currentAction.complete | ||
| ? 'completed' | ||
| : currentAction.timedOut | ||
| ? 'timed out' | ||
| : currentAction.failed > 0 | ||
| ? 'failed' | ||
| : 'in progress', | ||
| type: actionNames[currentAction.type ?? 'ACTION'], | ||
| total: currentAction.total, | ||
| nbAgents: currentAction.nbAgents, | ||
| nbAgentsAck: currentAction.nbAgentsAck, | ||
| actionId: currentAction.actionId, | ||
| failed: currentAction.failed, | ||
| }} | ||
| /> | ||
| ); | ||
| return ( | ||
| <> | ||
| {currentActions | ||
| .filter((action) => action.type !== 'UPGRADE') | ||
| .slice(0, 3) | ||
| .map((currentAction) => ( | ||
| <React.Fragment key={currentAction.actionId}> | ||
| <EuiCallOut | ||
| color={ | ||
| currentAction.complete | ||
| ? 'success' | ||
| : currentAction.timedOut || currentAction.failed > 0 | ||
| ? 'danger' | ||
| : 'primary' | ||
| } | ||
| > | ||
| <EuiFlexGroup | ||
| className="euiCallOutHeader__title" | ||
| justifyContent="spaceBetween" | ||
| alignItems="center" | ||
| gutterSize="none" | ||
| > | ||
| <EuiFlexItem grow={false}> | ||
| <div> | ||
| {!currentAction.complete && !currentAction.timedOut ? ( | ||
| <EuiLoadingSpinner /> | ||
| ) : currentAction.complete ? ( | ||
| <EuiIcon type="check" /> | ||
| ) : ( | ||
| <EuiIcon type="alert" /> | ||
| )} | ||
| | ||
| {calloutTitle(currentAction)} | ||
| </div> | ||
| </EuiFlexItem> | ||
| </EuiFlexGroup> | ||
| </EuiCallOut> | ||
| <EuiSpacer size="l" /> | ||
| </React.Fragment> | ||
| ))} | ||
| </> | ||
| ); | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
...eet/public/applications/fleet/sections/agents/agent_list_page/hooks/use_action_status.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| import { useCallback, useEffect, useRef, useState } from 'react'; | ||
| import { i18n } from '@kbn/i18n'; | ||
|
|
||
| import { sendGetActionStatus, useStartServices } from '../../../../hooks'; | ||
|
|
||
| import type { CurrentAction } from '../../../../types'; | ||
|
|
||
| const POLL_INTERVAL = 30 * 1000; | ||
|
|
||
| export function useActionStatus() { | ||
| const [currentActions, setCurrentActions] = useState<CurrentAction[]>([]); | ||
| const currentTimeoutRef = useRef<NodeJS.Timeout>(); | ||
| const isCancelledRef = useRef<boolean>(false); | ||
| const { notifications } = useStartServices(); | ||
|
|
||
| const refreshActions = useCallback(async () => { | ||
| try { | ||
| const res = await sendGetActionStatus(); | ||
| if (isCancelledRef.current) { | ||
| return; | ||
| } | ||
| if (res.error) { | ||
| throw res.error; | ||
| } | ||
|
|
||
| if (!res.data) { | ||
| throw new Error('No data'); | ||
| } | ||
|
|
||
| setCurrentActions(res.data.items); | ||
| } catch (err) { | ||
| notifications.toasts.addError(err, { | ||
| title: i18n.translate('xpack.fleet.actionStatus.fetchRequestError', { | ||
| defaultMessage: 'An error happened while fetching action status', | ||
| }), | ||
| }); | ||
| } | ||
| }, [notifications.toasts]); | ||
|
|
||
| // Poll for upgrades | ||
| useEffect(() => { | ||
| isCancelledRef.current = false; | ||
|
|
||
| async function pollData() { | ||
| await refreshActions(); | ||
| if (isCancelledRef.current) { | ||
| return; | ||
| } | ||
| currentTimeoutRef.current = setTimeout(() => pollData(), POLL_INTERVAL); | ||
| } | ||
|
|
||
| pollData(); | ||
|
|
||
| return () => { | ||
| isCancelledRef.current = true; | ||
|
|
||
| if (currentTimeoutRef.current) { | ||
| clearTimeout(currentTimeoutRef.current); | ||
| } | ||
| }; | ||
| }, [refreshActions]); | ||
|
|
||
| return { | ||
| currentActions, | ||
| refreshActions, | ||
| }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the
totalcount that represents how many agents were actioned (clicked by user), this helps with status reporting in case something went wrong while creating the action documents in batches.