-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[Fleet] Save package policy previous revision on package upgrade #222779
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jillguyonnet
merged 27 commits into
elastic:main
from
jillguyonnet:fleet/keep-package-policy-previous-revisions
Jun 20, 2025
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
64a535d
[Fleet] Save package policy previous revision on package upgrade
jillguyonnet bf592c1
[CI] Auto-commit changed files from 'node scripts/jest_integration -u…
kibanamachine 4e52fec
Feedback
jillguyonnet d7efcc5
[CI] Auto-commit changed files from 'node scripts/jest_integration -u…
kibanamachine 7157e40
Save previous package SO
jillguyonnet 7c68f60
Fix package revision save
jillguyonnet 7a4ce88
[CI] Auto-commit changed files from 'node scripts/capture_oas_snapsho…
kibanamachine 0acc2c9
[CI] Auto-commit changed files from 'node scripts/jest_integration -u…
kibanamachine e710b9a
Add package SO backfill
jillguyonnet d01d843
[CI] Auto-commit changed files from 'make api-docs'
kibanamachine f51ac42
Fix FTR tests
jillguyonnet 53a8b0e
Fix more FTR tests
jillguyonnet 7cfea07
Fix merge conflict mistake
jillguyonnet e97f252
[CI] Auto-commit changed files from 'node scripts/capture_oas_snapsho…
kibanamachine 6e422a6
[CI] Auto-commit changed files from 'node scripts/jest_integration -u…
kibanamachine cd08738
Save previous version in package SO on update
jillguyonnet 079ff49
Fix
jillguyonnet f2a3dfd
[CI] Auto-commit changed files from 'make api-docs'
kibanamachine 4e9cad6
[CI] Auto-commit changed files from 'node scripts/jest_integration -u…
kibanamachine 9d9bf02
Merge branch 'main' into fleet/keep-package-policy-previous-revisions
elasticmachine 3eb4c3e
Fix
jillguyonnet 2796dfd
Fix remaining test failures
jillguyonnet 78b2eed
Add check for bulk creating/updating previous revisions
jillguyonnet 77b5bae
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine 69526e8
Merge branch 'main' into fleet/keep-package-policy-previous-revisions
jillguyonnet f598e69
Merge branch 'main' into fleet/keep-package-policy-previous-revisions
elasticmachine 773a995
Remove mapping definition of monitoring-entity-source
jillguyonnet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...fleet/server/saved_objects/model_versions/package_policy_latest_revision_backfill.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| import type { | ||
| SavedObject, | ||
| SavedObjectModelTransformationContext, | ||
| } from '@kbn/core-saved-objects-server'; | ||
|
|
||
| import type { PackagePolicy } from '../../../common'; | ||
|
|
||
| import { backfillPackagePolicyLatestRevision } from './package_policy_latest_revision_backfill'; | ||
|
|
||
| describe('backfillPackagePolicyLatestRevision', () => { | ||
| const packagePolicyDoc: SavedObject<PackagePolicy & { latest_revision?: boolean }> = { | ||
| id: 'policy1', | ||
| type: 'ingest-package-policies', | ||
| references: [], | ||
| attributes: { | ||
| id: 'policy1', | ||
| name: 'Policy 1', | ||
| namespace: 'default', | ||
| description: '', | ||
| policy_id: 'policy1', | ||
| policy_ids: ['policy1'], | ||
| package: { name: 'test-package', version: '1.0.0', title: 'Test Package' }, | ||
| inputs: [], | ||
| revision: 1, | ||
| updated_at: '2021-08-17T14:00:00.000Z', | ||
| updated_by: 'elastic', | ||
| created_at: '2021-08-17T14:00:00.000Z', | ||
| created_by: 'elastic', | ||
| enabled: true, | ||
| }, | ||
| }; | ||
|
|
||
| it('should set latest_revision to true if not defined', () => { | ||
| const migratedPackagePolicyDoc = backfillPackagePolicyLatestRevision( | ||
| packagePolicyDoc, | ||
| {} as SavedObjectModelTransformationContext | ||
| ); | ||
|
|
||
| expect(migratedPackagePolicyDoc.attributes.latest_revision).toBe(true); | ||
| }); | ||
|
|
||
| it('should not change latest_revision if already defined', () => { | ||
| const migratedPackagePolicyDoc = backfillPackagePolicyLatestRevision( | ||
| { | ||
| ...packagePolicyDoc, | ||
| attributes: { | ||
| ...packagePolicyDoc.attributes, | ||
| latest_revision: false, | ||
| }, | ||
| }, | ||
| {} as SavedObjectModelTransformationContext | ||
| ); | ||
|
|
||
| expect(migratedPackagePolicyDoc.attributes.latest_revision).toBe(false); | ||
| }); | ||
| }); |
21 changes: 21 additions & 0 deletions
21
...ared/fleet/server/saved_objects/model_versions/package_policy_latest_revision_backfill.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| import type { SavedObjectModelDataBackfillFn } from '@kbn/core-saved-objects-server'; | ||
|
|
||
| import type { PackagePolicy } from '../../../common'; | ||
|
|
||
| export const backfillPackagePolicyLatestRevision: SavedObjectModelDataBackfillFn< | ||
| PackagePolicy & { latest_revision?: boolean }, | ||
| PackagePolicy & { latest_revision?: boolean } | ||
| > = (packagePolicyDoc) => { | ||
| if (packagePolicyDoc.attributes.latest_revision === undefined) { | ||
| packagePolicyDoc.attributes.latest_revision = true; | ||
| } | ||
|
|
||
| return packagePolicyDoc; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're removing all fields from this SO type? Not sure I understand where this change is coming from, I see this type was introduced 2 weeks ago with #219680.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed on Slack, #219680 renamed
monitoring-entity-sourcetoentity-analytics-monitoring-entity-source. I've deleted the entire definition ofmonitoring-entity-sourceaccordingly.