Skip to content

Commit

Permalink
[Fleet] delete unenrolled agents task (elastic#195544)
Browse files Browse the repository at this point in the history
## Summary

Closes elastic#189506

Testing steps:
- enable deleting unenrolled agents by adding
`xpack.fleet.enableDeleteUnenrolledAgents: true` to `kibana.dev.yml` or
turn it on on the UI
- add some unenroll agents with the helper script
```
cd x-pack/plugins/fleet
node scripts/create_agents/index.js --status unenrolled --count 10

 info Creating 10 agents with statuses:
 info    unenrolled: 10
 info Batch complete, created 10 agent docs, took 0, errors: false
 info All batches complete. Created 10 agents in total. Goodbye!
```
- restart kibana or wait for the task to run and verify that the
unenrolled agents were deleted
```
[2024-10-08T16:14:45.152+02:00][DEBUG][plugins.fleet.fleet:delete-unenrolled-agents-task:0.0.5] [DeleteUnenrolledAgentsTask] Executed deletion of 10 unenrolled agents
[2024-10-08T16:14:45.153+02:00][INFO ][plugins.fleet.fleet:delete-unenrolled-agents-task:0.0.5] [DeleteUnenrolledAgentsTask] runTask ended: success
```

Added to UI settings:
<img width="1057" alt="image"
src="https://github.com/user-attachments/assets/2c9279f9-86a8-4630-a6cd-5aaa42e05fe7">

If the flag is preconfigured, disabled update on the UI with a tooltip:
<img width="1009" alt="image"
src="https://github.com/user-attachments/assets/45041020-6447-4295-995e-6848f0238f88">

The update is also prevented from the API:
<img width="2522" alt="image"
src="https://github.com/user-attachments/assets/cfbc8e21-e062-4e7f-9d08-9767fa387752">

Once the preconfiguration is removed, the UI update is allowed again.


### Checklist

- [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 <[email protected]>
  • Loading branch information
juliaElastic and kibanamachine authored Oct 14, 2024
1 parent 94ee8d5 commit c53b2a8
Show file tree
Hide file tree
Showing 31 changed files with 1,041 additions and 29 deletions.
52 changes: 49 additions & 3 deletions oas_docs/bundle.json
Original file line number Diff line number Diff line change
Expand Up @@ -26150,7 +26150,7 @@
},
"/api/fleet/logstash_api_keys": {
"post": {
"description": "Generate Logstash API keyy",
"description": "Generate Logstash API key",
"operationId": "%2Fapi%2Ffleet%2Flogstash_api_keys#0",
"parameters": [
{
Expand Down Expand Up @@ -40259,6 +40259,22 @@
"item": {
"additionalProperties": false,
"properties": {
"delete_unenrolled_agents": {
"additionalProperties": false,
"properties": {
"enabled": {
"type": "boolean"
},
"is_preconfigured": {
"type": "boolean"
}
},
"required": [
"enabled",
"is_preconfigured"
],
"type": "object"
},
"fleet_server_hosts": {
"items": {
"type": "string"
Expand Down Expand Up @@ -40305,7 +40321,6 @@
}
},
"required": [
"prerelease_integrations_enabled",
"id"
],
"type": "object"
Expand Down Expand Up @@ -40404,6 +40419,22 @@
"additional_yaml_config": {
"type": "string"
},
"delete_unenrolled_agents": {
"additionalProperties": false,
"properties": {
"enabled": {
"type": "boolean"
},
"is_preconfigured": {
"type": "boolean"
}
},
"required": [
"enabled",
"is_preconfigured"
],
"type": "object"
},
"fleet_server_hosts": {
"items": {
"format": "uri",
Expand Down Expand Up @@ -40443,6 +40474,22 @@
"item": {
"additionalProperties": false,
"properties": {
"delete_unenrolled_agents": {
"additionalProperties": false,
"properties": {
"enabled": {
"type": "boolean"
},
"is_preconfigured": {
"type": "boolean"
}
},
"required": [
"enabled",
"is_preconfigured"
],
"type": "object"
},
"fleet_server_hosts": {
"items": {
"type": "string"
Expand Down Expand Up @@ -40489,7 +40536,6 @@
}
},
"required": [
"prerelease_integrations_enabled",
"id"
],
"type": "object"
Expand Down
52 changes: 49 additions & 3 deletions oas_docs/bundle.serverless.json
Original file line number Diff line number Diff line change
Expand Up @@ -26150,7 +26150,7 @@
},
"/api/fleet/logstash_api_keys": {
"post": {
"description": "Generate Logstash API keyy",
"description": "Generate Logstash API key",
"operationId": "%2Fapi%2Ffleet%2Flogstash_api_keys#0",
"parameters": [
{
Expand Down Expand Up @@ -40259,6 +40259,22 @@
"item": {
"additionalProperties": false,
"properties": {
"delete_unenrolled_agents": {
"additionalProperties": false,
"properties": {
"enabled": {
"type": "boolean"
},
"is_preconfigured": {
"type": "boolean"
}
},
"required": [
"enabled",
"is_preconfigured"
],
"type": "object"
},
"fleet_server_hosts": {
"items": {
"type": "string"
Expand Down Expand Up @@ -40305,7 +40321,6 @@
}
},
"required": [
"prerelease_integrations_enabled",
"id"
],
"type": "object"
Expand Down Expand Up @@ -40404,6 +40419,22 @@
"additional_yaml_config": {
"type": "string"
},
"delete_unenrolled_agents": {
"additionalProperties": false,
"properties": {
"enabled": {
"type": "boolean"
},
"is_preconfigured": {
"type": "boolean"
}
},
"required": [
"enabled",
"is_preconfigured"
],
"type": "object"
},
"fleet_server_hosts": {
"items": {
"format": "uri",
Expand Down Expand Up @@ -40443,6 +40474,22 @@
"item": {
"additionalProperties": false,
"properties": {
"delete_unenrolled_agents": {
"additionalProperties": false,
"properties": {
"enabled": {
"type": "boolean"
},
"is_preconfigured": {
"type": "boolean"
}
},
"required": [
"enabled",
"is_preconfigured"
],
"type": "object"
},
"fleet_server_hosts": {
"items": {
"type": "string"
Expand Down Expand Up @@ -40489,7 +40536,6 @@
}
},
"required": [
"prerelease_integrations_enabled",
"id"
],
"type": "object"
Expand Down
37 changes: 34 additions & 3 deletions oas_docs/output/kibana.serverless.staging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23652,7 +23652,7 @@ paths:
- Elastic Agent policies
/api/fleet/logstash_api_keys:
post:
description: Generate Logstash API keyy
description: Generate Logstash API key
operationId: '%2Fapi%2Ffleet%2Flogstash_api_keys#0'
parameters:
- description: The version of the API to use
Expand Down Expand Up @@ -33283,6 +33283,17 @@ paths:
additionalProperties: false
type: object
properties:
delete_unenrolled_agents:
additionalProperties: false
type: object
properties:
enabled:
type: boolean
is_preconfigured:
type: boolean
required:
- enabled
- is_preconfigured
fleet_server_hosts:
items:
type: string
Expand Down Expand Up @@ -33314,7 +33325,6 @@ paths:
version:
type: string
required:
- prerelease_integrations_enabled
- id
required:
- item
Expand Down Expand Up @@ -33376,6 +33386,17 @@ paths:
properties:
additional_yaml_config:
type: string
delete_unenrolled_agents:
additionalProperties: false
type: object
properties:
enabled:
type: boolean
is_preconfigured:
type: boolean
required:
- enabled
- is_preconfigured
fleet_server_hosts:
items:
format: uri
Expand Down Expand Up @@ -33404,6 +33425,17 @@ paths:
additionalProperties: false
type: object
properties:
delete_unenrolled_agents:
additionalProperties: false
type: object
properties:
enabled:
type: boolean
is_preconfigured:
type: boolean
required:
- enabled
- is_preconfigured
fleet_server_hosts:
items:
type: string
Expand Down Expand Up @@ -33435,7 +33467,6 @@ paths:
version:
type: string
required:
- prerelease_integrations_enabled
- id
required:
- item
Expand Down
37 changes: 34 additions & 3 deletions oas_docs/output/kibana.serverless.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23652,7 +23652,7 @@ paths:
- Elastic Agent policies
/api/fleet/logstash_api_keys:
post:
description: Generate Logstash API keyy
description: Generate Logstash API key
operationId: '%2Fapi%2Ffleet%2Flogstash_api_keys#0'
parameters:
- description: The version of the API to use
Expand Down Expand Up @@ -33283,6 +33283,17 @@ paths:
additionalProperties: false
type: object
properties:
delete_unenrolled_agents:
additionalProperties: false
type: object
properties:
enabled:
type: boolean
is_preconfigured:
type: boolean
required:
- enabled
- is_preconfigured
fleet_server_hosts:
items:
type: string
Expand Down Expand Up @@ -33314,7 +33325,6 @@ paths:
version:
type: string
required:
- prerelease_integrations_enabled
- id
required:
- item
Expand Down Expand Up @@ -33376,6 +33386,17 @@ paths:
properties:
additional_yaml_config:
type: string
delete_unenrolled_agents:
additionalProperties: false
type: object
properties:
enabled:
type: boolean
is_preconfigured:
type: boolean
required:
- enabled
- is_preconfigured
fleet_server_hosts:
items:
format: uri
Expand Down Expand Up @@ -33404,6 +33425,17 @@ paths:
additionalProperties: false
type: object
properties:
delete_unenrolled_agents:
additionalProperties: false
type: object
properties:
enabled:
type: boolean
is_preconfigured:
type: boolean
required:
- enabled
- is_preconfigured
fleet_server_hosts:
items:
type: string
Expand Down Expand Up @@ -33435,7 +33467,6 @@ paths:
version:
type: string
required:
- prerelease_integrations_enabled
- id
required:
- item
Expand Down
Loading

0 comments on commit c53b2a8

Please sign in to comment.