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] Versions mismatch in Integrations settings page when upgrade is available #152095

Closed
criamico opened this issue Feb 24, 2023 · 1 comment · Fixed by #156257
Closed

[Fleet] Versions mismatch in Integrations settings page when upgrade is available #152095

criamico opened this issue Feb 24, 2023 · 1 comment · Fixed by #156257
Assignees
Labels
bug Fixes for quality problems that affect the customer experience Team:Fleet Team label for Observability Data Collection Fleet team

Comments

@criamico
Copy link
Contributor

criamico commented Feb 24, 2023

Kibana version:

Found on 8.8.0-snapshot (local env)

Describe the bug:
Sometimes when installing an older version of a integration package, there is a versions mismatch in the Settings tab.
For instance I installed nginx-1.5.0 but the settings page displays the installed version as 1.7.0 , which is the latest available at the time of writing:

wrong_version

This causes some weird behaviors; for instance there is no "Upgrade is available" callout. Note that this doesn't happen reliably every time that there is an available upgrade.

Repro steps

  • Install an older version of an integration package. i.e. app/fleet/integrations/nginx-1.5.0/add-integration and navigate to Settings tab
  • The page should show installed version 1.5.0, but sometimes it show the latest instead

Notes

I did a quick research and it seems that installedVersion is defined here and all the operations to retrieve the value of the installed version are done in this file. I also noticed that packageInfo.version in SettingsPage component is correct.

The version and the upgrade are correctly reported in Integration policies tab:

Screenshot 2023-02-24 at 14 53 54

@criamico criamico added the bug Fixes for quality problems that affect the customer experience label Feb 24, 2023
@botelastic botelastic bot added the needs-team Issues missing a team label label Feb 24, 2023
@criamico criamico added the Team:Fleet Team label for Observability Data Collection Fleet team label Feb 24, 2023
@elasticmachine
Copy link
Contributor

Pinging @elastic/fleet (Team:Fleet)

@botelastic botelastic bot removed the needs-team Issues missing a team label label Feb 24, 2023
@criamico criamico changed the title [Fleet] Versions mismatch in settings page when upgrade is available [Fleet] Versions mismatch in Integrations settings page when upgrade is available Feb 24, 2023
@jillguyonnet jillguyonnet self-assigned this Apr 19, 2023
jillguyonnet added a commit that referenced this issue May 2, 2023
## Summary

This PR fixes a bug where an older version of a package cannot be
installed when creating a new agent policy.

Closes #152095

### Reproducing the bug

1. Run Kibana off the `main` branch.
2. Install a package of your choice for the first time (it should not
already be installed) on a version lower than the latest (cf. screenshot
1). In the configuration page under `Where to add this integration?`,
leave `New hosts` selected to ensure a new agent policy is created (cf.
screenshot 2).
3. After the package is installed, go to the package settings: notice
that the installed version is actually the latest (cf. screenshot 3).
4. Note: if you go to the `Integration policies` tab of the package, you
will notice that the integration policy has the version number you
intended to install (cf. screenshot 4).

### Cause of the bug

The `onSubmit` hook used by the package install form [makes use the of
the `epm/packages/_bulk`
endpoint](https://github.com/elastic/kibana/blob/e62581f8bf6098f2813768af2f31647c592645a2/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/single_page_layout/hooks/form.tsx#L272)
to bulk install multiple packages if a new agent policy is to be
created. The `epm/packages/_bulk` endpoint accepts an array of packages
which are either specified by a package name (string) or name and
version (object). In the current implementation, this hook only provides
the package names, which resolves to the latest version of the package
being installed.

### How this PR fixes the bug

This PR make the following changes:
* Make the `BulkInstallPackagesFromRegistryRequestSchema` validation
accepts an array of either strings or objects of shape `{ name: string,
version: string }` for packages.
* Modify the `sendBulkInstallPackages` request hook to do the same.
* Make the `onSubmit` hook used by the package install form pass the
package name and version to the `epm/packages/_bulk` endpoint.

### Additional changes

* Add API integration test for bulk package install
* Amend OpenAPI definition: [Swagger
link](https://petstore.swagger.io/?url=https://raw.githubusercontent.com/elastic/kibana/a4a3209905a5cf099fa22779e889a57acb124fb2/x-pack/plugins/fleet/common/openapi/bundled.json#/Elastic%20Package%20Manager%20(EPM)/bulk-install-packages)
(cf. screenshot 7)

### Testing steps

1. (Optional) Test that the `epm/packages/_bulk` endpoint accepts
package name as strings or package name and version as objects, or even
a mix of both (cf. screenshot 6).
2. Same steps as `Reproducing the bug` above on this branch. The correct
version of the package should be installed (cf screenshot 5).

### Screenshots

Screenshot 1: preparing to install an older version of a package:
<img width="1917" alt="Screenshot 2023-05-02 at 11 21 12"
src="https://user-images.githubusercontent.com/23701614/235631501-aa03d2b0-6fe8-4e9a-8e0c-5547f8fccea0.png">


Screenshot 2: creating a new agent policy when installing the package:
<img width="1917" alt="Screenshot 2023-05-02 at 11 21 33"
src="https://user-images.githubusercontent.com/23701614/235631650-3d9bfc19-ace3-4488-a7c7-48078aae3e7c.png">

Screenshot 3: integration settings after installing an older version
onto a new agent policy, showing that the installed version is actually
the latest version:
<img width="1917" alt="Screenshot 2023-05-02 at 11 29 07"
src="https://user-images.githubusercontent.com/23701614/235631920-3ca8f606-d225-464e-8094-46aeee4869df.png">


Screenshot 4: `Integration policies` tab, showing that the integration
policy has the older version:
<img width="1917" alt="Screenshot 2023-05-02 at 11 28 43"
src="https://user-images.githubusercontent.com/23701614/235632212-c82a3ddd-cb33-4179-a4ab-b57e33e7490d.png">


Screenshot 5: integration settings after installing an older version
onto a new agent policy **with the bug fix**, showing that the correct
version was installed:
<img width="1917" alt="Screenshot 2023-05-02 at 11 23 09"
src="https://user-images.githubusercontent.com/23701614/235632590-bb26183d-ce60-439c-9bee-eadb9fdb9654.png">


Screenshot 6: API call showing the two ways of specifying a package
using the `epm/packages/_bulk` endpoint (package name only, or name and
version):
<img width="1917" alt="Screenshot 2023-05-02 at 11 59 11"
src="https://user-images.githubusercontent.com/23701614/235637532-ae32072b-ca84-48bb-9760-120a2149f0e5.png">


Screenshot 7: `epm/packages/_bulk` endpoint reference on Swagger:
<img width="1429" alt="Screenshot 2023-05-02 at 15 13 14"
src="https://user-images.githubusercontent.com/23701614/235677504-e8ba1329-1a70-44f8-92c5-0f32e5da7e46.png">

### 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

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
kibanamachine pushed a commit to kibanamachine/kibana that referenced this issue May 2, 2023
## Summary

This PR fixes a bug where an older version of a package cannot be
installed when creating a new agent policy.

Closes elastic#152095

### Reproducing the bug

1. Run Kibana off the `main` branch.
2. Install a package of your choice for the first time (it should not
already be installed) on a version lower than the latest (cf. screenshot
1). In the configuration page under `Where to add this integration?`,
leave `New hosts` selected to ensure a new agent policy is created (cf.
screenshot 2).
3. After the package is installed, go to the package settings: notice
that the installed version is actually the latest (cf. screenshot 3).
4. Note: if you go to the `Integration policies` tab of the package, you
will notice that the integration policy has the version number you
intended to install (cf. screenshot 4).

### Cause of the bug

The `onSubmit` hook used by the package install form [makes use the of
the `epm/packages/_bulk`
endpoint](https://github.com/elastic/kibana/blob/e62581f8bf6098f2813768af2f31647c592645a2/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/single_page_layout/hooks/form.tsx#L272)
to bulk install multiple packages if a new agent policy is to be
created. The `epm/packages/_bulk` endpoint accepts an array of packages
which are either specified by a package name (string) or name and
version (object). In the current implementation, this hook only provides
the package names, which resolves to the latest version of the package
being installed.

### How this PR fixes the bug

This PR make the following changes:
* Make the `BulkInstallPackagesFromRegistryRequestSchema` validation
accepts an array of either strings or objects of shape `{ name: string,
version: string }` for packages.
* Modify the `sendBulkInstallPackages` request hook to do the same.
* Make the `onSubmit` hook used by the package install form pass the
package name and version to the `epm/packages/_bulk` endpoint.

### Additional changes

* Add API integration test for bulk package install
* Amend OpenAPI definition: [Swagger
link](https://petstore.swagger.io/?url=https://raw.githubusercontent.com/elastic/kibana/a4a3209905a5cf099fa22779e889a57acb124fb2/x-pack/plugins/fleet/common/openapi/bundled.json#/Elastic%20Package%20Manager%20(EPM)/bulk-install-packages)
(cf. screenshot 7)

### Testing steps

1. (Optional) Test that the `epm/packages/_bulk` endpoint accepts
package name as strings or package name and version as objects, or even
a mix of both (cf. screenshot 6).
2. Same steps as `Reproducing the bug` above on this branch. The correct
version of the package should be installed (cf screenshot 5).

### Screenshots

Screenshot 1: preparing to install an older version of a package:
<img width="1917" alt="Screenshot 2023-05-02 at 11 21 12"
src="https://user-images.githubusercontent.com/23701614/235631501-aa03d2b0-6fe8-4e9a-8e0c-5547f8fccea0.png">

Screenshot 2: creating a new agent policy when installing the package:
<img width="1917" alt="Screenshot 2023-05-02 at 11 21 33"
src="https://user-images.githubusercontent.com/23701614/235631650-3d9bfc19-ace3-4488-a7c7-48078aae3e7c.png">

Screenshot 3: integration settings after installing an older version
onto a new agent policy, showing that the installed version is actually
the latest version:
<img width="1917" alt="Screenshot 2023-05-02 at 11 29 07"
src="https://user-images.githubusercontent.com/23701614/235631920-3ca8f606-d225-464e-8094-46aeee4869df.png">

Screenshot 4: `Integration policies` tab, showing that the integration
policy has the older version:
<img width="1917" alt="Screenshot 2023-05-02 at 11 28 43"
src="https://user-images.githubusercontent.com/23701614/235632212-c82a3ddd-cb33-4179-a4ab-b57e33e7490d.png">

Screenshot 5: integration settings after installing an older version
onto a new agent policy **with the bug fix**, showing that the correct
version was installed:
<img width="1917" alt="Screenshot 2023-05-02 at 11 23 09"
src="https://user-images.githubusercontent.com/23701614/235632590-bb26183d-ce60-439c-9bee-eadb9fdb9654.png">

Screenshot 6: API call showing the two ways of specifying a package
using the `epm/packages/_bulk` endpoint (package name only, or name and
version):
<img width="1917" alt="Screenshot 2023-05-02 at 11 59 11"
src="https://user-images.githubusercontent.com/23701614/235637532-ae32072b-ca84-48bb-9760-120a2149f0e5.png">

Screenshot 7: `epm/packages/_bulk` endpoint reference on Swagger:
<img width="1429" alt="Screenshot 2023-05-02 at 15 13 14"
src="https://user-images.githubusercontent.com/23701614/235677504-e8ba1329-1a70-44f8-92c5-0f32e5da7e46.png">

### 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

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
(cherry picked from commit d71f6f3)
kibanamachine referenced this issue May 2, 2023
# Backport

This will backport the following commits from `main` to `8.8`:
- [[Fleet] Fix package install with older version
(#156257)](#156257)

<!--- Backport version: 8.9.7 -->

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

<!--BACKPORT [{"author":{"name":"Jill
Guyonnet","email":"jill.guyonnet@elastic.co"},"sourceCommit":{"committedDate":"2023-05-02T15:02:51Z","message":"[Fleet]
Fix package install with older version (#156257)\n\n##
Summary\r\n\r\nThis PR fixes a bug where an older version of a package
cannot be\r\ninstalled when creating a new agent policy.\r\n\r\nCloses
https://github.com/elastic/kibana/issues/152095\r\n\r\n### Reproducing
the bug\r\n\r\n1. Run Kibana off the `main` branch.\r\n2. Install a
package of your choice for the first time (it should not\r\nalready be
installed) on a version lower than the latest (cf. screenshot\r\n1). In
the configuration page under `Where to add this integration?`,\r\nleave
`New hosts` selected to ensure a new agent policy is created
(cf.\r\nscreenshot 2).\r\n3. After the package is installed, go to the
package settings: notice\r\nthat the installed version is actually the
latest (cf. screenshot 3).\r\n4. Note: if you go to the `Integration
policies` tab of the package, you\r\nwill notice that the integration
policy has the version number you\r\nintended to install (cf. screenshot
4).\r\n\r\n### Cause of the bug\r\n\r\nThe `onSubmit` hook used by the
package install form [makes use the of\r\nthe
`epm/packages/_bulk`\r\nendpoint](https://github.com/elastic/kibana/blob/e62581f8bf6098f2813768af2f31647c592645a2/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/single_page_layout/hooks/form.tsx#L272)\r\nto
bulk install multiple packages if a new agent policy is to
be\r\ncreated. The `epm/packages/_bulk` endpoint accepts an array of
packages\r\nwhich are either specified by a package name (string) or
name and\r\nversion (object). In the current implementation, this hook
only provides\r\nthe package names, which resolves to the latest version
of the package\r\nbeing installed.\r\n\r\n### How this PR fixes the
bug\r\n\r\nThis PR make the following changes:\r\n* Make the
`BulkInstallPackagesFromRegistryRequestSchema` validation\r\naccepts an
array of either strings or objects of shape `{ name: string,\r\nversion:
string }` for packages.\r\n* Modify the `sendBulkInstallPackages`
request hook to do the same.\r\n* Make the `onSubmit` hook used by the
package install form pass the\r\npackage name and version to the
`epm/packages/_bulk` endpoint.\r\n\r\n### Additional changes\r\n\r\n*
Add API integration test for bulk package install\r\n* Amend OpenAPI
definition:
[Swagger\r\nlink](https://petstore.swagger.io/?url=https://raw.githubusercontent.com/elastic/kibana/a4a3209905a5cf099fa22779e889a57acb124fb2/x-pack/plugins/fleet/common/openapi/bundled.json#/Elastic%20Package%20Manager%20(EPM)/bulk-install-packages)\r\n(cf.
screenshot 7)\r\n\r\n### Testing steps\r\n\r\n1. (Optional) Test that
the `epm/packages/_bulk` endpoint accepts\r\npackage name as strings or
package name and version as objects, or even\r\na mix of both (cf.
screenshot 6).\r\n2. Same steps as `Reproducing the bug` above on this
branch. The correct\r\nversion of the package should be installed (cf
screenshot 5).\r\n\r\n### Screenshots\r\n\r\nScreenshot 1: preparing to
install an older version of a package:\r\n<img width=\"1917\"
alt=\"Screenshot 2023-05-02 at 11 21
12\"\r\nsrc=\"https://user-images.githubusercontent.com/23701614/235631501-aa03d2b0-6fe8-4e9a-8e0c-5547f8fccea0.png\">\r\n\r\n\r\nScreenshot
2: creating a new agent policy when installing the package:\r\n<img
width=\"1917\" alt=\"Screenshot 2023-05-02 at 11 21
33\"\r\nsrc=\"https://user-images.githubusercontent.com/23701614/235631650-3d9bfc19-ace3-4488-a7c7-48078aae3e7c.png\">\r\n\r\nScreenshot
3: integration settings after installing an older version\r\nonto a new
agent policy, showing that the installed version is actually\r\nthe
latest version:\r\n<img width=\"1917\" alt=\"Screenshot 2023-05-02 at 11
29
07\"\r\nsrc=\"https://user-images.githubusercontent.com/23701614/235631920-3ca8f606-d225-464e-8094-46aeee4869df.png\">\r\n\r\n\r\nScreenshot
4: `Integration policies` tab, showing that the integration\r\npolicy
has the older version:\r\n<img width=\"1917\" alt=\"Screenshot
2023-05-02 at 11 28
43\"\r\nsrc=\"https://user-images.githubusercontent.com/23701614/235632212-c82a3ddd-cb33-4179-a4ab-b57e33e7490d.png\">\r\n\r\n\r\nScreenshot
5: integration settings after installing an older version\r\nonto a new
agent policy **with the bug fix**, showing that the correct\r\nversion
was installed:\r\n<img width=\"1917\" alt=\"Screenshot 2023-05-02 at 11
23
09\"\r\nsrc=\"https://user-images.githubusercontent.com/23701614/235632590-bb26183d-ce60-439c-9bee-eadb9fdb9654.png\">\r\n\r\n\r\nScreenshot
6: API call showing the two ways of specifying a package\r\nusing the
`epm/packages/_bulk` endpoint (package name only, or name
and\r\nversion):\r\n<img width=\"1917\" alt=\"Screenshot 2023-05-02 at
11 59
11\"\r\nsrc=\"https://user-images.githubusercontent.com/23701614/235637532-ae32072b-ca84-48bb-9760-120a2149f0e5.png\">\r\n\r\n\r\nScreenshot
7: `epm/packages/_bulk` endpoint reference on Swagger:\r\n<img
width=\"1429\" alt=\"Screenshot 2023-05-02 at 15 13
14\"\r\nsrc=\"https://user-images.githubusercontent.com/23701614/235677504-e8ba1329-1a70-44f8-92c5-0f32e5da7e46.png\">\r\n\r\n###
Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"d71f6f3d0337a66aab755ab576fa6f4f85652a5c","branchLabelMapping":{"^v8.9.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:Fleet","backport:prev-minor","v8.9.0"],"number":156257,"url":"https://github.com/elastic/kibana/pull/156257","mergeCommit":{"message":"[Fleet]
Fix package install with older version (#156257)\n\n##
Summary\r\n\r\nThis PR fixes a bug where an older version of a package
cannot be\r\ninstalled when creating a new agent policy.\r\n\r\nCloses
https://github.com/elastic/kibana/issues/152095\r\n\r\n### Reproducing
the bug\r\n\r\n1. Run Kibana off the `main` branch.\r\n2. Install a
package of your choice for the first time (it should not\r\nalready be
installed) on a version lower than the latest (cf. screenshot\r\n1). In
the configuration page under `Where to add this integration?`,\r\nleave
`New hosts` selected to ensure a new agent policy is created
(cf.\r\nscreenshot 2).\r\n3. After the package is installed, go to the
package settings: notice\r\nthat the installed version is actually the
latest (cf. screenshot 3).\r\n4. Note: if you go to the `Integration
policies` tab of the package, you\r\nwill notice that the integration
policy has the version number you\r\nintended to install (cf. screenshot
4).\r\n\r\n### Cause of the bug\r\n\r\nThe `onSubmit` hook used by the
package install form [makes use the of\r\nthe
`epm/packages/_bulk`\r\nendpoint](https://github.com/elastic/kibana/blob/e62581f8bf6098f2813768af2f31647c592645a2/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/single_page_layout/hooks/form.tsx#L272)\r\nto
bulk install multiple packages if a new agent policy is to
be\r\ncreated. The `epm/packages/_bulk` endpoint accepts an array of
packages\r\nwhich are either specified by a package name (string) or
name and\r\nversion (object). In the current implementation, this hook
only provides\r\nthe package names, which resolves to the latest version
of the package\r\nbeing installed.\r\n\r\n### How this PR fixes the
bug\r\n\r\nThis PR make the following changes:\r\n* Make the
`BulkInstallPackagesFromRegistryRequestSchema` validation\r\naccepts an
array of either strings or objects of shape `{ name: string,\r\nversion:
string }` for packages.\r\n* Modify the `sendBulkInstallPackages`
request hook to do the same.\r\n* Make the `onSubmit` hook used by the
package install form pass the\r\npackage name and version to the
`epm/packages/_bulk` endpoint.\r\n\r\n### Additional changes\r\n\r\n*
Add API integration test for bulk package install\r\n* Amend OpenAPI
definition:
[Swagger\r\nlink](https://petstore.swagger.io/?url=https://raw.githubusercontent.com/elastic/kibana/a4a3209905a5cf099fa22779e889a57acb124fb2/x-pack/plugins/fleet/common/openapi/bundled.json#/Elastic%20Package%20Manager%20(EPM)/bulk-install-packages)\r\n(cf.
screenshot 7)\r\n\r\n### Testing steps\r\n\r\n1. (Optional) Test that
the `epm/packages/_bulk` endpoint accepts\r\npackage name as strings or
package name and version as objects, or even\r\na mix of both (cf.
screenshot 6).\r\n2. Same steps as `Reproducing the bug` above on this
branch. The correct\r\nversion of the package should be installed (cf
screenshot 5).\r\n\r\n### Screenshots\r\n\r\nScreenshot 1: preparing to
install an older version of a package:\r\n<img width=\"1917\"
alt=\"Screenshot 2023-05-02 at 11 21
12\"\r\nsrc=\"https://user-images.githubusercontent.com/23701614/235631501-aa03d2b0-6fe8-4e9a-8e0c-5547f8fccea0.png\">\r\n\r\n\r\nScreenshot
2: creating a new agent policy when installing the package:\r\n<img
width=\"1917\" alt=\"Screenshot 2023-05-02 at 11 21
33\"\r\nsrc=\"https://user-images.githubusercontent.com/23701614/235631650-3d9bfc19-ace3-4488-a7c7-48078aae3e7c.png\">\r\n\r\nScreenshot
3: integration settings after installing an older version\r\nonto a new
agent policy, showing that the installed version is actually\r\nthe
latest version:\r\n<img width=\"1917\" alt=\"Screenshot 2023-05-02 at 11
29
07\"\r\nsrc=\"https://user-images.githubusercontent.com/23701614/235631920-3ca8f606-d225-464e-8094-46aeee4869df.png\">\r\n\r\n\r\nScreenshot
4: `Integration policies` tab, showing that the integration\r\npolicy
has the older version:\r\n<img width=\"1917\" alt=\"Screenshot
2023-05-02 at 11 28
43\"\r\nsrc=\"https://user-images.githubusercontent.com/23701614/235632212-c82a3ddd-cb33-4179-a4ab-b57e33e7490d.png\">\r\n\r\n\r\nScreenshot
5: integration settings after installing an older version\r\nonto a new
agent policy **with the bug fix**, showing that the correct\r\nversion
was installed:\r\n<img width=\"1917\" alt=\"Screenshot 2023-05-02 at 11
23
09\"\r\nsrc=\"https://user-images.githubusercontent.com/23701614/235632590-bb26183d-ce60-439c-9bee-eadb9fdb9654.png\">\r\n\r\n\r\nScreenshot
6: API call showing the two ways of specifying a package\r\nusing the
`epm/packages/_bulk` endpoint (package name only, or name
and\r\nversion):\r\n<img width=\"1917\" alt=\"Screenshot 2023-05-02 at
11 59
11\"\r\nsrc=\"https://user-images.githubusercontent.com/23701614/235637532-ae32072b-ca84-48bb-9760-120a2149f0e5.png\">\r\n\r\n\r\nScreenshot
7: `epm/packages/_bulk` endpoint reference on Swagger:\r\n<img
width=\"1429\" alt=\"Screenshot 2023-05-02 at 15 13
14\"\r\nsrc=\"https://user-images.githubusercontent.com/23701614/235677504-e8ba1329-1a70-44f8-92c5-0f32e5da7e46.png\">\r\n\r\n###
Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"d71f6f3d0337a66aab755ab576fa6f4f85652a5c"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v8.9.0","labelRegex":"^v8.9.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/156257","number":156257,"mergeCommit":{"message":"[Fleet]
Fix package install with older version (#156257)\n\n##
Summary\r\n\r\nThis PR fixes a bug where an older version of a package
cannot be\r\ninstalled when creating a new agent policy.\r\n\r\nCloses
https://github.com/elastic/kibana/issues/152095\r\n\r\n### Reproducing
the bug\r\n\r\n1. Run Kibana off the `main` branch.\r\n2. Install a
package of your choice for the first time (it should not\r\nalready be
installed) on a version lower than the latest (cf. screenshot\r\n1). In
the configuration page under `Where to add this integration?`,\r\nleave
`New hosts` selected to ensure a new agent policy is created
(cf.\r\nscreenshot 2).\r\n3. After the package is installed, go to the
package settings: notice\r\nthat the installed version is actually the
latest (cf. screenshot 3).\r\n4. Note: if you go to the `Integration
policies` tab of the package, you\r\nwill notice that the integration
policy has the version number you\r\nintended to install (cf. screenshot
4).\r\n\r\n### Cause of the bug\r\n\r\nThe `onSubmit` hook used by the
package install form [makes use the of\r\nthe
`epm/packages/_bulk`\r\nendpoint](https://github.com/elastic/kibana/blob/e62581f8bf6098f2813768af2f31647c592645a2/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/single_page_layout/hooks/form.tsx#L272)\r\nto
bulk install multiple packages if a new agent policy is to
be\r\ncreated. The `epm/packages/_bulk` endpoint accepts an array of
packages\r\nwhich are either specified by a package name (string) or
name and\r\nversion (object). In the current implementation, this hook
only provides\r\nthe package names, which resolves to the latest version
of the package\r\nbeing installed.\r\n\r\n### How this PR fixes the
bug\r\n\r\nThis PR make the following changes:\r\n* Make the
`BulkInstallPackagesFromRegistryRequestSchema` validation\r\naccepts an
array of either strings or objects of shape `{ name: string,\r\nversion:
string }` for packages.\r\n* Modify the `sendBulkInstallPackages`
request hook to do the same.\r\n* Make the `onSubmit` hook used by the
package install form pass the\r\npackage name and version to the
`epm/packages/_bulk` endpoint.\r\n\r\n### Additional changes\r\n\r\n*
Add API integration test for bulk package install\r\n* Amend OpenAPI
definition:
[Swagger\r\nlink](https://petstore.swagger.io/?url=https://raw.githubusercontent.com/elastic/kibana/a4a3209905a5cf099fa22779e889a57acb124fb2/x-pack/plugins/fleet/common/openapi/bundled.json#/Elastic%20Package%20Manager%20(EPM)/bulk-install-packages)\r\n(cf.
screenshot 7)\r\n\r\n### Testing steps\r\n\r\n1. (Optional) Test that
the `epm/packages/_bulk` endpoint accepts\r\npackage name as strings or
package name and version as objects, or even\r\na mix of both (cf.
screenshot 6).\r\n2. Same steps as `Reproducing the bug` above on this
branch. The correct\r\nversion of the package should be installed (cf
screenshot 5).\r\n\r\n### Screenshots\r\n\r\nScreenshot 1: preparing to
install an older version of a package:\r\n<img width=\"1917\"
alt=\"Screenshot 2023-05-02 at 11 21
12\"\r\nsrc=\"https://user-images.githubusercontent.com/23701614/235631501-aa03d2b0-6fe8-4e9a-8e0c-5547f8fccea0.png\">\r\n\r\n\r\nScreenshot
2: creating a new agent policy when installing the package:\r\n<img
width=\"1917\" alt=\"Screenshot 2023-05-02 at 11 21
33\"\r\nsrc=\"https://user-images.githubusercontent.com/23701614/235631650-3d9bfc19-ace3-4488-a7c7-48078aae3e7c.png\">\r\n\r\nScreenshot
3: integration settings after installing an older version\r\nonto a new
agent policy, showing that the installed version is actually\r\nthe
latest version:\r\n<img width=\"1917\" alt=\"Screenshot 2023-05-02 at 11
29
07\"\r\nsrc=\"https://user-images.githubusercontent.com/23701614/235631920-3ca8f606-d225-464e-8094-46aeee4869df.png\">\r\n\r\n\r\nScreenshot
4: `Integration policies` tab, showing that the integration\r\npolicy
has the older version:\r\n<img width=\"1917\" alt=\"Screenshot
2023-05-02 at 11 28
43\"\r\nsrc=\"https://user-images.githubusercontent.com/23701614/235632212-c82a3ddd-cb33-4179-a4ab-b57e33e7490d.png\">\r\n\r\n\r\nScreenshot
5: integration settings after installing an older version\r\nonto a new
agent policy **with the bug fix**, showing that the correct\r\nversion
was installed:\r\n<img width=\"1917\" alt=\"Screenshot 2023-05-02 at 11
23
09\"\r\nsrc=\"https://user-images.githubusercontent.com/23701614/235632590-bb26183d-ce60-439c-9bee-eadb9fdb9654.png\">\r\n\r\n\r\nScreenshot
6: API call showing the two ways of specifying a package\r\nusing the
`epm/packages/_bulk` endpoint (package name only, or name
and\r\nversion):\r\n<img width=\"1917\" alt=\"Screenshot 2023-05-02 at
11 59
11\"\r\nsrc=\"https://user-images.githubusercontent.com/23701614/235637532-ae32072b-ca84-48bb-9760-120a2149f0e5.png\">\r\n\r\n\r\nScreenshot
7: `epm/packages/_bulk` endpoint reference on Swagger:\r\n<img
width=\"1429\" alt=\"Screenshot 2023-05-02 at 15 13
14\"\r\nsrc=\"https://user-images.githubusercontent.com/23701614/235677504-e8ba1329-1a70-44f8-92c5-0f32e5da7e46.png\">\r\n\r\n###
Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"d71f6f3d0337a66aab755ab576fa6f4f85652a5c"}}]}]
BACKPORT-->

Co-authored-by: Jill Guyonnet <jill.guyonnet@elastic.co>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Fixes for quality problems that affect the customer experience Team:Fleet Team label for Observability Data Collection Fleet team
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants