From cdc8ec0eaf2998286096d4cc24bbf5205a5924e4 Mon Sep 17 00:00:00 2001
From: Julia Bardi <90178898+juliaElastic@users.noreply.github.com>
Date: Tue, 7 Mar 2023 15:44:44 +0100
Subject: [PATCH] [Fleet] Display errors in Agent activity with link to Logs
(#152583)
## Summary
Improvement of Agent activity to show action errors with a link to
`Review error logs`
Part of https://github.com/elastic/kibana/issues/141206
Extended `action_status` API to return latest errors, these are the most
recent docs from `.fleet-action-results` that require errors.
We could do something more clever like aggregate the most frequent
errors and take the top hits from each bucket if that's a desirable
feature to group the same errors together.
To verify:
- Enroll agents (with horde/normally)
- Trigger some actions with failures (e.g. upgrade agents that are not
upgradeable, change artifact repo to an invalid url)
- Go to Agent Activity and click on `Show errors` under the failed
actions.
- The last 3 errors will be shown, with buttons to `Review error log`.
These are distinct errors per agent id.
- Click on `Review error log`, verify that the `Logs UI` shows the
expected filters (see
[here](https://github.com/elastic/kibana/pull/152583#discussion_r1126481201))
```
GET kbn:/api/fleet/agents/action_status
{
"actionId": "3de4a573-011b-4c8c-9ccb-c6516bcc27d2",
"nbAgentsActionCreated": 1,
"nbAgentsAck": 0,
"version": "8.6.1",
"startTime": "2023-02-28T16:34:10.553Z",
"type": "UPGRADE",
"nbAgentsActioned": 102,
"status": "FAILED",
"expiration": "2023-02-28T16:54:10.553Z",
"creationTime": "2023-02-28T16:34:50.352Z",
"nbAgentsFailed": 102,
"hasRolloutPeriod": true,
"completionTime": "2023-02-28T16:39:28.000Z",
"latestErrors": [
{
"agentId": "906560bc-2af4-4916-8261-3769e8c38931",
"error": """failed verification of agent binary: 2 errors occurred:
* fetching asc file from '/Library/Elastic/Agent/data/elastic-agent-496e7e/downloads/elastic-agent-8.6.1-darwin-x86_64.tar.gz.asc': open /Library/Elastic/Agent/data/elastic-agent-496e7e/downloads/elastic-agent-8.6.1-darwin-x86_64.tar.gz.asc: no such file or directory
* invalid signature for /Library/Elastic/Agent/data/elastic-agent-496e7e/downloads/elastic-agent-8.6.1-darwin-x86_64.tar.gz: openpgp: invalid signature: hash tag doesn't match
""",
"timestamp": "2023-02-28T16:39:28Z",
"hostname": "Julias-MacBook-Pro.local"
},
{
"agentId": "080bf24f-f3ac-4256-b525-41d5bec1514e",
"error": "Agent 080bf24f-f3ac-4256-b525-41d5bec1514e is not upgradeable",
"timestamp": "2023-02-28T16:34:50.715Z",
"hostname": "Julias-MacBook-Pro.local"
},
{
"agentId": "6c6cbc39-5214-4001-928d-374bfed8ef1d",
"error": "Agent 6c6cbc39-5214-4001-928d-374bfed8ef1d is not upgradeable",
"timestamp": "2023-02-28T16:34:50.715Z",
"hostname": "Julias-MacBook-Pro.local"
}
]
},
```
Added an accordion on the UI to show error messages with a link to Logs.
In the design there was only one `Review error logs` button per action,
I thought it is better to drill down to a specific agent id, we could do
either/both.
See reasoning here
https://github.com/elastic/kibana/issues/141206#issuecomment-1451634339
Latest styling, included host name on UI after feedback from Nima:
### 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: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
---
.../plugins/fleet/common/openapi/bundled.json | 29 ++++-
.../plugins/fleet/common/openapi/bundled.yaml | 20 +++
.../openapi/paths/agents@action_status.yaml | 18 +++
.../fleet/common/types/models/agent.ts | 8 ++
.../components/agent_activity_flyout.tsx | 6 +
.../components/view_errors.test.tsx | 64 ++++++++++
.../components/view_errors.tsx | 115 ++++++++++++++++++
.../server/services/agents/action_status.ts | 73 ++++++++++-
x-pack/plugins/fleet/server/types/index.tsx | 1 +
.../fleet/server/types/rest_spec/agent.ts | 1 +
x-pack/plugins/fleet/tsconfig.json | 1 +
.../apis/agents/action_status.ts | 12 ++
12 files changed, 342 insertions(+), 6 deletions(-)
create mode 100644 x-pack/plugins/fleet/public/applications/fleet/sections/agents/agent_list_page/components/view_errors.test.tsx
create mode 100644 x-pack/plugins/fleet/public/applications/fleet/sections/agents/agent_list_page/components/view_errors.tsx
diff --git a/x-pack/plugins/fleet/common/openapi/bundled.json b/x-pack/plugins/fleet/common/openapi/bundled.json
index 4ff0b522325ca6..6bc611d0238878 100644
--- a/x-pack/plugins/fleet/common/openapi/bundled.json
+++ b/x-pack/plugins/fleet/common/openapi/bundled.json
@@ -1705,6 +1705,14 @@
},
{
"$ref": "#/components/parameters/page_index"
+ },
+ {
+ "schema": {
+ "type": "integer",
+ "default": 5
+ },
+ "in": "query",
+ "name": "errorSize"
}
],
"responses": {
@@ -1730,7 +1738,8 @@
"EXPIRED",
"CANCELLED",
"FAILED",
- "IN_PROGRESS"
+ "IN_PROGRESS",
+ "ROLLOUT_PASSED"
]
},
"nbAgentsActioned": {
@@ -1768,6 +1777,24 @@
},
"creationTime": {
"type": "string"
+ },
+ "latestErrors": {
+ "type": "array",
+ "description": "latest errors that happened when the agents executed the action",
+ "items": {
+ "type": "object",
+ "properties": {
+ "agentId": {
+ "type": "string"
+ },
+ "error": {
+ "type": "string"
+ },
+ "timestamp": {
+ "type": "string"
+ }
+ }
+ }
}
},
"required": [
diff --git a/x-pack/plugins/fleet/common/openapi/bundled.yaml b/x-pack/plugins/fleet/common/openapi/bundled.yaml
index 9d6ae17a04a412..5c14990778c32f 100644
--- a/x-pack/plugins/fleet/common/openapi/bundled.yaml
+++ b/x-pack/plugins/fleet/common/openapi/bundled.yaml
@@ -1063,6 +1063,11 @@ paths:
parameters:
- $ref: '#/components/parameters/page_size'
- $ref: '#/components/parameters/page_index'
+ - schema:
+ type: integer
+ default: 5
+ in: query
+ name: errorSize
responses:
'200':
description: OK
@@ -1086,6 +1091,7 @@ paths:
- CANCELLED
- FAILED
- IN_PROGRESS
+ - ROLLOUT_PASSED
nbAgentsActioned:
type: number
nbAgentsActionCreated:
@@ -1110,6 +1116,20 @@ paths:
type: string
creationTime:
type: string
+ latestErrors:
+ type: array
+ description: >-
+ latest errors that happened when the agents executed
+ the action
+ items:
+ type: object
+ properties:
+ agentId:
+ type: string
+ error:
+ type: string
+ timestamp:
+ type: string
required:
- actionId
- complete
diff --git a/x-pack/plugins/fleet/common/openapi/paths/agents@action_status.yaml b/x-pack/plugins/fleet/common/openapi/paths/agents@action_status.yaml
index 1c2d013457d6f3..6daea7e6ebb2bb 100644
--- a/x-pack/plugins/fleet/common/openapi/paths/agents@action_status.yaml
+++ b/x-pack/plugins/fleet/common/openapi/paths/agents@action_status.yaml
@@ -5,6 +5,11 @@ get:
parameters:
- $ref: ../components/parameters/page_size.yaml
- $ref: ../components/parameters/page_index.yaml
+ - schema:
+ type: integer
+ default: 5
+ in: query
+ name: errorSize
responses:
'200':
description: OK
@@ -28,6 +33,7 @@ get:
- CANCELLED
- FAILED
- IN_PROGRESS
+ - ROLLOUT_PASSED
nbAgentsActioned:
type: number
nbAgentsActionCreated:
@@ -52,6 +58,18 @@ get:
type: string
creationTime:
type: string
+ latestErrors:
+ type: array
+ description: latest errors that happened when the agents executed the action
+ items:
+ type: object
+ properties:
+ agentId:
+ type: string
+ error:
+ type: string
+ timestamp:
+ type: string
required:
- actionId
- complete
diff --git a/x-pack/plugins/fleet/common/types/models/agent.ts b/x-pack/plugins/fleet/common/types/models/agent.ts
index 537d0f250e8282..0d5e15088219e4 100644
--- a/x-pack/plugins/fleet/common/types/models/agent.ts
+++ b/x-pack/plugins/fleet/common/types/models/agent.ts
@@ -135,6 +135,13 @@ export interface CurrentUpgrade {
startTime?: string;
}
+export interface ActionErrorResult {
+ agentId: string;
+ error: string;
+ timestamp: string;
+ hostname?: string;
+}
+
export interface ActionStatus {
actionId: string;
// how many agents are successfully included in action documents
@@ -155,6 +162,7 @@ export interface ActionStatus {
newPolicyId?: string;
creationTime: string;
hasRolloutPeriod?: boolean;
+ latestErrors?: ActionErrorResult[];
}
export interface AgentDiagnostics {
diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/agent_list_page/components/agent_activity_flyout.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/agent_list_page/components/agent_activity_flyout.tsx
index b57e1aea8b39ea..de6da14fd5014d 100644
--- a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/agent_list_page/components/agent_activity_flyout.tsx
+++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/agent_list_page/components/agent_activity_flyout.tsx
@@ -35,6 +35,7 @@ import { SO_SEARCH_LIMIT } from '../../../../constants';
import { Loading } from '../../components';
import { getTodayActions, getOtherDaysActions } from './agent_activity_helper';
+import { ViewErrors } from './view_errors';
const FullHeightFlyoutBody = styled(EuiFlyoutBody)`
.euiFlyoutBody__overflowContent {
@@ -502,6 +503,11 @@ const ActivityItem: React.FunctionComponent<{ action: ActionStatus }> = ({ actio
{displayByStatus[action.status].description}
+