Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fleet] Create index templates and ingest pipeline at package policy …
…creation time for input packages (#148772) ## Summary Closes #145529 For integration packages, index templates are created at install time because the package contains all information needed to create the data stream. Input packages need to create the index templates at package policy creation time so that dataset can be populated. Summary of changes: - when creating a package policy for an input package, the correct index templates and ingest pipelines are created, for example for the dataset `dataset1` the following will be created (and added to `installed_es` on the installation saved object): - `logs-dataset1-1.0.0` (ingest_pipeline) - `logs-dataset1` (index_template) - `logs-dataset1@package` (component template) - `logs-dataset1@custom'`(component template) - when a dataset matches an existing data stream - if the existing data stream is from the same package, do not create any new index templates as existing ones will be used - if the existing data stream is from a different package, the API will reject the request unless the force flag is used. - when upgrading an input package, all dynamically created assets will be updated as well. - when uninstalling an input package, all dynamically created assets will be uninstalled - bonus: support the new top level `elasticsearch` field for input package manifests (needed this field for upgrade testing) ### Test setup To test we need a docker registry with input packages, the easiest way is to use the test fixtures from the kibana repo (replace directory with your own) ``` docker run -p 8080:8080 -v /Users/markhopkin/dev/kibana/x-pack/test/fleet_api_integration/apis/fixtures/test_packages:/packages/test-packages -v /Users/markhopkin/dev/kibana/x-pack/test/fleet_api_integration/apis/fixtures/package_registry_config.yml:/package-registry/config.yml docker.elastic.co/package-registry/package-registry:main ``` And add this to your kibana yml config: ``` xpack.fleet.registryUrl: http://localhost:8080 ``` this will make the test package `input_package_upgrade` available which is a version of the custom logs integration: `http://<your_kibana>/app/integrations/detail/input_package_upgrade-1.0.0/overview` ### Test scenarios #### 1. Package policy creation (new datastream) - with input_package_upgrade version 1.0.0 installed and an agent policy with at least one agent - create a package policy with a valid logfile and `dataset1` as the dataset - logs-dataset1 index template should have been created - add an agent to the package policy - append to the log file - data should be added to the logs-dataset1-default datastream ##### 2. Package policy creation (existing datastream same package) - with input_package_upgrade version 1.0.0 installed and an agent policy with at least one agent - create **another** package policy with a valid logfile and `dataset1` as the dataset - logs-dataset1 should still exist - append to the log file - data should be added to the logs-dataset1-default datastream ##### 3. Package policy creation (existing datastream different package) - with input_package_upgrade version 1.0.0 installed and an agent policy with at least one agent - ensure there are some other fleet data streams on the system (i.e data has been ingested), e.g logs-elastic-agent - create a package policy with a valid logfile and `elastic-agent` as the dataset -the package policy should be successfully created - append to the log file - data should be added to the logs-elastic-agent-default datastream ##### 3b. Package policy creation (existing index template different package) - with input_package_upgrade version 1.0.0 installed and an agent policy with at least one agent - ensure there is another fleet index template on the system with no matching data streams (i.e no data has been ingested), e.g logs-system.auth from the system package - create a package policy with a valid logfile and `system.auth` as the dataset -the package policy should be successfully created - append to the log file - data should be added to the logs-system.auth-default datastream - the `logs-system.auth` index template should still have` _meta.package.name` set to 'system' <img width="650" alt="Screenshot 2023-01-17 at 21 31 10" src="https://user-images.githubusercontent.com/3315046/213016570-daab98e4-9cc2-479a-9349-9fd727f9d899.png"> ##### 4. Package policy delete - with input_package_upgrade version 1.0.0 installed and an agent policy with at least one agent - ensure there are some other fleet data streams on the system, e.g logs-elastic-agent - create one or many package policys with a valid logfile and different datasets - note all of the index templates created - uninstall the package - all created index templates should be deleted ##### 5. package policy upgrade - with input_package_upgrade version 1.0.0 installed and an agent policy with at least one agent - create one or many package policys with a valid logfile and different datasets - note all of the index templates created - upgrade to input_package_upgrade version 1.1.0, this adds `mappings.properties.@timestamp` to the `@package` component template for all data streams: ``` mappings: properties: '@timestamp': ignore_malformed: false type: date ``` - verify all new data streams have the new property ### Checklist Delete any items that are not applicable to this PR. - [x] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md) - [ ] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [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] Any UI touched in this PR is usable by keyboard only (learn more about [keyboard accessibility](https://webaim.org/techniques/keyboard/)) - [x] Any UI touched in this PR does not create any new axe failures (run axe in browser: [FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/), [Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))
- Loading branch information