Skip to content

Commit

Permalink
[Fleet] Displaying policy changes in Agent activity (#153237)
Browse files Browse the repository at this point in the history
## Summary

Closes #141206

Added queries to `/action_status` API to query policy updates and query
the corresponding revisions of agents.
See more explanation here:
#141206 (comment)

On UI displaying these `POLICY_CHANGE` actions with some additional info
(policy name and new revision).

To test:
- Create agent policies and update them
- See that the policy change appears in agent activity
- Enroll agents to an agent policy and then update the policy
- See that the policy change appears in agent activity, should go
through In progress and then Complete state as the Agents receive the
new policy change revision.

<img width="528" alt="image"
src="https://user-images.githubusercontent.com/90178898/225590483-aa0273c3-df35-42c9-913a-815f130db4c3.png">
<img width="529" alt="image"
src="https://user-images.githubusercontent.com/90178898/225592220-4a43a301-6144-452a-94b8-ae059b4a5de9.png">

### Checklist

- [x] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

---------

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
2 people authored and nkhristinin committed Mar 22, 2023
1 parent 1746fa8 commit 56a8860
Show file tree
Hide file tree
Showing 9 changed files with 520 additions and 88 deletions.
49 changes: 39 additions & 10 deletions x-pack/plugins/fleet/common/openapi/bundled.json
Original file line number Diff line number Diff line change
Expand Up @@ -1791,25 +1791,43 @@
]
},
"nbAgentsActioned": {
"type": "number"
"type": "number",
"description": "number of agents actioned"
},
"nbAgentsActionCreated": {
"type": "number"
"type": "number",
"description": "number of agents included in action from kibana"
},
"nbAgentsAck": {
"type": "number"
"type": "number",
"description": "number of agents that acknowledged the action"
},
"nbAgentsFailed": {
"type": "number"
"type": "number",
"description": "number of agents that failed to execute the action"
},
"version": {
"type": "string"
"type": "string",
"description": "agent version number (UPGRADE action)"
},
"startTime": {
"type": "string"
"type": "string",
"description": "start time of action (scheduled actions)"
},
"type": {
"type": "string"
"type": "string",
"enum": [
"POLICY_REASSIGN",
"UPGRADE",
"UNENROLL",
"FORCE_UNENROLL",
"UPDATE_TAGS",
"CANCEL",
"REQUEST_DIAGNOSTICS",
"SETTINGS",
"POLICY_CHANGE",
"INPUT_ACTION"
]
},
"expiration": {
"type": "string"
Expand All @@ -1821,10 +1839,20 @@
"type": "string"
},
"newPolicyId": {
"type": "string"
"type": "string",
"description": "new policy id (POLICY_REASSIGN action)"
},
"policyId": {
"type": "string",
"description": "policy id (POLICY_CHANGE action)"
},
"revision": {
"type": "string",
"description": "new policy revision (POLICY_CHANGE action)"
},
"creationTime": {
"type": "string"
"type": "string",
"description": "creation time of action"
},
"latestErrors": {
"type": "array",
Expand Down Expand Up @@ -1853,7 +1881,8 @@
"nbAgentsAck",
"nbAgentsFailed",
"status",
"creationTime"
"creationTime",
"type"
]
}
}
Expand Down
26 changes: 26 additions & 0 deletions x-pack/plugins/fleet/common/openapi/bundled.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1123,18 +1123,35 @@ paths:
- ROLLOUT_PASSED
nbAgentsActioned:
type: number
description: number of agents actioned
nbAgentsActionCreated:
type: number
description: number of agents included in action from kibana
nbAgentsAck:
type: number
description: number of agents that acknowledged the action
nbAgentsFailed:
type: number
description: number of agents that failed to execute the action
version:
type: string
description: agent version number (UPGRADE action)
startTime:
type: string
description: start time of action (scheduled actions)
type:
type: string
enum:
- POLICY_REASSIGN
- UPGRADE
- UNENROLL
- FORCE_UNENROLL
- UPDATE_TAGS
- CANCEL
- REQUEST_DIAGNOSTICS
- SETTINGS
- POLICY_CHANGE
- INPUT_ACTION
expiration:
type: string
completionTime:
Expand All @@ -1143,8 +1160,16 @@ paths:
type: string
newPolicyId:
type: string
description: new policy id (POLICY_REASSIGN action)
policyId:
type: string
description: policy id (POLICY_CHANGE action)
revision:
type: string
description: new policy revision (POLICY_CHANGE action)
creationTime:
type: string
description: creation time of action
latestErrors:
type: array
description: >-
Expand All @@ -1168,6 +1193,7 @@ paths:
- nbAgentsFailed
- status
- creationTime
- type
required:
- items
'400':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,35 @@ get:
- ROLLOUT_PASSED
nbAgentsActioned:
type: number
description: number of agents actioned
nbAgentsActionCreated:
type: number
description: number of agents included in action from kibana
nbAgentsAck:
type: number
description: number of agents that acknowledged the action
nbAgentsFailed:
type: number
description: number of agents that failed to execute the action
version:
type: string
description: agent version number (UPGRADE action)
startTime:
type: string
description: start time of action (scheduled actions)
type:
type: string
enum:
- POLICY_REASSIGN
- UPGRADE
- UNENROLL
- FORCE_UNENROLL
- UPDATE_TAGS
- CANCEL
- REQUEST_DIAGNOSTICS
- SETTINGS
- POLICY_CHANGE
- INPUT_ACTION
expiration:
type: string
completionTime:
Expand All @@ -56,8 +73,16 @@ get:
type: string
newPolicyId:
type: string
description: new policy id (POLICY_REASSIGN action)
policyId:
type: string
description: policy id (POLICY_CHANGE action)
revision:
type: string
description: new policy revision (POLICY_CHANGE action)
creationTime:
type: string
description: creation time of action
latestErrors:
type: array
description: latest errors that happened when the agents executed the action
Expand All @@ -79,6 +104,7 @@ get:
- nbAgentsFailed
- status
- creationTime
- type
required:
- items
'400':
Expand Down
8 changes: 6 additions & 2 deletions x-pack/plugins/fleet/common/types/models/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ export type AgentActionType =
| 'CANCEL'
| 'FORCE_UNENROLL'
| 'UPDATE_TAGS'
| 'REQUEST_DIAGNOSTICS';
| 'REQUEST_DIAGNOSTICS'
| 'POLICY_CHANGE'
| 'INPUT_ACTION';

type FleetServerAgentComponentStatusTuple = typeof FleetServerAgentComponentStatuses;
export type FleetServerAgentComponentStatus = FleetServerAgentComponentStatusTuple[number];
Expand Down Expand Up @@ -152,7 +154,7 @@ export interface ActionStatus {
nbAgentsFailed: number;
version?: string;
startTime?: string;
type?: string;
type: AgentActionType;
// how many agents were actioned by the user
nbAgentsActioned: number;
status: 'COMPLETE' | 'EXPIRED' | 'CANCELLED' | 'FAILED' | 'IN_PROGRESS' | 'ROLLOUT_PASSED';
Expand All @@ -163,6 +165,8 @@ export interface ActionStatus {
creationTime: string;
hasRolloutPeriod?: boolean;
latestErrors?: ActionErrorResult[];
revision?: number;
policyId?: string;
}

export interface AgentDiagnostics {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,4 +426,72 @@ describe('AgentActivityFlyout', () => {
.textContent?.replace(/\s/g, '')
).toContain('Completed Sep 15, 2022 12:00 PM'.replace(/\s/g, ''));
});

it('should render agent activity for policy change no agents', () => {
const mockActionStatuses = [
{
actionId: 'action8',
nbAgentsActionCreated: 0,
nbAgentsAck: 0,
type: 'POLICY_CHANGE',
nbAgentsActioned: 0,
status: 'COMPLETE',
expiration: '2099-09-16T10:00:00.000Z',
policyId: 'policy1',
revision: 2,
creationTime: '2022-09-15T10:00:00.000Z',
nbAgentsFailed: 0,
completionTime: '2022-09-15T11:00:00.000Z',
},
];
mockUseActionStatus.mockReturnValue({
currentActions: mockActionStatuses,
abortUpgrade: mockAbortUpgrade,
isFirstLoading: true,
});
const result = renderComponent();

expect(result.container.querySelector('[data-test-subj="statusTitle"]')!.textContent).toEqual(
'Policy changed'
);
expect(
result.container
.querySelector('[data-test-subj="statusDescription"]')!
.textContent?.replace(/\s/g, '')
).toContain('Policy1 changed to revision 2 at Sep 15, 2022 10:00 AM.'.replace(/\s/g, ''));
});

it('should render agent activity for policy change with agents', () => {
const mockActionStatuses = [
{
actionId: 'action8',
nbAgentsActionCreated: 3,
nbAgentsAck: 3,
type: 'POLICY_CHANGE',
nbAgentsActioned: 3,
status: 'COMPLETE',
expiration: '2099-09-16T10:00:00.000Z',
policyId: 'policy1',
revision: 2,
creationTime: '2022-09-15T10:00:00.000Z',
nbAgentsFailed: 0,
completionTime: '2022-09-15T11:00:00.000Z',
},
];
mockUseActionStatus.mockReturnValue({
currentActions: mockActionStatuses,
abortUpgrade: mockAbortUpgrade,
isFirstLoading: true,
});
const result = renderComponent();

expect(result.container.querySelector('[data-test-subj="statusTitle"]')!.textContent).toEqual(
'3 agents applied policy change'
);
expect(
result.container
.querySelector('[data-test-subj="statusDescription"]')!
.textContent?.replace(/\s/g, '')
).toContain('Policy1 changed to revision 2 at Sep 15, 2022 10:00 AM.'.replace(/\s/g, ''));
});
});
Loading

0 comments on commit 56a8860

Please sign in to comment.