diff --git a/x-pack/plugins/enterprise_search/server/lib/enterprise_search_config_api.test.ts b/x-pack/plugins/enterprise_search/server/lib/enterprise_search_config_api.test.ts index de13077cd1b099..66f2bf78e0c9c3 100644 --- a/x-pack/plugins/enterprise_search/server/lib/enterprise_search_config_api.test.ts +++ b/x-pack/plugins/enterprise_search/server/lib/enterprise_search_config_api.test.ts @@ -12,9 +12,16 @@ import fetch from 'node-fetch'; const { Response } = jest.requireActual('node-fetch'); +jest.mock('@kbn/utils', () => ({ + kibanaPackageJson: { version: '1.0.0' }, +})); + import { loggingSystemMock } from 'src/core/server/mocks'; -import { callEnterpriseSearchConfigAPI } from './enterprise_search_config_api'; +import { + callEnterpriseSearchConfigAPI, + warnMismatchedVersions, +} from './enterprise_search_config_api'; describe('callEnterpriseSearchConfigAPI', () => { const mockConfig = { @@ -218,4 +225,22 @@ describe('callEnterpriseSearchConfigAPI', () => { "Exceeded 200ms timeout while checking http://localhost:3002. Please consider increasing your enterpriseSearch.accessCheckTimeout value so that users aren't prevented from accessing Enterprise Search plugins due to slow responses." ); }); + + describe('warnMismatchedVersions', () => { + it("logs a warning when Enterprise Search and Kibana's versions are not the same", () => { + warnMismatchedVersions('1.1.0', mockDependencies.log); + + expect(mockDependencies.log.warn).toHaveBeenCalledWith( + expect.stringContaining( + 'Your Kibana instance (v1.0.0) is not the same version as your Enterprise Search instance (v1.1.0)' + ) + ); + }); + + it("does not log a warning when Enterprise Search and Kibana's versions are the same", () => { + warnMismatchedVersions('1.0.0', mockDependencies.log); + + expect(mockDependencies.log.warn).not.toHaveBeenCalled(); + }); + }); }); diff --git a/x-pack/plugins/enterprise_search/server/lib/enterprise_search_config_api.ts b/x-pack/plugins/enterprise_search/server/lib/enterprise_search_config_api.ts index ebe718dfebd309..c7aa8e09194d24 100644 --- a/x-pack/plugins/enterprise_search/server/lib/enterprise_search_config_api.ts +++ b/x-pack/plugins/enterprise_search/server/lib/enterprise_search_config_api.ts @@ -8,6 +8,8 @@ import AbortController from 'abort-controller'; import fetch from 'node-fetch'; +import { kibanaPackageJson } from '@kbn/utils'; + import { KibanaRequest, Logger } from 'src/core/server'; import { stripTrailingSlash } from '../../common/strip_slashes'; @@ -58,6 +60,8 @@ export const callEnterpriseSearchConfigAPI = async ({ }); const data = await response.json(); + warnMismatchedVersions(data?.version?.number, log); + return { access: { hasAppSearchAccess: !!data?.current_user?.access?.app_search, @@ -135,3 +139,13 @@ export const callEnterpriseSearchConfigAPI = async ({ clearTimeout(timeout); } }; + +export const warnMismatchedVersions = (enterpriseSearchVersion: string, log: Logger) => { + const kibanaVersion = kibanaPackageJson.version; + + if (enterpriseSearchVersion !== kibanaVersion) { + log.warn( + `Your Kibana instance (v${kibanaVersion}) is not the same version as your Enterprise Search instance (v${enterpriseSearchVersion}). Please upgrade your instances accordingly to matching versions, otherwise you may see breaking or otherwise buggy behavior.` + ); + } +};