Skip to content
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

[Fleet] Implement state machine behavior for package install #178657

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
d4710a3
[Fleet] Implement state machine behavior for package install
criamico Mar 13, 2024
94aaa4d
fix types and test
criamico Mar 13, 2024
7234abd
Merge branch 'main' into 175592_package_lifecycle_state_machine
kibanamachine Mar 14, 2024
b89756e
Improve naming
criamico Mar 14, 2024
7e027ec
Add context and start writing new function
criamico Mar 14, 2024
6a54196
Merge branch 'main' into 175592_package_lifecycle_state_machine
kibanamachine Mar 18, 2024
f68cdcd
Add post transition function
criamico Mar 18, 2024
28d4de0
Save data between iterations
criamico Mar 19, 2024
59cd767
Improvements to state machine
criamico Mar 20, 2024
fffba51
Remove wrapper function and return updatedContext
criamico Mar 20, 2024
6267ec6
Implement step functions
criamico Mar 21, 2024
8c00a9b
remove changes to _install_packages
criamico Mar 22, 2024
addab4d
Merge branch 'main' into 175592_package_lifecycle_state_machine
kibanamachine Mar 22, 2024
04f0e2d
Naming changes and tests
criamico Mar 22, 2024
25c5ea5
Add feature flag and plug new functions
criamico Mar 22, 2024
d92c638
Merge branch 'main' into 175592_package_lifecycle_state_machine
kibanamachine Mar 25, 2024
c3d5537
Fix error in header functions and add logging
criamico Mar 25, 2024
c6f080f
Fix errors in install process and modify logging
criamico Mar 26, 2024
8074328
Fix unit tests and add feature flag check
criamico Mar 26, 2024
16ac037
Save latest executed state in saved object and improve unit tests
criamico Mar 27, 2024
5f09e58
Merge branch 'main' into 175592_package_lifecycle_state_machine
kibanamachine Mar 27, 2024
a82bd68
[CI] Auto-commit changed files from 'node scripts/check_mappings_upda…
kibanamachine Mar 27, 2024
cefff9b
Save error in saved object
criamico Mar 27, 2024
fa85aa6
Add unit tests
criamico Mar 28, 2024
5f850b6
Merge branch 'main' into 175592_package_lifecycle_state_machine
kibanamachine Mar 28, 2024
18ded6f
Add openapi changes and fix wrong parameter name
criamico Mar 28, 2024
12a0e33
[CI] Auto-commit changed files from 'node scripts/jest_integration -u…
kibanamachine Mar 28, 2024
6059c93
Fix type error
criamico Mar 28, 2024
5746610
Fixes to the logic, add tests
criamico Mar 29, 2024
f88752d
Split up steps in smaller functions and improve files organization
criamico Mar 29, 2024
e9ee148
Enable feature flag for integration tests
criamico Mar 29, 2024
0f81778
Merge branch 'main' into 175592_package_lifecycle_state_machine
kibanamachine Mar 29, 2024
28edd3b
Fix filename
criamico Mar 29, 2024
4a16aeb
Fix missing assets return
criamico Apr 2, 2024
beeaefd
Merge branch 'main' into 175592_package_lifecycle_state_machine
kibanamachine Apr 2, 2024
741065f
Fix postTransition call
criamico Apr 2, 2024
6f7809c
Address code review comments
criamico Apr 2, 2024
1beb1bb
remove console log
criamico Apr 2, 2024
dc95c45
fix integration test and add unit test
criamico Apr 3, 2024
f503c1d
Fix tests and enable feature flag
criamico Apr 4, 2024
9d969e6
Merge branch 'main' into 175592_package_lifecycle_state_machine
kibanamachine Apr 4, 2024
44f1924
Unit test for create_restart_installation
criamico Apr 4, 2024
9a09893
Merge branch 'main' into 175592_package_lifecycle_state_machine
kibanamachine Apr 4, 2024
d49a317
Fix unit test
criamico Apr 4, 2024
783ca85
Add more unit tests and try fixing mapping change
criamico Apr 5, 2024
3a26fb4
Add unit test for stepDeletePreviousPipelines
criamico Apr 5, 2024
ef9a9fa
Merge branch 'main' into 175592_package_lifecycle_state_machine
kibanamachine Apr 5, 2024
179db75
More unit tests for install steps
criamico Apr 5, 2024
11b1432
Merge branch 'main' into 175592_package_lifecycle_state_machine
kibanamachine Apr 8, 2024
4a96479
Add unit test for stepSaveSystemObject
criamico Apr 8, 2024
117feaf
Merge branch 'main' into 175592_package_lifecycle_state_machine
kibanamachine Apr 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export const HASH_TO_VERSION_MAP = {
'endpoint:user-artifact-manifest|7502b5c5bc923abe8aa5ccfd636e8c3d': '10.0.0',
'enterprise_search_telemetry|3d1b76c39bfb2cc8296b024d73854724': '10.0.0',
'epm-packages-assets|44621b2f6052ef966da47b7c3a00f33b': '10.0.0',
'epm-packages|c1e2020399dbebba2448096ca007c668': '10.1.0',
'epm-packages|8ce219acd0f6f3529237d52193866afb': '10.2.0',
'event_loop_delays_daily|5df7e292ddd5028e07c1482e130e6654': '10.0.0',
'event-annotation-group|df07b1a361c32daf4e6842c1d5521dbe': '10.0.0',
'exception-list-agnostic|8a1defe5981db16792cb9a772e84bb9a': '10.0.0',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@
"installed_kibana_space_id",
"internal",
"keep_policies_up_to_date",
"latest_executed_state",
"latest_install_failed_attempts",
"name",
"package_assets",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1003,6 +1003,10 @@
"index": false,
"type": "boolean"
},
"latest_executed_state": {
"enabled": false,
"type": "object"
},
"latest_install_failed_attempts": {
"enabled": false,
"type": "object"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ describe('checking migration metadata changes on all registered SO types', () =>
"dashboard": "211e9ca30f5a95d5f3c27b1bf2b58e6cfa0c9ae9",
"endpoint:user-artifact-manifest": "1c3533161811a58772e30cdc77bac4631da3ef2b",
"enterprise_search_telemetry": "9ac912e1417fc8681e0cd383775382117c9e3d3d",
"epm-packages": "c23d3d00c051a08817335dba26f542b64b18a56a",
"epm-packages": "f8ee125b57df31fd035dc04ad81aef475fd2f5bd",
"epm-packages-assets": "7a3e58efd9a14191d0d1a00b8aaed30a145fd0b1",
"event-annotation-group": "715ba867d8c68f3c9438052210ea1c30a9362582",
"event_loop_delays_daily": "01b967e8e043801357503de09199dfa3853bab88",
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/fleet/common/experimental_features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const allowedExperimentalValues = Object.freeze<Record<string, boolean>>(
agentless: false,
enableStrictKQLValidation: false,
subfeaturePrivileges: false,
enablePackagesStateMachine: true,
});

type ExperimentalConfigKeys = Array<keyof ExperimentalFeatures>;
Expand Down
28 changes: 28 additions & 0 deletions x-pack/plugins/fleet/common/openapi/bundled.json
Original file line number Diff line number Diff line change
Expand Up @@ -6302,6 +6302,34 @@
}
}
},
"latest_executed_state": {
"description": "Latest successfully executed state in package install state machine",
"type": "object",
"properties": {
"name": {
"type": "string",
"enum": [
"create_restart_installation",
"install_kibana_assets",
"install_ilm_policies",
"install_ml_model",
"install_index_template_pipelines",
"remove_legacy_templates",
"update_current_write_indices",
"install_transforms",
"delete_previous_pipelines",
"save_archive_entries_from_assets_map",
"update_so"
]
},
"started_at": {
"type": "string"
},
"error": {
"type": "string"
}
}
},
"verification_status": {
"type": "string",
"enum": [
Expand Down
22 changes: 22 additions & 0 deletions x-pack/plugins/fleet/common/openapi/bundled.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3970,6 +3970,28 @@ components:
type: string
stack:
type: string
latest_executed_state:
description: Latest successfully executed state in package install state machine
type: object
properties:
name:
type: string
enum:
- create_restart_installation
- install_kibana_assets
- install_ilm_policies
- install_ml_model
- install_index_template_pipelines
- remove_legacy_templates
- update_current_write_indices
- install_transforms
- delete_previous_pipelines
- save_archive_entries_from_assets_map
- update_so
started_at:
type: string
error:
type: string
verification_status:
type: string
enum:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,28 @@ properties:
type: string
stack:
type: string
latest_executed_state:
description: Latest successfully executed state in package install state machine
type: object
properties:
name:
type: string
enum:
- create_restart_installation
- install_kibana_assets
- install_ilm_policies
- install_ml_model
- install_index_template_pipelines
- remove_legacy_templates
- update_current_write_indices
- install_transforms
- delete_previous_pipelines
- save_archive_entries_from_assets_map
- update_so
started_at:
type: string
error:
type: string
verification_status:
type: string
enum:
Expand Down
32 changes: 32 additions & 0 deletions x-pack/plugins/fleet/common/types/models/epm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export type InstallType = 'reinstall' | 'reupdate' | 'rollback' | 'update' | 'in
export type InstallSource = 'registry' | 'upload' | 'bundled' | 'custom';

export type EpmPackageInstallStatus = 'installed' | 'installing' | 'install_failed';
export type InstallResultStatus = 'installed' | 'already_installed';

export type ServiceName = 'kibana' | 'elasticsearch';
export type AgentAssetType = typeof agentAssetTypes;
Expand Down Expand Up @@ -548,6 +549,36 @@ export interface InstallFailedAttempt {
};
}

export enum INSTALL_STATES {
CREATE_RESTART_INSTALLATION = 'create_restart_installation',
INSTALL_KIBANA_ASSETS = 'install_kibana_assets',
INSTALL_ILM_POLICIES = 'install_ilm_policies',
INSTALL_ML_MODEL = 'install_ml_model',
INSTALL_INDEX_TEMPLATE_PIPELINES = 'install_index_template_pipelines',
REMOVE_LEGACY_TEMPLATES = 'remove_legacy_templates',
UPDATE_CURRENT_WRITE_INDICES = 'update_current_write_indices',
INSTALL_TRANSFORMS = 'install_transforms',
DELETE_PREVIOUS_PIPELINES = 'delete_previous_pipelines',
SAVE_ARCHIVE_ENTRIES = 'save_archive_entries_from_assets_map',
RESOLVE_KIBANA_PROMISE = 'resolve_kibana_promise',
UPDATE_SO = 'update_so',
}
type StatesKeys = keyof typeof INSTALL_STATES;
export type StateNames = typeof INSTALL_STATES[StatesKeys];

export interface LatestExecutedState<T> {
name: T;
started_at: string;
error?: string;
}

export type InstallLatestExecutedState = LatestExecutedState<StateNames>;

export interface StateContext<T> {
[key: string]: any;
latestExecutedState?: LatestExecutedState<T>;
}

export interface Installation {
installed_kibana: KibanaAssetReference[];
installed_es: EsAssetReference[];
Expand All @@ -568,6 +599,7 @@ export interface Installation {
internal?: boolean;
removable?: boolean;
latest_install_failed_attempts?: InstallFailedAttempt[];
latest_executed_state?: InstallLatestExecutedState;
}

export interface PackageUsageStats {
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/fleet/common/types/rest_spec/epm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import type {
EpmPackageInstallStatus,
SimpleSOAssetType,
AssetSOObject,
InstallResultStatus,
} from '../models/epm';

export interface GetCategoriesRequest {
Expand Down Expand Up @@ -154,7 +155,7 @@ export interface IBulkInstallPackageHTTPError {

export interface InstallResult {
assets?: AssetReference[];
status?: 'installed' | 'already_installed';
status?: InstallResultStatus;
error?: Error;
installType: InstallType;
installSource: InstallSource;
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/fleet/server/routes/epm/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,7 @@ const soToInstallationInfo = (pkg: PackageListItem | PackageInfo) => {
verification_key_id: attributes.verification_key_id,
experimental_data_stream_features: attributes.experimental_data_stream_features,
latest_install_failed_attempts: attributes.latest_install_failed_attempts,
latest_executed_state: attributes.latest_executed_state,
};

return {
Expand Down
11 changes: 11 additions & 0 deletions x-pack/plugins/fleet/server/saved_objects/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,7 @@ export const getSavedObjectTypes = (): { [key: string]: SavedObjectsType } => ({
},
},
latest_install_failed_attempts: { type: 'object', enabled: false },
latest_executed_state: { type: 'object', enabled: false },
installed_kibana: {
dynamic: false,
properties: {},
Expand Down Expand Up @@ -571,6 +572,16 @@ export const getSavedObjectTypes = (): { [key: string]: SavedObjectsType } => ({
},
],
},
'2': {
changes: [
{
type: 'mappings_addition',
addedMappings: {
latest_executed_state: { type: 'object', enabled: false },
},
},
],
},
},
migrations: {
'7.14.0': migrateInstallationToV7140,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ export async function installKibanaAssetsAndReferences({
pkgName,
pkgTitle,
packageInstallContext,
paths,
installedPkg,
spaceId,
assetTags,
Expand All @@ -185,7 +184,6 @@ export async function installKibanaAssetsAndReferences({
pkgName: string;
pkgTitle: string;
packageInstallContext: PackageInstallContext;
paths: string[];
installedPkg?: SavedObject<Installation>;
spaceId: string;
assetTags?: PackageSpecTags[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ export async function _installPackage({
pkgName,
pkgTitle,
packageInstallContext,
paths,
installedPkg,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Linter noticed that this parameter wasn't used anymore, I removed it

logger,
spaceId,
Expand Down
Loading
Loading