mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
* Initial work * Add missing file * Add tests where missing * Add kibana version to esNames * Share ILM policy across versions
This commit is contained in:
parent
61173cd9a8
commit
8d52178cbe
8 changed files with 38 additions and 19 deletions
|
@ -173,6 +173,7 @@ describe('createIndex', () => {
|
|||
await clusterClientAdapter.createIndex('foo');
|
||||
expect(clusterClient.callAsInternalUser).toHaveBeenCalledWith('indices.create', {
|
||||
index: 'foo',
|
||||
body: {},
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -94,9 +94,12 @@ export class ClusterClientAdapter {
|
|||
return result as boolean;
|
||||
}
|
||||
|
||||
public async createIndex(name: string): Promise<void> {
|
||||
public async createIndex(name: string, body: any = {}): Promise<void> {
|
||||
try {
|
||||
await this.callEs('indices.create', { index: name });
|
||||
await this.callEs('indices.create', {
|
||||
index: name,
|
||||
body,
|
||||
});
|
||||
} catch (err) {
|
||||
if (err.body?.error?.type !== 'resource_already_exists_exception') {
|
||||
throw new Error(`error creating initial index: ${err.message}`);
|
||||
|
|
|
@ -22,8 +22,7 @@ describe('getIndexTemplate()', () => {
|
|||
|
||||
test('returns the correct details of the index template', () => {
|
||||
const indexTemplate = getIndexTemplate(esNames);
|
||||
expect(indexTemplate.index_patterns).toEqual([esNames.indexPattern]);
|
||||
expect(indexTemplate.aliases[esNames.alias]).toEqual({});
|
||||
expect(indexTemplate.index_patterns).toEqual([esNames.indexPatternWithVersion]);
|
||||
expect(indexTemplate.settings.number_of_shards).toBeGreaterThanOrEqual(0);
|
||||
expect(indexTemplate.settings.number_of_replicas).toBeGreaterThanOrEqual(0);
|
||||
expect(indexTemplate.settings['index.lifecycle.name']).toBe(esNames.ilmPolicy);
|
||||
|
|
|
@ -10,10 +10,7 @@ import mappings from '../../generated/mappings.json';
|
|||
// returns the body of an index template used in an ES indices.putTemplate call
|
||||
export function getIndexTemplate(esNames: EsNames) {
|
||||
const indexTemplateBody: any = {
|
||||
index_patterns: [esNames.indexPattern],
|
||||
aliases: {
|
||||
[esNames.alias]: {},
|
||||
},
|
||||
index_patterns: [esNames.indexPatternWithVersion],
|
||||
settings: {
|
||||
number_of_shards: 1,
|
||||
number_of_replicas: 1,
|
||||
|
|
|
@ -62,7 +62,13 @@ class EsInitializationSteps {
|
|||
async createInitialIndexIfNotExists(): Promise<void> {
|
||||
const exists = await this.esContext.esAdapter.doesAliasExist(this.esContext.esNames.alias);
|
||||
if (!exists) {
|
||||
await this.esContext.esAdapter.createIndex(this.esContext.esNames.initialIndex);
|
||||
await this.esContext.esAdapter.createIndex(this.esContext.esNames.initialIndex, {
|
||||
aliases: {
|
||||
[this.esContext.esNames.alias]: {
|
||||
is_write_index: true,
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,11 +9,12 @@ import { EsNames } from './names';
|
|||
const createNamesMock = () => {
|
||||
const mock: jest.Mocked<EsNames> = {
|
||||
base: '.kibana',
|
||||
alias: '.kibana-event-log',
|
||||
alias: '.kibana-event-log-8.0.0',
|
||||
ilmPolicy: '.kibana-event-log-policy',
|
||||
indexPattern: '.kibana-event-log-*',
|
||||
initialIndex: '.kibana-event-log-000001',
|
||||
indexTemplate: '.kibana-event-log-template',
|
||||
indexPatternWithVersion: '.kibana-event-log-8.0.0-*',
|
||||
initialIndex: '.kibana-event-log-8.0.0-000001',
|
||||
indexTemplate: '.kibana-event-log-8.0.0-template',
|
||||
};
|
||||
return mock;
|
||||
};
|
||||
|
|
|
@ -6,15 +6,21 @@
|
|||
|
||||
import { getEsNames } from './names';
|
||||
|
||||
jest.mock('../lib/../../../../package.json', () => ({
|
||||
version: '1.2.3',
|
||||
}));
|
||||
|
||||
describe('getEsNames()', () => {
|
||||
test('works as expected', () => {
|
||||
const base = 'XYZ';
|
||||
const version = '1.2.3';
|
||||
const esNames = getEsNames(base);
|
||||
expect(esNames.base).toEqual(base);
|
||||
expect(esNames.alias).toEqual(`${base}-event-log`);
|
||||
expect(esNames.alias).toEqual(`${base}-event-log-${version}`);
|
||||
expect(esNames.ilmPolicy).toEqual(`${base}-event-log-policy`);
|
||||
expect(esNames.indexPattern).toEqual(`${base}-event-log-*`);
|
||||
expect(esNames.initialIndex).toEqual(`${base}-event-log-000001`);
|
||||
expect(esNames.indexTemplate).toEqual(`${base}-event-log-template`);
|
||||
expect(esNames.indexPatternWithVersion).toEqual(`${base}-event-log-${version}-*`);
|
||||
expect(esNames.initialIndex).toEqual(`${base}-event-log-${version}-000001`);
|
||||
expect(esNames.indexTemplate).toEqual(`${base}-event-log-${version}-template`);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -4,25 +4,31 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
const EVENT_LOG_NAME_SUFFIX = '-event-log';
|
||||
import xPackage from '../../../../package.json';
|
||||
|
||||
const EVENT_LOG_NAME_SUFFIX = `-event-log`;
|
||||
const EVENT_LOG_VERSION_SUFFIX = `-${xPackage.version}`;
|
||||
|
||||
export interface EsNames {
|
||||
base: string;
|
||||
alias: string;
|
||||
ilmPolicy: string;
|
||||
indexPattern: string;
|
||||
indexPatternWithVersion: string;
|
||||
initialIndex: string;
|
||||
indexTemplate: string;
|
||||
}
|
||||
|
||||
export function getEsNames(baseName: string): EsNames {
|
||||
const eventLogName = `${baseName}${EVENT_LOG_NAME_SUFFIX}`;
|
||||
const eventLogNameWithVersion = `${eventLogName}${EVENT_LOG_VERSION_SUFFIX}`;
|
||||
return {
|
||||
base: baseName,
|
||||
alias: eventLogName,
|
||||
alias: eventLogNameWithVersion,
|
||||
ilmPolicy: `${eventLogName}-policy`,
|
||||
indexPattern: `${eventLogName}-*`,
|
||||
initialIndex: `${eventLogName}-000001`,
|
||||
indexTemplate: `${eventLogName}-template`,
|
||||
indexPatternWithVersion: `${eventLogNameWithVersion}-*`,
|
||||
initialIndex: `${eventLogNameWithVersion}-000001`,
|
||||
indexTemplate: `${eventLogNameWithVersion}-template`,
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue