Skip to content

Add fleet policy revisions cleanup task#242612

Merged
MichelLosier merged 24 commits intoelastic:mainfrom
MichelLosier:add-fleet-policy-revisions-cleanup-task
Nov 24, 2025
Merged

Add fleet policy revisions cleanup task#242612
MichelLosier merged 24 commits intoelastic:mainfrom
MichelLosier:add-fleet-policy-revisions-cleanup-task

Conversation

@MichelLosier
Copy link
Contributor

@MichelLosier MichelLosier commented Nov 11, 2025

Summary

Resolves: #119963
PR to add new Kibana config to allow list: https://github.com/elastic/cloud/pull/149322

  • Adds the background task FleetPolicyRevisionsCleanupTask which removes excess policy revisions from the .fleet-policies index
  • Enabled by default, disabled by new feature flag:
 xpack.fleet.experimentalFeatures:
  enableFleetPolicyRevisionsCleanupTask: true
  • Configurable with the following:
xpack.fleet.fleetPolicyRevisionsCleanup:
  interval: string // Time interval expression. Default: '1h'
  max_revisions: number // Maximum amount of policy revisions. Default: 10.
  max_policies_per_run: number // Maximum policies to delete revisions from per run. Default 100.
  • Also adds an internal endpoint for the same operation:
POST kbn:/internal/fleet/agent_policies/_cleanup_revisions
{
    "maxRevisions": number, // max revisions a policy should have
    "maxPolicies": number, // max policies to process
}

Release notes

  • Adds the background task FleetPolicyRevisionsCleanupTask which removes excess policy revisions from the .fleet-policies index

Details

  • The task will look for the top max_policies_per_run sorted by document count, filtered down to those exceeding the max_revisions
  • It will then lookup the minimum revision index used by agents for each policy.
  • Policy revision documents will be deleted for each policy that have an idx at or below the max_revisions cutoff, which is calculated from the minimum revision used by agents for that policy or the latest revision idx
  • The delete_by_query for removing policy revisions is configured for a max_docs of 5000, which means at most 1 job run will only delete 5000 at a time.

The idea here is to optimize for low resource environments, and slowly burn down revisions for environments that have had revisions counts run away. The exposed configuration allows for more aggressive use for those that need it.

Manual testing

This PR introduces a --revisions flag for the create_agents script to generate a set amount of revisions per policy.
Example:

node scripts/create_agents --kibana http://0.0.0.0:5601/kibana --count 5 --batches 100 --concurrentBatches 100  --revisions 1000

Will create 100 policies with 5 agents and 1000 revisions each.

Configure kibana.dev.yml to the task parameters, as described above, you want to test with.

Check revisions counts in the kibana dev console:

GET .fleet-policies/_search
{
	"size": 0,
	"aggs": {
		"latest_revisions_by_policy_id": {
			"terms": {
				"field": "policy_id",
				"order": { "_count": "desc" }
			},
			"aggs": {
				"latest_revision": {
					"max": {
						"field": "revision_idx"
					}
				}
			}
		}
	}
}

Additionally the new internal endpoint can also be used to perform the same operation in the dev console:

POST kbn:/internal/fleet/agent_policies/_cleanup_revisions?apiVersion=1
{
    "maxRevisions": 10,
    "maxPolicies": 100
}

Checklist

Check the PR satisfies following conditions.

Reviewers should verify this PR satisfies this list as well.

  • Any text added follows EUI's writing guidelines, uses sentence case text and includes i18n support
  • Documentation was added for features that require explanation or tutorials
  • Unit or functional tests were updated or added to match the most common scenarios
  • If a plugin configuration key changed, check if it needs to be allowlisted in the cloud and added to the docker list
  • This was checked for breaking HTTP API changes, and any breaking changes have been approved by the breaking-change committee. The release_note:breaking label should be applied in these situations.
  • Flaky Test Runner was used on any tests changed
  • The PR description includes the appropriate Release Notes section, and the correct release_note:* label is applied per the guidelines
  • Review the backport guidelines and apply applicable backport:* labels.

Identify risks

Does this PR introduce any risks? For example, consider risks like hard to test bugs, performance regression, potential of data loss.

Describe the risk, its severity, and mitigation for each identified risk. Invite stakeholders and evaluate how to proceed before merging.

@MichelLosier
Copy link
Contributor Author

/ci

@MichelLosier
Copy link
Contributor Author

Open for early review. Next steps here:

  • Add internal API endpoint to run this job on demand
    • Use internal API for FTR tests
@MichelLosier
Copy link
Contributor Author

/ci

@MichelLosier MichelLosier marked this pull request as ready for review November 20, 2025 19:17
@MichelLosier MichelLosier requested a review from a team as a code owner November 20, 2025 19:17
Copy link
Member

@nchaulet nchaulet left a comment

Choose a reason for hiding this comment

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

a few suggestions, code LGTM 🚀

@botelastic botelastic bot added the Team:Fleet Team label for Observability Data Collection Fleet team label Nov 20, 2025
@elasticmachine
Copy link
Contributor

Pinging @elastic/fleet (Team:Fleet)

@MichelLosier MichelLosier self-assigned this Nov 24, 2025
eokoneyo pushed a commit to eokoneyo/kibana that referenced this pull request Dec 2, 2025
Resolves: elastic#119963
PR to add new Kibana config to allow list:
elastic/cloud#149322

* Adds the background task `FleetPolicyRevisionsCleanupTask` which
removes excess policy revisions from the `.fleet-policies` index
* Enabled by default, disabled by new feature flag:
```
 xpack.fleet.experimentalFeatures:
  enableFleetPolicyRevisionsCleanupTask: true
```
* Configurable with the following:

```
xpack.fleet.fleetPolicyRevisionsCleanup:
  interval: string // Time interval expression. Default: '1h'
  max_revisions: number // Maximum amount of policy revisions. Default: 10.
  max_policies_per_run: number // Maximum policies to delete revisions from per run. Default 100.
```
* Also adds an internal endpoint for the same operation:

```
POST kbn:/internal/fleet/agent_policies/_cleanup_revisions?apiVersion=1
{
    "maxRevisions": number, // max revisions a policy should have
    "maxPolicies": number, // max policies to process
}
```
---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
@shahzad31
Copy link
Contributor

@MichelLosier would it be possible to backport this to 8.19?

@MichelLosier MichelLosier added backport:version Backport to applied version labels and removed backport:skip This PR does not require backporting labels Dec 9, 2025
@kibanamachine kibanamachine added backport:skip This PR does not require backporting and removed backport:version Backport to applied version labels labels Dec 9, 2025
@MichelLosier MichelLosier added backport:version Backport to applied version labels v8.19.9 and removed backport:skip This PR does not require backporting labels Dec 9, 2025
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.19

https://github.com/elastic/kibana/actions/runs/20076604803

@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.19

https://github.com/elastic/kibana/actions/runs/20076604866

@kibanamachine
Copy link
Contributor

💔 All backports failed

Status Branch Result
8.19 Backport failed because of merge conflicts

Manual backport

To create the backport manually run:

node scripts/backport --pr 242612

Questions ?

Please refer to the Backport tool documentation

1 similar comment
@kibanamachine
Copy link
Contributor

💔 All backports failed

Status Branch Result
8.19 Backport failed because of merge conflicts

Manual backport

To create the backport manually run:

node scripts/backport --pr 242612

Questions ?

Please refer to the Backport tool documentation

MichelLosier added a commit to MichelLosier/kibana that referenced this pull request Dec 9, 2025
Resolves: elastic#119963
PR to add new Kibana config to allow list:
elastic/cloud#149322

* Adds the background task `FleetPolicyRevisionsCleanupTask` which
removes excess policy revisions from the `.fleet-policies` index
* Enabled by default, disabled by new feature flag:
```
 xpack.fleet.experimentalFeatures:
  enableFleetPolicyRevisionsCleanupTask: true
```
* Configurable with the following:

```
xpack.fleet.fleetPolicyRevisionsCleanup:
  interval: string // Time interval expression. Default: '1h'
  max_revisions: number // Maximum amount of policy revisions. Default: 10.
  max_policies_per_run: number // Maximum policies to delete revisions from per run. Default 100.
```
* Also adds an internal endpoint for the same operation:

```
POST kbn:/internal/fleet/agent_policies/_cleanup_revisions?apiVersion=1
{
    "maxRevisions": number, // max revisions a policy should have
    "maxPolicies": number, // max policies to process
}
```
---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
(cherry picked from commit d2e01dc)

# Conflicts:
#	x-pack/platform/plugins/shared/fleet/common/experimental_features.ts
#	x-pack/platform/plugins/shared/fleet/moon.yml
#	x-pack/platform/test/fleet_api_integration/config.base.ts
#	x-pack/platform/test/plugin_api_integration/test_suites/task_manager/check_registered_task_types.ts
MichelLosier added a commit to MichelLosier/kibana that referenced this pull request Dec 9, 2025
Resolves: elastic#119963
PR to add new Kibana config to allow list:
elastic/cloud#149322

* Adds the background task `FleetPolicyRevisionsCleanupTask` which
removes excess policy revisions from the `.fleet-policies` index
* Enabled by default, disabled by new feature flag:
```
 xpack.fleet.experimentalFeatures:
  enableFleetPolicyRevisionsCleanupTask: true
```
* Configurable with the following:

```
xpack.fleet.fleetPolicyRevisionsCleanup:
  interval: string // Time interval expression. Default: '1h'
  max_revisions: number // Maximum amount of policy revisions. Default: 10.
  max_policies_per_run: number // Maximum policies to delete revisions from per run. Default 100.
```
* Also adds an internal endpoint for the same operation:

```
POST kbn:/internal/fleet/agent_policies/_cleanup_revisions?apiVersion=1
{
    "maxRevisions": number, // max revisions a policy should have
    "maxPolicies": number, // max policies to process
}
```
---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
(cherry picked from commit d2e01dc)

# Conflicts:
#	x-pack/platform/plugins/shared/fleet/common/experimental_features.ts
#	x-pack/platform/plugins/shared/fleet/common/types/index.ts
#	x-pack/platform/plugins/shared/fleet/moon.yml
#	x-pack/platform/plugins/shared/fleet/server/config.ts
#	x-pack/platform/plugins/shared/fleet/server/plugin.ts
#	x-pack/platform/test/fleet_api_integration/config.base.ts
#	x-pack/platform/test/plugin_api_integration/test_suites/task_manager/check_registered_task_types.ts
@MichelLosier
Copy link
Contributor Author

💚 All backports created successfully

Status Branch Result
9.2
9.1
8.19

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

MichelLosier added a commit to MichelLosier/kibana that referenced this pull request Dec 9, 2025
Resolves: elastic#119963
PR to add new Kibana config to allow list:
elastic/cloud#149322

* Adds the background task `FleetPolicyRevisionsCleanupTask` which
removes excess policy revisions from the `.fleet-policies` index
* Enabled by default, disabled by new feature flag:
```
 xpack.fleet.experimentalFeatures:
  enableFleetPolicyRevisionsCleanupTask: true
```
* Configurable with the following:

```
xpack.fleet.fleetPolicyRevisionsCleanup:
  interval: string // Time interval expression. Default: '1h'
  max_revisions: number // Maximum amount of policy revisions. Default: 10.
  max_policies_per_run: number // Maximum policies to delete revisions from per run. Default 100.
```
* Also adds an internal endpoint for the same operation:

```
POST kbn:/internal/fleet/agent_policies/_cleanup_revisions?apiVersion=1
{
    "maxRevisions": number, // max revisions a policy should have
    "maxPolicies": number, // max policies to process
}
```
---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
(cherry picked from commit d2e01dc)

# Conflicts:
#	x-pack/platform/plugins/shared/fleet/common/constants/routes.ts
#	x-pack/platform/plugins/shared/fleet/common/experimental_features.ts
#	x-pack/platform/plugins/shared/fleet/common/types/index.ts
#	x-pack/platform/plugins/shared/fleet/moon.yml
#	x-pack/platform/plugins/shared/fleet/server/config.test.ts
#	x-pack/platform/plugins/shared/fleet/server/config.ts
#	x-pack/platform/plugins/shared/fleet/server/plugin.ts
#	x-pack/platform/plugins/shared/fleet/server/routes/agent_policy/handlers.ts
#	x-pack/platform/plugins/shared/fleet/server/routes/agent_policy/index.ts
#	x-pack/platform/plugins/shared/fleet/server/types/rest_spec/agent_policy.ts
#	x-pack/platform/test/fleet_api_integration/apis/agent_policy/index.js
#	x-pack/platform/test/fleet_api_integration/config.base.ts
#	x-pack/platform/test/plugin_api_integration/test_suites/task_manager/check_registered_task_types.ts
#	x-pack/platform/test/serverless/functional/test_suites/common/examples/search/index.ts
MichelLosier added a commit that referenced this pull request Dec 9, 2025
# Backport

This will backport the following commits from `main` to `9.2`:
- [Add fleet policy revisions cleanup task
(#242612)](#242612)

<!--- Backport version: 10.2.0 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Michel
Losier","email":"michel.losier@elastic.co"},"sourceCommit":{"committedDate":"2025-11-24T18:53:39Z","message":"Add
fleet policy revisions cleanup task (#242612)\n\nResolves:
https://github.com/elastic/kibana/issues/119963\nPR to add new Kibana
config to allow list:\nhttps://github.com/elastic/cloud/pull/149322\n\n*
Adds the background task `FleetPolicyRevisionsCleanupTask`
which\nremoves excess policy revisions from the `.fleet-policies`
index\n* Enabled by default, disabled by new feature flag:\n```\n
xpack.fleet.experimentalFeatures:\n
enableFleetPolicyRevisionsCleanupTask: true\n```\n* Configurable with
the following:\n\n```\nxpack.fleet.fleetPolicyRevisionsCleanup:\n
interval: string // Time interval expression. Default: '1h'\n
max_revisions: number // Maximum amount of policy revisions. Default:
10.\n max_policies_per_run: number // Maximum policies to delete
revisions from per run. Default 100.\n```\n* Also adds an internal
endpoint for the same operation:\n\n```\nPOST
kbn:/internal/fleet/agent_policies/_cleanup_revisions?apiVersion=1\n{\n
\"maxRevisions\": number, // max revisions a policy should have\n
\"maxPolicies\": number, // max policies to
process\n}\n```\n---------\n\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"d2e01dc368b018be3f09de5eb65e2ba5e2ef95a0","branchLabelMapping":{"^v9.3.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:enhancement","Team:Fleet","ci:cloud-deploy","backport:version","v9.3.0","v9.2.3","v9.1.9","v8.19.9"],"title":"Add
fleet policy revisions cleanup
task","number":242612,"url":"https://github.com/elastic/kibana/pull/242612","mergeCommit":{"message":"Add
fleet policy revisions cleanup task (#242612)\n\nResolves:
https://github.com/elastic/kibana/issues/119963\nPR to add new Kibana
config to allow list:\nhttps://github.com/elastic/cloud/pull/149322\n\n*
Adds the background task `FleetPolicyRevisionsCleanupTask`
which\nremoves excess policy revisions from the `.fleet-policies`
index\n* Enabled by default, disabled by new feature flag:\n```\n
xpack.fleet.experimentalFeatures:\n
enableFleetPolicyRevisionsCleanupTask: true\n```\n* Configurable with
the following:\n\n```\nxpack.fleet.fleetPolicyRevisionsCleanup:\n
interval: string // Time interval expression. Default: '1h'\n
max_revisions: number // Maximum amount of policy revisions. Default:
10.\n max_policies_per_run: number // Maximum policies to delete
revisions from per run. Default 100.\n```\n* Also adds an internal
endpoint for the same operation:\n\n```\nPOST
kbn:/internal/fleet/agent_policies/_cleanup_revisions?apiVersion=1\n{\n
\"maxRevisions\": number, // max revisions a policy should have\n
\"maxPolicies\": number, // max policies to
process\n}\n```\n---------\n\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"d2e01dc368b018be3f09de5eb65e2ba5e2ef95a0"}},"sourceBranch":"main","suggestedTargetBranches":["9.2","9.1","8.19"],"targetPullRequestStates":[{"branch":"main","label":"v9.3.0","branchLabelMappingKey":"^v9.3.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/242612","number":242612,"mergeCommit":{"message":"Add
fleet policy revisions cleanup task (#242612)\n\nResolves:
https://github.com/elastic/kibana/issues/119963\nPR to add new Kibana
config to allow list:\nhttps://github.com/elastic/cloud/pull/149322\n\n*
Adds the background task `FleetPolicyRevisionsCleanupTask`
which\nremoves excess policy revisions from the `.fleet-policies`
index\n* Enabled by default, disabled by new feature flag:\n```\n
xpack.fleet.experimentalFeatures:\n
enableFleetPolicyRevisionsCleanupTask: true\n```\n* Configurable with
the following:\n\n```\nxpack.fleet.fleetPolicyRevisionsCleanup:\n
interval: string // Time interval expression. Default: '1h'\n
max_revisions: number // Maximum amount of policy revisions. Default:
10.\n max_policies_per_run: number // Maximum policies to delete
revisions from per run. Default 100.\n```\n* Also adds an internal
endpoint for the same operation:\n\n```\nPOST
kbn:/internal/fleet/agent_policies/_cleanup_revisions?apiVersion=1\n{\n
\"maxRevisions\": number, // max revisions a policy should have\n
\"maxPolicies\": number, // max policies to
process\n}\n```\n---------\n\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"d2e01dc368b018be3f09de5eb65e2ba5e2ef95a0"}},{"branch":"9.2","label":"v9.2.3","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"9.1","label":"v9.1.9","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.19","label":"v8.19.9","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->
MichelLosier added a commit that referenced this pull request Dec 9, 2025
# Backport

This will backport the following commits from `main` to `8.19`:
- [Add fleet policy revisions cleanup task
(#242612)](#242612)

<!--- Backport version: 10.2.0 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Michel
Losier","email":"michel.losier@elastic.co"},"sourceCommit":{"committedDate":"2025-11-24T18:53:39Z","message":"Add
fleet policy revisions cleanup task (#242612)\n\nResolves:
https://github.com/elastic/kibana/issues/119963\nPR to add new Kibana
config to allow list:\nhttps://github.com/elastic/cloud/pull/149322\n\n*
Adds the background task `FleetPolicyRevisionsCleanupTask`
which\nremoves excess policy revisions from the `.fleet-policies`
index\n* Enabled by default, disabled by new feature flag:\n```\n
xpack.fleet.experimentalFeatures:\n
enableFleetPolicyRevisionsCleanupTask: true\n```\n* Configurable with
the following:\n\n```\nxpack.fleet.fleetPolicyRevisionsCleanup:\n
interval: string // Time interval expression. Default: '1h'\n
max_revisions: number // Maximum amount of policy revisions. Default:
10.\n max_policies_per_run: number // Maximum policies to delete
revisions from per run. Default 100.\n```\n* Also adds an internal
endpoint for the same operation:\n\n```\nPOST
kbn:/internal/fleet/agent_policies/_cleanup_revisions?apiVersion=1\n{\n
\"maxRevisions\": number, // max revisions a policy should have\n
\"maxPolicies\": number, // max policies to
process\n}\n```\n---------\n\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"d2e01dc368b018be3f09de5eb65e2ba5e2ef95a0","branchLabelMapping":{"^v9.3.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:enhancement","Team:Fleet","ci:cloud-deploy","backport:version","v9.3.0","v9.2.3","v9.1.9","v8.19.9"],"title":"Add
fleet policy revisions cleanup
task","number":242612,"url":"https://github.com/elastic/kibana/pull/242612","mergeCommit":{"message":"Add
fleet policy revisions cleanup task (#242612)\n\nResolves:
https://github.com/elastic/kibana/issues/119963\nPR to add new Kibana
config to allow list:\nhttps://github.com/elastic/cloud/pull/149322\n\n*
Adds the background task `FleetPolicyRevisionsCleanupTask`
which\nremoves excess policy revisions from the `.fleet-policies`
index\n* Enabled by default, disabled by new feature flag:\n```\n
xpack.fleet.experimentalFeatures:\n
enableFleetPolicyRevisionsCleanupTask: true\n```\n* Configurable with
the following:\n\n```\nxpack.fleet.fleetPolicyRevisionsCleanup:\n
interval: string // Time interval expression. Default: '1h'\n
max_revisions: number // Maximum amount of policy revisions. Default:
10.\n max_policies_per_run: number // Maximum policies to delete
revisions from per run. Default 100.\n```\n* Also adds an internal
endpoint for the same operation:\n\n```\nPOST
kbn:/internal/fleet/agent_policies/_cleanup_revisions?apiVersion=1\n{\n
\"maxRevisions\": number, // max revisions a policy should have\n
\"maxPolicies\": number, // max policies to
process\n}\n```\n---------\n\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"d2e01dc368b018be3f09de5eb65e2ba5e2ef95a0"}},"sourceBranch":"main","suggestedTargetBranches":["9.2","9.1","8.19"],"targetPullRequestStates":[{"branch":"main","label":"v9.3.0","branchLabelMappingKey":"^v9.3.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/242612","number":242612,"mergeCommit":{"message":"Add
fleet policy revisions cleanup task (#242612)\n\nResolves:
https://github.com/elastic/kibana/issues/119963\nPR to add new Kibana
config to allow list:\nhttps://github.com/elastic/cloud/pull/149322\n\n*
Adds the background task `FleetPolicyRevisionsCleanupTask`
which\nremoves excess policy revisions from the `.fleet-policies`
index\n* Enabled by default, disabled by new feature flag:\n```\n
xpack.fleet.experimentalFeatures:\n
enableFleetPolicyRevisionsCleanupTask: true\n```\n* Configurable with
the following:\n\n```\nxpack.fleet.fleetPolicyRevisionsCleanup:\n
interval: string // Time interval expression. Default: '1h'\n
max_revisions: number // Maximum amount of policy revisions. Default:
10.\n max_policies_per_run: number // Maximum policies to delete
revisions from per run. Default 100.\n```\n* Also adds an internal
endpoint for the same operation:\n\n```\nPOST
kbn:/internal/fleet/agent_policies/_cleanup_revisions?apiVersion=1\n{\n
\"maxRevisions\": number, // max revisions a policy should have\n
\"maxPolicies\": number, // max policies to
process\n}\n```\n---------\n\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"d2e01dc368b018be3f09de5eb65e2ba5e2ef95a0"}},{"branch":"9.2","label":"v9.2.3","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"9.1","label":"v9.1.9","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.19","label":"v8.19.9","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->
MichelLosier added a commit that referenced this pull request Dec 10, 2025
# Backport

This will backport the following commits from `main` to `9.1`:
- [Add fleet policy revisions cleanup task
(#242612)](#242612)

<!--- Backport version: 10.2.0 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Michel
Losier","email":"michel.losier@elastic.co"},"sourceCommit":{"committedDate":"2025-11-24T18:53:39Z","message":"Add
fleet policy revisions cleanup task (#242612)\n\nResolves:
https://github.com/elastic/kibana/issues/119963\nPR to add new Kibana
config to allow list:\nhttps://github.com/elastic/cloud/pull/149322\n\n*
Adds the background task `FleetPolicyRevisionsCleanupTask`
which\nremoves excess policy revisions from the `.fleet-policies`
index\n* Enabled by default, disabled by new feature flag:\n```\n
xpack.fleet.experimentalFeatures:\n
enableFleetPolicyRevisionsCleanupTask: true\n```\n* Configurable with
the following:\n\n```\nxpack.fleet.fleetPolicyRevisionsCleanup:\n
interval: string // Time interval expression. Default: '1h'\n
max_revisions: number // Maximum amount of policy revisions. Default:
10.\n max_policies_per_run: number // Maximum policies to delete
revisions from per run. Default 100.\n```\n* Also adds an internal
endpoint for the same operation:\n\n```\nPOST
kbn:/internal/fleet/agent_policies/_cleanup_revisions?apiVersion=1\n{\n
\"maxRevisions\": number, // max revisions a policy should have\n
\"maxPolicies\": number, // max policies to
process\n}\n```\n---------\n\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"d2e01dc368b018be3f09de5eb65e2ba5e2ef95a0","branchLabelMapping":{"^v9.3.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:enhancement","Team:Fleet","ci:cloud-deploy","backport:version","v9.3.0","v9.2.3","v9.1.9","v8.19.9"],"title":"Add
fleet policy revisions cleanup
task","number":242612,"url":"https://github.com/elastic/kibana/pull/242612","mergeCommit":{"message":"Add
fleet policy revisions cleanup task (#242612)\n\nResolves:
https://github.com/elastic/kibana/issues/119963\nPR to add new Kibana
config to allow list:\nhttps://github.com/elastic/cloud/pull/149322\n\n*
Adds the background task `FleetPolicyRevisionsCleanupTask`
which\nremoves excess policy revisions from the `.fleet-policies`
index\n* Enabled by default, disabled by new feature flag:\n```\n
xpack.fleet.experimentalFeatures:\n
enableFleetPolicyRevisionsCleanupTask: true\n```\n* Configurable with
the following:\n\n```\nxpack.fleet.fleetPolicyRevisionsCleanup:\n
interval: string // Time interval expression. Default: '1h'\n
max_revisions: number // Maximum amount of policy revisions. Default:
10.\n max_policies_per_run: number // Maximum policies to delete
revisions from per run. Default 100.\n```\n* Also adds an internal
endpoint for the same operation:\n\n```\nPOST
kbn:/internal/fleet/agent_policies/_cleanup_revisions?apiVersion=1\n{\n
\"maxRevisions\": number, // max revisions a policy should have\n
\"maxPolicies\": number, // max policies to
process\n}\n```\n---------\n\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"d2e01dc368b018be3f09de5eb65e2ba5e2ef95a0"}},"sourceBranch":"main","suggestedTargetBranches":["9.2","9.1","8.19"],"targetPullRequestStates":[{"branch":"main","label":"v9.3.0","branchLabelMappingKey":"^v9.3.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/242612","number":242612,"mergeCommit":{"message":"Add
fleet policy revisions cleanup task (#242612)\n\nResolves:
https://github.com/elastic/kibana/issues/119963\nPR to add new Kibana
config to allow list:\nhttps://github.com/elastic/cloud/pull/149322\n\n*
Adds the background task `FleetPolicyRevisionsCleanupTask`
which\nremoves excess policy revisions from the `.fleet-policies`
index\n* Enabled by default, disabled by new feature flag:\n```\n
xpack.fleet.experimentalFeatures:\n
enableFleetPolicyRevisionsCleanupTask: true\n```\n* Configurable with
the following:\n\n```\nxpack.fleet.fleetPolicyRevisionsCleanup:\n
interval: string // Time interval expression. Default: '1h'\n
max_revisions: number // Maximum amount of policy revisions. Default:
10.\n max_policies_per_run: number // Maximum policies to delete
revisions from per run. Default 100.\n```\n* Also adds an internal
endpoint for the same operation:\n\n```\nPOST
kbn:/internal/fleet/agent_policies/_cleanup_revisions?apiVersion=1\n{\n
\"maxRevisions\": number, // max revisions a policy should have\n
\"maxPolicies\": number, // max policies to
process\n}\n```\n---------\n\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"d2e01dc368b018be3f09de5eb65e2ba5e2ef95a0"}},{"branch":"9.2","label":"v9.2.3","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"9.1","label":"v9.1.9","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.19","label":"v8.19.9","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->
@lucabelluccini
Copy link
Contributor

Thanks for the backports!

MichelLosier added a commit that referenced this pull request Jan 14, 2026
Adds documentation for the `xpack.fleet.fleetPolicyRevisionsCleanup` configuration added in

#242612
elastic/cloud#149322

---------

Co-authored-by: florent-leborgne <florent.leborgne@elastic.co>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:version Backport to applied version labels ci:cloud-deploy Create or update a Cloud deployment release_note:enhancement Team:Fleet Team label for Observability Data Collection Fleet team v8.19.9 v9.1.9 v9.2.3 v9.3.0

8 participants