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

[Enterprise Search] Log warning for Kibana/EntSearch version mismatches #100809

Merged
merged 2 commits into from
May 28, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) => {
Copy link
Member Author

@cee-chen cee-chen May 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was 50/50 about pulling this out to a separate helper const vs. keeping it inline in the main fn, but I figured there was enough complex logic going on in the main fn (timeouts, etc.) that it was a little nicer to pull this out to its own thing 🤔 If you feel strongly otherwise though I can change it, LMK

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.`
cee-chen marked this conversation as resolved.
Show resolved Hide resolved
);
}
};