Skip to content

Commit

Permalink
Add server log warnings whenever Kibana and Enterprise Search version…
Browse files Browse the repository at this point in the history
…s are mismatched
  • Loading branch information
cee-chen committed May 27, 2021
1 parent 5dde07f commit e1277da
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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.`
);
}
};

0 comments on commit e1277da

Please sign in to comment.