Skip to content

Commit

Permalink
[Alerting] Migrate Event Log plugin to TS project references (#81557)
Browse files Browse the repository at this point in the history
* [Alerting] Migrate Event Log plugin to TS project references

* fixed faling typechecks

* fixed path to spaces plugin ts file

* fixed missing include

* added fix for mapping.json

* replaced package.json get version with kibanaVersion from plugin initial context

* fixed build

* fixed typechecks

* fixed tests
  • Loading branch information
YulNaumenko authored Jan 16, 2021
1 parent c66c942 commit 5c112b8
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 13 deletions.
5 changes: 5 additions & 0 deletions x-pack/plugins/event_log/server/es/context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ describe('createEsContext', () => {
logger,
clusterClientPromise: Promise.resolve(clusterClient),
indexNameRoot: 'test0',
kibanaVersion: '1.2.3',
});

expect(context.initialized).toBeFalsy();
Expand All @@ -38,6 +39,7 @@ describe('createEsContext', () => {
logger,
clusterClientPromise: Promise.resolve(clusterClient),
indexNameRoot: 'test-index',
kibanaVersion: '1.2.3',
});

const esNames = context.esNames;
Expand All @@ -57,6 +59,7 @@ describe('createEsContext', () => {
logger,
clusterClientPromise: Promise.resolve(clusterClient),
indexNameRoot: 'test1',
kibanaVersion: '1.2.3',
});
clusterClient.callAsInternalUser.mockResolvedValue(false);

Expand All @@ -74,6 +77,7 @@ describe('createEsContext', () => {
logger,
clusterClientPromise: Promise.resolve(clusterClient),
indexNameRoot: 'test2',
kibanaVersion: '1.2.3',
});
clusterClient.callAsInternalUser.mockResolvedValue(true);
context.initialize();
Expand All @@ -98,6 +102,7 @@ describe('createEsContext', () => {
logger,
clusterClientPromise: Promise.resolve(clusterClient),
indexNameRoot: 'test2',
kibanaVersion: '1.2.3',
});
context.initialize();
const success = await context.waitTillReady();
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/event_log/server/es/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export interface EsContextCtorParams {
logger: Logger;
clusterClientPromise: Promise<EsClusterClient>;
indexNameRoot: string;
kibanaVersion: string;
}

class EsContextImpl implements EsContext {
Expand All @@ -47,7 +48,7 @@ class EsContextImpl implements EsContext {

constructor(params: EsContextCtorParams) {
this.logger = params.logger;
this.esNames = getEsNames(params.indexNameRoot);
this.esNames = getEsNames(params.indexNameRoot, params.kibanaVersion);
this.readySignal = createReadySignal();
this.initialized = false;
this.esAdapter = new ClusterClientAdapter({
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/event_log/server/es/documents.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ describe('getIlmPolicy()', () => {
});

describe('getIndexTemplate()', () => {
const esNames = getEsNames('XYZ');
const kibanaVersion = '1.2.3';
const esNames = getEsNames('XYZ', kibanaVersion);

test('returns the correct details of the index template', () => {
const indexTemplate = getIndexTemplate(esNames);
Expand Down
16 changes: 9 additions & 7 deletions x-pack/plugins/event_log/server/es/names.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,22 @@ jest.mock('../lib/../../../../package.json', () => ({
describe('getEsNames()', () => {
test('works as expected', () => {
const base = 'XYZ';
const version = '1.2.3';
const esNames = getEsNames(base);
const kibanaVersion = '1.2.3';
const esNames = getEsNames(base, kibanaVersion);
expect(esNames.base).toEqual(base);
expect(esNames.alias).toEqual(`${base}-event-log-${version}`);
expect(esNames.alias).toEqual(`${base}-event-log-${kibanaVersion}`);
expect(esNames.ilmPolicy).toEqual(`${base}-event-log-policy`);
expect(esNames.indexPattern).toEqual(`${base}-event-log-*`);
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`);
expect(esNames.indexPatternWithVersion).toEqual(`${base}-event-log-${kibanaVersion}-*`);
expect(esNames.initialIndex).toEqual(`${base}-event-log-${kibanaVersion}-000001`);
expect(esNames.indexTemplate).toEqual(`${base}-event-log-${kibanaVersion}-template`);
});

test('ilm policy name does not contain dot prefix', () => {
const base = '.XYZ';
const esNames = getEsNames(base);
const kibanaVersion = '1.2.3';

const esNames = getEsNames(base, kibanaVersion);
expect(esNames.ilmPolicy).toEqual('XYZ-event-log-policy');
});
});
6 changes: 2 additions & 4 deletions x-pack/plugins/event_log/server/es/names.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import xPackage from '../../../../package.json';

const EVENT_LOG_NAME_SUFFIX = `-event-log`;
const EVENT_LOG_VERSION_SUFFIX = `-${xPackage.version}`;

export interface EsNames {
base: string;
Expand All @@ -19,7 +16,8 @@ export interface EsNames {
indexTemplate: string;
}

export function getEsNames(baseName: string): EsNames {
export function getEsNames(baseName: string, kibanaVersion: string): EsNames {
const EVENT_LOG_VERSION_SUFFIX = `-${kibanaVersion.toLocaleLowerCase()}`;
const eventLogName = `${baseName}${EVENT_LOG_NAME_SUFFIX}`;
const eventLogNameWithVersion = `${eventLogName}${EVENT_LOG_VERSION_SUFFIX}`;
const eventLogPolicyName = `${
Expand Down
3 changes: 3 additions & 0 deletions x-pack/plugins/event_log/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,14 @@ export class Plugin implements CorePlugin<IEventLogService, IEventLogClientServi
private globalConfig$: Observable<SharedGlobalConfig>;
private eventLogClientService?: EventLogClientService;
private savedObjectProviderRegistry: SavedObjectProviderRegistry;
private kibanaVersion: PluginInitializerContext['env']['packageInfo']['version'];

constructor(private readonly context: PluginInitializerContext) {
this.systemLogger = this.context.logger.get();
this.config$ = this.context.config.create<IEventLogConfig>();
this.globalConfig$ = this.context.config.legacy.globalConfig$;
this.savedObjectProviderRegistry = new SavedObjectProviderRegistry();
this.kibanaVersion = this.context.env.packageInfo.version;
}

async setup(core: CoreSetup): Promise<IEventLogService> {
Expand All @@ -78,6 +80,7 @@ export class Plugin implements CorePlugin<IEventLogService, IEventLogClientServi
clusterClientPromise: core
.getStartServices()
.then(([{ elasticsearch }]) => elasticsearch.legacy.client),
kibanaVersion: this.kibanaVersion,
});

this.eventLogService = new EventLogService({
Expand Down
22 changes: 22 additions & 0 deletions x-pack/plugins/event_log/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"extends": "../../../tsconfig.base.json",
"compilerOptions": {
"composite": true,
"outDir": "./target/types",
"emitDeclarationOnly": true,
"declaration": true,
"declarationMap": true
},
"include": [
"server/**/*",
"scripts/**/*",
"generated/*",
// have to declare *.json explicitly due to https://github.com/microsoft/TypeScript/issues/25636
"generated/*.json",
"common/*"
],
"references": [
{ "path": "../../../src/core/tsconfig.json" },
{ "path": "../spaces/tsconfig.json" }
]
}
1 change: 1 addition & 0 deletions x-pack/test/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
{ "path": "../plugins/global_search_providers/tsconfig.json" },
{ "path": "../plugins/features/tsconfig.json" },
{ "path": "../plugins/embeddable_enhanced/tsconfig.json" },
{ "path": "../plugins/event_log/tsconfig.json"},
{ "path": "../plugins/licensing/tsconfig.json" },
{ "path": "../plugins/task_manager/tsconfig.json" },
{ "path": "../plugins/telemetry_collection_xpack/tsconfig.json" },
Expand Down
2 changes: 2 additions & 0 deletions x-pack/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"plugins/graph/**/*",
"plugins/features/**/*",
"plugins/embeddable_enhanced/**/*",
"plugins/event_log/**/*",
"plugins/licensing/**/*",
"plugins/searchprofiler/**/*",
"plugins/security_solution/cypress/**/*",
Expand Down Expand Up @@ -73,6 +74,7 @@
{ "path": "./plugins/features/tsconfig.json" },
{ "path": "./plugins/graph/tsconfig.json" },
{ "path": "./plugins/embeddable_enhanced/tsconfig.json" },
{ "path": "./plugins/event_log/tsconfig.json"},
{ "path": "./plugins/licensing/tsconfig.json" },
{ "path": "./plugins/searchprofiler/tsconfig.json" },
{ "path": "./plugins/task_manager/tsconfig.json" },
Expand Down
1 change: 1 addition & 0 deletions x-pack/tsconfig.refs.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
{ "path": "./plugins/data_enhanced/tsconfig.json" },
{ "path": "./plugins/global_search/tsconfig.json" },
{ "path": "./plugins/global_search_providers/tsconfig.json" },
{ "path": "./plugins/event_log/tsconfig.json"},
{ "path": "./plugins/features/tsconfig.json" },
{ "path": "./plugins/graph/tsconfig.json" },
{ "path": "./plugins/embeddable_enhanced/tsconfig.json" },
Expand Down

0 comments on commit 5c112b8

Please sign in to comment.