[Fleet] Save package policy previous revision on package upgrade (#222779)

## Summary

Closes https://github.com/elastic/ingest-dev/issues/5444

* Add `enablePackageRollback` feature flag
* Save package policy previous revision on package upgrade
* Add `latest_revision` boolean property to
`ingest-package-policies/fleet-package-policies` saved object type
   * Package policy SO are created with `latest_revision: true`
* When a package policy is updated with a new package version, the
previous SO is saved to ES with id `{id}:prev` and `latest_revision:
false`
   * Backfill existing SO with `latest_revision: true`
   * GET logic filters for `latest_revision: true`
* Save package previous version
   * Add `previous_version` property to `epm-packages` saved object type
   * When a package is upgraded to a new version, set `previous_version`

### Testing

* Install an integration on an outdated version (edit the version in the
URL and add the integration).
* Check the package policy SO: it should have been created with
`latest_revision: true`.
* Check the package SO: the `previous_version` property should not be
set.
* Upgrade the integration and upgrade package policies.
* Check the package policy SO: there should now be 2 SO for this package
policy:
   * The updated one with `latest_revision: true` and policy id
* The previous one with `latest_revision: false` and `{policy_id}:prev`
* Check the package SO: the `previous_version` property should be set to
the old version

Note: it seems Fleet only allows upgrading packages to the latest
version (please correct me if that's wrong); for testing two consecutive
updates (e.g. check that only the most recent revision is saved), it
might be necessary to run a custom EPR.

### 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
- [x] The PR description includes the appropriate Release Notes section,
and the correct `release_note:*` label is applied per the
[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

### Identify risks

Risk of bad requests across Fleet wherever packages or package policies
are queried.

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
Jill Guyonnet 2025-06-20 10:37:23 +02:00 committed by GitHub
parent 8bd7f0e522
commit c5280d74bd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 307 additions and 26 deletions

View file

@ -313,12 +313,9 @@
"enabled",
"error",
"filter",
"indexPattern",
"integrationName",
"managed",
"matchers",
"matchers.fields",
"matchers.values",
"name",
"type"
],
@ -373,6 +370,7 @@
"latest_install_failed_attempts",
"name",
"package_assets",
"previous_version",
"verification_key_id",
"verification_status",
"version"
@ -550,6 +548,7 @@
"enabled",
"inputs",
"is_managed",
"latest_revision",
"name",
"namespace",
"output_id",
@ -735,6 +734,7 @@
"enabled",
"inputs",
"is_managed",
"latest_revision",
"name",
"namespace",
"output_id",
@ -841,19 +841,6 @@
"job.job_id",
"model_id"
],
"monitoring-entity-source": [
"enabled",
"error",
"filter",
"indexPattern",
"integrationName",
"managed",
"matchers",
"matchers.fields",
"matchers.values",
"name",
"type"
],
"monitoring-telemetry": [
"reportedClusterUuids"
],

View file

@ -1256,6 +1256,9 @@
"dynamic": false,
"properties": {}
},
"previous_version": {
"type": "keyword"
},
"verification_key_id": {
"type": "keyword"
},
@ -1835,6 +1838,9 @@
"is_managed": {
"type": "boolean"
},
"latest_revision": {
"type": "boolean"
},
"name": {
"type": "keyword"
},
@ -2438,6 +2444,9 @@
"is_managed": {
"type": "boolean"
},
"latest_revision": {
"type": "boolean"
},
"name": {
"type": "keyword"
},