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

[Fleet] Request diagnostics #142369

Merged
merged 41 commits into from
Nov 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
0ec98c2
request diagnostics action API
juliaElastic Sep 30, 2022
af2e1d6
agent diagnostics action UI
juliaElastic Sep 30, 2022
7a47627
call diagnostics api when clicking button, added modal
juliaElastic Oct 3, 2022
03e6ab6
showing diagnostics uploads list with mock data
juliaElastic Oct 4, 2022
6cc9d88
Merge branch 'main' into feat/request-diagnostics
juliaElastic Oct 5, 2022
478c3d5
bulk request diagnostics
juliaElastic Oct 5, 2022
c559655
query action status to show diagnostics status
juliaElastic Oct 5, 2022
f36b539
fix for failed status display
juliaElastic Oct 5, 2022
c0dcc51
changed implementation to query files index in /uploads API
juliaElastic Oct 5, 2022
46b9000
Merge branch 'main' into feat/request-diagnostics
juliaElastic Oct 5, 2022
383c4bf
Merge branch 'main' into feat/request-diagnostics
kibanamachine Oct 5, 2022
e795a39
implemented file download
juliaElastic Oct 6, 2022
ed1a5d1
changed implementation to add downlaod headers for file
juliaElastic Oct 6, 2022
d537961
added toast when a diagnostics became ready
juliaElastic Oct 6, 2022
f165ee7
added tests on request diagnostics and uploads
juliaElastic Oct 7, 2022
a15ba47
fixed checks
juliaElastic Oct 7, 2022
4b7c5c5
fix checks
juliaElastic Oct 7, 2022
30e16aa
Merge branch 'main' into feat/request-diagnostics
kibanamachine Oct 10, 2022
6684a78
returning always octet stream when downloading file
juliaElastic Oct 10, 2022
63202fc
Merge branch 'main' into feat/request-diagnostics
kibanamachine Oct 12, 2022
6944bc2
Merge branch 'main' into feat/request-diagnostics
kibanamachine Oct 17, 2022
099b1d2
Merge branch 'main' into feat/request-diagnostics
kibanamachine Oct 19, 2022
fc1192b
Merge branch 'main' into feat/request-diagnostics
kibanamachine Oct 24, 2022
8c3d5d6
Merge branch 'main' into feat/request-diagnostics
juliaElastic Oct 31, 2022
e19e68c
Merge branch 'main' into feat/request-diagnostics
kibanamachine Oct 31, 2022
ccdca4a
Merge branch 'main' into feat/request-diagnostics
kibanamachine Nov 2, 2022
26ad93c
Merge branch 'main' into feat/request-diagnostics
kibanamachine Nov 2, 2022
02c6b5a
Merge branch 'main' into feat/request-diagnostics
juliaElastic Nov 2, 2022
f758d96
Update tsconfig.json
juliaElastic Nov 2, 2022
e61a15d
Merge branch 'main' into feat/request-diagnostics
kibanamachine Nov 7, 2022
22ad451
fixed test
juliaElastic Nov 7, 2022
0b56f04
Merge branch 'main' into feat/request-diagnostics
juliaElastic Nov 7, 2022
b164e02
[CI] Auto-commit changed files from 'node scripts/generate codeowners'
kibanamachine Nov 7, 2022
448f0fa
Merge branch 'main' into feat/request-diagnostics
juliaElastic Nov 8, 2022
a486196
added feature flag to hide request diagnostics action
juliaElastic Nov 8, 2022
c0755cf
fixed checks
juliaElastic Nov 8, 2022
b3123fa
fixed test
juliaElastic Nov 8, 2022
820edee
removed mock data and changed the query to return diagnostic files
juliaElastic Nov 8, 2022
3cfaf2e
Merge branch 'main' into feat/request-diagnostics
juliaElastic Nov 8, 2022
d622ed3
fixed integration test
juliaElastic Nov 9, 2022
89888ae
added error handling, extracted index names as constants
juliaElastic Nov 9, 2022
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
4 changes: 4 additions & 0 deletions x-pack/plugins/fleet/common/constants/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ export const AGENT_API_ROUTES = {
BULK_UNENROLL_PATTERN: `${API_ROOT}/agents/bulk_unenroll`,
REASSIGN_PATTERN: `${API_ROOT}/agents/{agentId}/reassign`,
BULK_REASSIGN_PATTERN: `${API_ROOT}/agents/bulk_reassign`,
REQUEST_DIAGNOSTICS_PATTERN: `${API_ROOT}/agents/{agentId}/request_diagnostics`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add the new endpoints to the docs? It can be done in a separate PR as well

BULK_REQUEST_DIAGNOSTICS_PATTERN: `${API_ROOT}/agents/bulk_request_diagnostics`,
AVAILABLE_VERSIONS_PATTERN: `${API_ROOT}/agents/available_versions`,
STATUS_PATTERN: `${API_ROOT}/agent_status`,
DATA_PATTERN: `${API_ROOT}/agent_status/data`,
Expand All @@ -137,6 +139,8 @@ export const AGENT_API_ROUTES = {
CURRENT_UPGRADES_PATTERN: `${API_ROOT}/agents/current_upgrades`,
ACTION_STATUS_PATTERN: `${API_ROOT}/agents/action_status`,
LIST_TAGS_PATTERN: `${API_ROOT}/agents/tags`,
LIST_UPLOADS_PATTERN: `${API_ROOT}/agents/{agentId}/uploads`,
GET_UPLOAD_FILE_PATTERN: `${API_ROOT}/agents/files/{fileId}/{fileName}`,
};

export const ENROLLMENT_API_KEY_ROUTES = {
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/fleet/common/experimental_features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const allowedExperimentalValues = Object.freeze({
createPackagePolicyMultiPageLayout: true,
packageVerification: true,
showDevtoolsRequest: true,
showRequestDiagnostics: false,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added feature flag to hide Request diagnostics action by default at 3 places: Agent list single action, bulk action, Agent details action.
For local testing, set this boolean to true.

Feature flag off:
image
image
image

Toggle on:
image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this!

});

type ExperimentalConfigKeys = Array<keyof ExperimentalFeatures>;
Expand Down
10 changes: 10 additions & 0 deletions x-pack/plugins/fleet/common/services/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,16 @@ export const agentRouteService = {
AGENT_API_ROUTES.ACTIONS_PATTERN.replace('{agentId}', agentId),
getListTagsPath: () => AGENT_API_ROUTES.LIST_TAGS_PATTERN,
getAvailableVersionsPath: () => AGENT_API_ROUTES.AVAILABLE_VERSIONS_PATTERN,
getRequestDiagnosticsPath: (agentId: string) =>
AGENT_API_ROUTES.REQUEST_DIAGNOSTICS_PATTERN.replace('{agentId}', agentId),
getBulkRequestDiagnosticsPath: () => AGENT_API_ROUTES.BULK_REQUEST_DIAGNOSTICS_PATTERN,
getListAgentUploads: (agentId: string) =>
AGENT_API_ROUTES.LIST_UPLOADS_PATTERN.replace('{agentId}', agentId),
getAgentFileDownloadLink: (fileId: string, fileName: string) =>
AGENT_API_ROUTES.GET_UPLOAD_FILE_PATTERN.replace('{fileId}', fileId).replace(
'{fileName}',
fileName
),
};

export const outputRoutesService = {
Expand Down
12 changes: 11 additions & 1 deletion x-pack/plugins/fleet/common/types/models/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ export type AgentActionType =
| 'POLICY_REASSIGN'
| 'CANCEL'
| 'FORCE_UNENROLL'
| 'UPDATE_TAGS';
| 'UPDATE_TAGS'
| 'REQUEST_DIAGNOSTICS';

type FleetServerAgentComponentStatusTuple = typeof FleetServerAgentComponentStatuses;
export type FleetServerAgentComponentStatus = FleetServerAgentComponentStatusTuple[number];
Expand Down Expand Up @@ -142,6 +143,15 @@ export interface ActionStatus {
creationTime: string;
}

export interface AgentDiagnostics {
id: string;
name: string;
createTime: string;
filePath: string;
status: 'READY' | 'AWAITING_UPLOAD' | 'DELETED' | 'IN_PROGRESS';
actionId: string;
}

// Generated from FleetServer schema.json
export interface FleetServerAgentComponentUnit {
id: string;
Expand Down
23 changes: 22 additions & 1 deletion x-pack/plugins/fleet/common/types/rest_spec/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@

import type { SearchHit } from '@kbn/es-types';

import type { Agent, AgentAction, ActionStatus, CurrentUpgrade, NewAgentAction } from '../models';
import type {
Agent,
AgentAction,
ActionStatus,
CurrentUpgrade,
NewAgentAction,
AgentDiagnostics,
} from '../models';

import type { ListResult, ListWithKuery } from './common';

Expand Down Expand Up @@ -38,6 +45,10 @@ export interface GetOneAgentResponse {
item: Agent;
}

export interface GetAgentUploadsResponse {
items: AgentDiagnostics[];
}

export interface PostNewAgentActionRequest {
body: {
action: Omit<NewAgentAction, 'agents'>;
Expand Down Expand Up @@ -121,6 +132,16 @@ export interface PostBulkAgentReassignRequest {
};
}

export type PostRequestDiagnosticsResponse = BulkAgentAction;
export type PostBulkRequestDiagnosticsResponse = BulkAgentAction;

export interface PostRequestBulkDiagnosticsRequest {
body: {
agents: string[] | string;
batchSize?: number;
};
}

export type PostBulkAgentReassignResponse = BulkAgentAction;

export type PostBulkUpdateAgentTagsResponse = BulkAgentAction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import {
} from '../../components';
import { useAgentRefresh } from '../hooks';
import { isAgentUpgradeable, policyHasFleetServer } from '../../../../services';
import { AgentRequestDiagnosticsModal } from '../../components/agent_request_diagnostics_modal';
import { ExperimentalFeaturesService } from '../../../../services';

export const AgentDetailsActionMenu: React.FunctionComponent<{
agent: Agent;
Expand All @@ -32,9 +34,11 @@ export const AgentDetailsActionMenu: React.FunctionComponent<{
const [isReassignFlyoutOpen, setIsReassignFlyoutOpen] = useState(assignFlyoutOpenByDefault);
const [isUnenrollModalOpen, setIsUnenrollModalOpen] = useState(false);
const [isUpgradeModalOpen, setIsUpgradeModalOpen] = useState(false);
const [isRequestDiagnosticsModalOpen, setIsRequestDiagnosticsModalOpen] = useState(false);
const isUnenrolling = agent.status === 'unenrolling';

const hasFleetServer = agentPolicy && policyHasFleetServer(agentPolicy);
const { showRequestDiagnostics } = ExperimentalFeaturesService.get();

const onClose = useMemo(() => {
if (onCancelReassign) {
Expand All @@ -44,6 +48,70 @@ export const AgentDetailsActionMenu: React.FunctionComponent<{
}
}, [onCancelReassign, setIsReassignFlyoutOpen]);

const menuItems = [
<EuiContextMenuItem
icon="pencil"
onClick={() => {
setIsReassignFlyoutOpen(true);
}}
disabled={!agent.active}
key="reassignPolicy"
>
<FormattedMessage
id="xpack.fleet.agentList.reassignActionText"
defaultMessage="Assign to new policy"
/>
</EuiContextMenuItem>,
<EuiContextMenuItem
icon="trash"
disabled={!hasFleetAllPrivileges || !agent.active}
onClick={() => {
setIsUnenrollModalOpen(true);
}}
>
{isUnenrolling ? (
<FormattedMessage
id="xpack.fleet.agentList.forceUnenrollOneButton"
defaultMessage="Force unenroll"
/>
) : (
<FormattedMessage
id="xpack.fleet.agentList.unenrollOneButton"
defaultMessage="Unenroll agent"
/>
)}
</EuiContextMenuItem>,
<EuiContextMenuItem
icon="refresh"
disabled={!isAgentUpgradeable(agent, kibanaVersion)}
onClick={() => {
setIsUpgradeModalOpen(true);
}}
>
<FormattedMessage
id="xpack.fleet.agentList.upgradeOneButton"
defaultMessage="Upgrade agent"
/>
</EuiContextMenuItem>,
];

if (showRequestDiagnostics) {
menuItems.push(
<EuiContextMenuItem
icon="download"
disabled={!hasFleetAllPrivileges}
onClick={() => {
setIsRequestDiagnosticsModalOpen(true);
}}
>
<FormattedMessage
id="xpack.fleet.agentList.diagnosticsOneButton"
defaultMessage="Request diagnostics .zip"
/>
</EuiContextMenuItem>
);
}

return (
<>
{isReassignFlyoutOpen && (
Expand Down Expand Up @@ -77,6 +145,17 @@ export const AgentDetailsActionMenu: React.FunctionComponent<{
/>
</EuiPortal>
)}
{isRequestDiagnosticsModalOpen && (
<EuiPortal>
<AgentRequestDiagnosticsModal
agents={[agent]}
agentCount={1}
onClose={() => {
setIsRequestDiagnosticsModalOpen(false);
}}
/>
</EuiPortal>
)}
<ContextMenuActions
button={{
props: { iconType: 'arrowDown', iconSide: 'right', color: 'primary' },
Expand All @@ -87,52 +166,7 @@ export const AgentDetailsActionMenu: React.FunctionComponent<{
/>
),
}}
items={[
<EuiContextMenuItem
icon="pencil"
onClick={() => {
setIsReassignFlyoutOpen(true);
}}
disabled={!agent.active}
key="reassignPolicy"
>
<FormattedMessage
id="xpack.fleet.agentList.reassignActionText"
defaultMessage="Assign to new policy"
/>
</EuiContextMenuItem>,
<EuiContextMenuItem
icon="trash"
disabled={!hasFleetAllPrivileges || !agent.active}
onClick={() => {
setIsUnenrollModalOpen(true);
}}
>
{isUnenrolling ? (
<FormattedMessage
id="xpack.fleet.agentList.forceUnenrollOneButton"
defaultMessage="Force unenroll"
/>
) : (
<FormattedMessage
id="xpack.fleet.agentList.unenrollOneButton"
defaultMessage="Unenroll agent"
/>
)}
</EuiContextMenuItem>,
<EuiContextMenuItem
icon="refresh"
disabled={!isAgentUpgradeable(agent, kibanaVersion)}
onClick={() => {
setIsUpgradeModalOpen(true);
}}
>
<FormattedMessage
id="xpack.fleet.agentList.upgradeOneButton"
defaultMessage="Upgrade agent"
/>
</EuiContextMenuItem>,
]}
items={menuItems}
/>
</>
);
Expand Down
Loading