Skip to content

Commit 1e4702a

Browse files
kibanamachineqn895elasticmachine
authored
[9.1] [Product docs] Fix bug not upgrading all previously installed product docs (E5) upon Kibana version upgrade (#234792) (#235285)
# Backport This will backport the following commits from `main` to `9.1`: - [[Product docs] Fix bug not upgrading all previously installed product docs (E5) upon Kibana version upgrade (#234792)](#234792) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Quynh Nguyen (Quinn)","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-09-16T23:04:14Z","message":"[Product docs] Fix bug not upgrading all previously installed product docs (E5) upon Kibana version upgrade (#234792)\n\nBug fix PR portion of #231884 for\nbackport purposes. This PR fixes\nhttps://github.com//issues/231450. It adds a check upon\nKibana start to get previously installed product docs and their\nInference IDs, then perform upgrade task for each. This means upon\nKibana start:\n\nIf previous version has ELSER installed → ELSER product docs are updated\nIf previous version has E5 installed → E5 product docs are updated\n\n<img width=\"694\" height=\"174\" alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/cb58a5b9-d339-414e-ab4d-677650e4946e\"\n/>\n\n### Checklist\n\nCheck the PR satisfies following conditions. \n\nReviewers should verify this PR satisfies this list as well.\n\n- [ ] Any text added follows [EUI's writing\nguidelines](https://elastic.github.io/eui/#/guidelines/writing), uses\nsentence case text and includes [i18n\nsupport](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)\n- [ ]\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\nwas added for features that require explanation or tutorials\n- [ ] [Unit or functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere updated or added to match the most common scenarios\n- [ ] If a plugin configuration key changed, check if it needs to be\nallowlisted in the cloud and added to the [docker\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\n- [ ] This was checked for breaking HTTP API changes, and any breaking\nchanges have been approved by the breaking-change committee. The\n`release_note:breaking` label should be applied in these situations.\n- [ ] [Flaky Test\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was\nused on any tests changed\n- [ ] The PR description includes the appropriate Release Notes section,\nand the correct `release_note:*` label is applied per the\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\n- [ ] Review the [backport\nguidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing)\nand apply applicable `backport:*` labels.\n\n### Identify risks\n\nDoes this PR introduce any risks? For example, consider risks like hard\nto test bugs, performance regression, potential of data loss.\n\nDescribe the risk, its severity, and mitigation for each identified\nrisk. Invite stakeholders and evaluate how to proceed before merging.\n\n- [ ] [See some risk\nexamples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx)\n- [ ] ...\n\n---------\n\nCo-authored-by: Elastic Machine <[email protected]>","sha":"4aaeee89f2192126465cccb890205e0c85feb817","branchLabelMapping":{"^v9.2.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","release_note:fix",":ml","backport:version","Team:AI Infra","v9.2.0","v9.1.3","v8.19.3","v9.0.6"],"title":"[Product docs] Fix bug not upgrading all previously installed product docs (E5) upon Kibana version upgrade","number":234792,"url":"https://github.com/elastic/kibana/pull/234792","mergeCommit":{"message":"[Product docs] Fix bug not upgrading all previously installed product docs (E5) upon Kibana version upgrade (#234792)\n\nBug fix PR portion of #231884 for\nbackport purposes. This PR fixes\nhttps://github.com//issues/231450. It adds a check upon\nKibana start to get previously installed product docs and their\nInference IDs, then perform upgrade task for each. This means upon\nKibana start:\n\nIf previous version has ELSER installed → ELSER product docs are updated\nIf previous version has E5 installed → E5 product docs are updated\n\n<img width=\"694\" height=\"174\" alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/cb58a5b9-d339-414e-ab4d-677650e4946e\"\n/>\n\n### Checklist\n\nCheck the PR satisfies following conditions. \n\nReviewers should verify this PR satisfies this list as well.\n\n- [ ] Any text added follows [EUI's writing\nguidelines](https://elastic.github.io/eui/#/guidelines/writing), uses\nsentence case text and includes [i18n\nsupport](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)\n- [ ]\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\nwas added for features that require explanation or tutorials\n- [ ] [Unit or functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere updated or added to match the most common scenarios\n- [ ] If a plugin configuration key changed, check if it needs to be\nallowlisted in the cloud and added to the [docker\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\n- [ ] This was checked for breaking HTTP API changes, and any breaking\nchanges have been approved by the breaking-change committee. The\n`release_note:breaking` label should be applied in these situations.\n- [ ] [Flaky Test\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was\nused on any tests changed\n- [ ] The PR description includes the appropriate Release Notes section,\nand the correct `release_note:*` label is applied per the\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\n- [ ] Review the [backport\nguidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing)\nand apply applicable `backport:*` labels.\n\n### Identify risks\n\nDoes this PR introduce any risks? For example, consider risks like hard\nto test bugs, performance regression, potential of data loss.\n\nDescribe the risk, its severity, and mitigation for each identified\nrisk. Invite stakeholders and evaluate how to proceed before merging.\n\n- [ ] [See some risk\nexamples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx)\n- [ ] ...\n\n---------\n\nCo-authored-by: Elastic Machine <[email protected]>","sha":"4aaeee89f2192126465cccb890205e0c85feb817"}},"sourceBranch":"main","suggestedTargetBranches":["9.1","8.19","9.0"],"targetPullRequestStates":[{"branch":"main","label":"v9.2.0","branchLabelMappingKey":"^v9.2.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/234792","number":234792,"mergeCommit":{"message":"[Product docs] Fix bug not upgrading all previously installed product docs (E5) upon Kibana version upgrade (#234792)\n\nBug fix PR portion of #231884 for\nbackport purposes. This PR fixes\nhttps://github.com//issues/231450. It adds a check upon\nKibana start to get previously installed product docs and their\nInference IDs, then perform upgrade task for each. This means upon\nKibana start:\n\nIf previous version has ELSER installed → ELSER product docs are updated\nIf previous version has E5 installed → E5 product docs are updated\n\n<img width=\"694\" height=\"174\" alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/cb58a5b9-d339-414e-ab4d-677650e4946e\"\n/>\n\n### Checklist\n\nCheck the PR satisfies following conditions. \n\nReviewers should verify this PR satisfies this list as well.\n\n- [ ] Any text added follows [EUI's writing\nguidelines](https://elastic.github.io/eui/#/guidelines/writing), uses\nsentence case text and includes [i18n\nsupport](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)\n- [ ]\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\nwas added for features that require explanation or tutorials\n- [ ] [Unit or functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere updated or added to match the most common scenarios\n- [ ] If a plugin configuration key changed, check if it needs to be\nallowlisted in the cloud and added to the [docker\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\n- [ ] This was checked for breaking HTTP API changes, and any breaking\nchanges have been approved by the breaking-change committee. The\n`release_note:breaking` label should be applied in these situations.\n- [ ] [Flaky Test\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was\nused on any tests changed\n- [ ] The PR description includes the appropriate Release Notes section,\nand the correct `release_note:*` label is applied per the\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\n- [ ] Review the [backport\nguidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing)\nand apply applicable `backport:*` labels.\n\n### Identify risks\n\nDoes this PR introduce any risks? For example, consider risks like hard\nto test bugs, performance regression, potential of data loss.\n\nDescribe the risk, its severity, and mitigation for each identified\nrisk. Invite stakeholders and evaluate how to proceed before merging.\n\n- [ ] [See some risk\nexamples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx)\n- [ ] ...\n\n---------\n\nCo-authored-by: Elastic Machine <[email protected]>","sha":"4aaeee89f2192126465cccb890205e0c85feb817"}},{"branch":"9.1","label":"v9.1.3","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.19","label":"v8.19.3","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"9.0","label":"v9.0.6","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Quynh Nguyen (Quinn) <[email protected]> Co-authored-by: Elastic Machine <[email protected]>
1 parent b56472a commit 1e4702a

File tree

9 files changed

+67
-10
lines changed

9 files changed

+67
-10
lines changed

packages/kbn-optimizer/limits.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ pageLoadAssetSize:
117117
painlessLab: 6299
118118
presentationPanel: 11484
119119
presentationUtil: 9000
120-
productDocBase: 3058
120+
productDocBase: 3074
121121
productIntercept: 9860
122122
profiling: 20716
123123
remoteClusters: 10170

x-pack/platform/plugins/shared/ai_infra/product_doc_base/server/plugin.test.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,16 @@ import { ProductDocBaseSetupDependencies, ProductDocBaseStartDependencies } from
1515
jest.mock('./services/package_installer');
1616
jest.mock('./services/search');
1717
jest.mock('./services/doc_install_status');
18+
jest.mock('./services/doc_manager');
1819
jest.mock('./routes');
1920
jest.mock('./tasks');
2021
import { registerRoutes } from './routes';
2122
import { PackageInstaller } from './services/package_installer';
2223
import { registerTaskDefinitions, scheduleEnsureUpToDateTask } from './tasks';
24+
import { DocumentationManager } from './services/doc_manager';
2325

2426
const PackageInstallMock = PackageInstaller as jest.Mock;
27+
const DocumentationManagerMock = DocumentationManager as jest.Mock;
2528

2629
describe('ProductDocBasePlugin', () => {
2730
let initContext: ReturnType<typeof coreMock.createPluginInitializerContext>;
@@ -41,6 +44,14 @@ describe('ProductDocBasePlugin', () => {
4144
};
4245

4346
PackageInstallMock.mockReturnValue({ ensureUpToDate: jest.fn().mockResolvedValue({}) });
47+
48+
DocumentationManagerMock.mockReturnValue({
49+
install: jest.fn().mockResolvedValue({}),
50+
update: jest.fn().mockResolvedValue({}),
51+
uninstall: jest.fn().mockResolvedValue({}),
52+
getStatus: jest.fn().mockResolvedValue({}),
53+
updateAll: jest.fn().mockResolvedValue({}),
54+
});
4455
});
4556

4657
afterEach(() => {
@@ -81,6 +92,7 @@ describe('ProductDocBasePlugin', () => {
8192
install: expect.any(Function),
8293
uninstall: expect.any(Function),
8394
update: expect.any(Function),
95+
updateAll: expect.any(Function),
8496
},
8597
search: expect.any(Function),
8698
});
@@ -89,8 +101,7 @@ describe('ProductDocBasePlugin', () => {
89101
it('schedules the update task', () => {
90102
plugin.setup(coreMock.createSetup(), pluginSetupDeps);
91103
plugin.start(coreMock.createStart(), pluginStartDeps);
92-
93-
expect(scheduleEnsureUpToDateTask).toHaveBeenCalledTimes(1);
104+
expect(DocumentationManagerMock().updateAll).toHaveBeenCalledTimes(1);
94105
});
95106
});
96107
});

x-pack/platform/plugins/shared/ai_infra/product_doc_base/server/plugin.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import type { Logger } from '@kbn/logging';
1010
import { getDataPath } from '@kbn/utils';
1111
import type { CoreSetup, CoreStart, Plugin, PluginInitializerContext } from '@kbn/core/server';
1212
import { SavedObjectsClient } from '@kbn/core/server';
13-
import { defaultInferenceEndpoints } from '@kbn/inference-common';
1413
import { productDocInstallStatusSavedObjectTypeName } from '../common/consts';
1514
import type { ProductDocBaseConfig } from './config';
1615
import {
@@ -114,14 +113,14 @@ export class ProductDocBasePlugin
114113
taskManager,
115114
};
116115

117-
documentationManager.update({ inferenceId: defaultInferenceEndpoints.ELSER }).catch((err) => {
118-
this.logger.error(`Error scheduling product documentation update task: ${err.message}`);
116+
documentationManager.updateAll().catch((err) => {
117+
this.logger.error(`Error scheduling product documentation updateAll task: ${err.message}`);
119118
});
120-
121119
return {
122120
management: {
123121
install: documentationManager.install.bind(documentationManager),
124122
update: documentationManager.update.bind(documentationManager),
123+
updateAll: documentationManager.updateAll.bind(documentationManager),
125124
uninstall: documentationManager.uninstall.bind(documentationManager),
126125
getStatus: documentationManager.getStatus.bind(documentationManager),
127126
},

x-pack/platform/plugins/shared/ai_infra/product_doc_base/server/services/doc_install_status/product_doc_install_service.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@ export class ProductDocInstallClient {
3030
perPage: 100,
3131
};
3232
const response = await this.soClient.find<TypeAttributes>(query);
33+
const savedObjects = response?.saved_objects.filter(
34+
(so) => so.attributes?.installation_status === 'installed'
35+
);
3336
const inferenceIds = new Set(
34-
response?.saved_objects.map(
35-
(so) => so.attributes?.inference_id ?? defaultInferenceEndpoints.ELSER
36-
)
37+
savedObjects.map((so) => so.attributes?.inference_id ?? defaultInferenceEndpoints.ELSER)
3738
);
3839
return Array.from(inferenceIds);
3940
}

x-pack/platform/plugins/shared/ai_infra/product_doc_base/server/services/doc_manager/doc_manager.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ describe('DocumentationManager', () => {
5454

5555
docInstallClient = {
5656
getInstallationStatus: jest.fn(),
57+
getPreviouslyInstalledInferenceIds: jest
58+
.fn()
59+
.mockResolvedValue([
60+
defaultInferenceEndpoints.MULTILINGUAL_E5_SMALL,
61+
defaultInferenceEndpoints.ELSER,
62+
]),
5763
} as unknown as jest.Mocked<ProductDocInstallClient>;
5864

5965
docManager = new DocumentationManager({

x-pack/platform/plugins/shared/ai_infra/product_doc_base/server/services/doc_manager/doc_manager.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import type {
2828
DocInstallOptions,
2929
DocUninstallOptions,
3030
DocUpdateOptions,
31+
DocUpdateAllOptions,
3132
} from './types';
3233
import { INSTALL_ALL_TASK_ID_MULTILINGUAL } from '../../tasks/install_all';
3334

@@ -139,6 +140,18 @@ export class DocumentationManager implements DocumentationManagerAPI {
139140
});
140141
}
141142
}
143+
async updateAll(options?: DocUpdateAllOptions): Promise<{ inferenceIds: string[] }> {
144+
const { inferenceIds } = options ?? {};
145+
const idsToUpdate: string[] =
146+
inferenceIds ?? (await this.docInstallClient.getPreviouslyInstalledInferenceIds()) ?? [];
147+
this.logger.info(
148+
`Updating product documentation to latest version for Inference IDs: ${idsToUpdate}`
149+
);
150+
await Promise.all(idsToUpdate.map((inferenceId) => this.update({ inferenceId })));
151+
return {
152+
inferenceIds: idsToUpdate,
153+
};
154+
}
142155

143156
async uninstall(options: DocUninstallOptions): Promise<void> {
144157
const { request, wait = false, inferenceId } = options;

x-pack/platform/plugins/shared/ai_infra/product_doc_base/server/services/doc_manager/types.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ export interface DocumentationManagerAPI {
2323
* No-op if the product documentation is not currently installed.
2424
*/
2525
update(options?: DocUpdateOptions): Promise<void>;
26+
/**
27+
* Update the product documentation for all previously installed inference IDs to the latest version.
28+
* No-op if the product documentation is not currently installed.
29+
*/
30+
updateAll(options?: DocUpdateAllOptions): Promise<{ inferenceIds: string[] }>;
2631
/**
2732
* Uninstall the product documentation.
2833
* No-op if the product documentation is not currently installed.
@@ -110,3 +115,23 @@ export interface DocUpdateOptions {
110115
*/
111116
inferenceId: string;
112117
}
118+
119+
/**
120+
* Options for {@link DocumentationManagerAPI.updateAll}
121+
*/
122+
export interface DocUpdateAllOptions {
123+
/**
124+
* When the operation was requested by a user, the request that initiated it.
125+
*
126+
* If not provided, the call will be considered as being done on behalf of system.
127+
*/
128+
request?: KibanaRequest;
129+
/**
130+
* If true, the docs with the same version majorMinor version will be forced to updated regardless
131+
*/
132+
forceUpdate?: boolean;
133+
/**
134+
* inferenceIds to update
135+
*/
136+
inferenceIds?: string[];
137+
}

x-pack/solutions/security/plugins/elastic_assistant/server/ai_assistant_service/helpers.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const mockProductDocManager = {
1414
install: jest.fn(),
1515
uninstall: jest.fn(),
1616
update: jest.fn(),
17+
updateAll: jest.fn(),
1718
};
1819

1920
describe('helpers', () => {

x-pack/solutions/security/plugins/elastic_assistant/server/ai_assistant_service/index.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ describe('AI Assistant Service', () => {
137137
getStatus: jest.fn(),
138138
install: jest.fn(),
139139
update: jest.fn(),
140+
updateAll: jest.fn(),
140141
uninstall: jest.fn(),
141142
}),
142143
};

0 commit comments

Comments
 (0)