Use default spaces suffix for signals index if spaces disabled (#57244) (#57521)

Addresses #57221.

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
Ryland Herrick 2020-02-13 17:19:50 -06:00 committed by GitHub
parent 0cc10f2c56
commit bbef07aebd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 1 deletions

View file

@ -11,6 +11,7 @@ import {
transformBulkError,
BulkError,
createSuccessObject,
getIndex,
ImportSuccessError,
createImportErrorObject,
transformImportError,
@ -292,4 +293,36 @@ describe('utils', () => {
expect(transformed).toEqual(expected);
});
});
describe('getIndex', () => {
it('appends the space ID to the configured index if spaces are enabled', () => {
const mockGet = jest.fn();
const mockGetSpaceId = jest.fn();
const config = jest.fn(() => ({ get: mockGet, has: jest.fn() }));
const server = { plugins: { spaces: { getSpaceId: mockGetSpaceId } }, config };
mockGet.mockReturnValue('mockSignalsIndex');
mockGetSpaceId.mockReturnValue('myspace');
// @ts-ignore-next-line TODO these dependencies are simplified on
// https://github.com/elastic/kibana/pull/56814. We're currently mocking
// out what we need.
const index = getIndex(null, server);
expect(index).toEqual('mockSignalsIndex-myspace');
});
it('appends the default space ID to the configured index if spaces are disabled', () => {
const mockGet = jest.fn();
const config = jest.fn(() => ({ get: mockGet, has: jest.fn() }));
const server = { plugins: {}, config };
mockGet.mockReturnValue('mockSignalsIndex');
// @ts-ignore-next-line TODO these dependencies are simplified on
// https://github.com/elastic/kibana/pull/56814. We're currently mocking
// out what we need.
const index = getIndex(null, server);
expect(index).toEqual('mockSignalsIndex-default');
});
});
});

View file

@ -178,7 +178,7 @@ export const getIndex = (
request: RequestFacade | Omit<RequestFacade, 'query'>,
server: ServerFacade
): string => {
const spaceId = server.plugins.spaces.getSpaceId(request);
const spaceId = server.plugins.spaces?.getSpaceId?.(request) ?? 'default';
const signalsIndex = server.config().get(`xpack.${APP_ID}.${SIGNALS_INDEX_KEY}`);
return `${signalsIndex}-${spaceId}`;
};