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

[Index Patterns] Move rollup config to index pattern management v2 #102285

Merged
9 changes: 9 additions & 0 deletions src/plugins/index_pattern_management/public/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

export const CONFIG_ROLLUPS = 'rollups:enableIndexPatterns';
9 changes: 1 addition & 8 deletions src/plugins/index_pattern_management/public/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,7 @@ import {
} from './plugin';
import { IndexPatternManagmentContext } from './types';

const createSetupContract = (): IndexPatternManagementSetup => ({
creation: {
addCreationConfig: jest.fn(),
} as any,
list: {
addListConfig: jest.fn(),
} as any,
});
const createSetupContract = (): IndexPatternManagementSetup => {};

const createStartContract = (): IndexPatternManagementStart => ({
creation: {
Expand Down
7 changes: 4 additions & 3 deletions src/plugins/index_pattern_management/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,13 @@ export class IndexPatternManagementPlugin
return mountManagementSection(core.getStartServices, params);
},
});

return this.indexPatternManagementService.setup({ httpClient: core.http });
}

public start(core: CoreStart, plugins: IndexPatternManagementStartDependencies) {
return this.indexPatternManagementService.start();
return this.indexPatternManagementService.start({
httpClient: core.http,
uiSettings: core.uiSettings,
});
}

public stop() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

export { RollupPrompt } from './rollup_prompt';
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import React from 'react';
Expand All @@ -14,7 +15,7 @@ export const RollupPrompt = () => (
<EuiCallOut color="warning" iconType="help" title="Beta feature">
<p>
{i18n.translate(
'xpack.rollupJobs.editRollupIndexPattern.rollupPrompt.betaCalloutParagraph1Text',
'indexPatternManagement.editRollupIndexPattern.rollupPrompt.betaCalloutParagraph1Text',
{
defaultMessage:
"Kibana's support for rollup index patterns is in beta. You might encounter issues using " +
Expand All @@ -25,7 +26,7 @@ export const RollupPrompt = () => (
</p>
<p>
{i18n.translate(
'xpack.rollupJobs.editRollupIndexPattern.rollupPrompt.betaCalloutParagraph2Text',
'indexPatternManagement.editRollupIndexPattern.rollupPrompt.betaCalloutParagraph2Text',
{
defaultMessage:
'You can match a rollup index pattern against one rollup index and zero or more regular ' +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@

export { IndexPatternCreationConfig, IndexPatternCreationOption } from './config';
export { IndexPatternCreationManager } from './manager';
// @ts-ignore
export { RollupIndexPatternCreationConfig } from './rollup_creation_config';
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,36 @@
* Side Public License, v 1.
*/

import { HttpSetup } from '../../../../../core/public';
import { memoize } from 'lodash';
import { HttpStart, CoreStart } from '../../../../../core/public';
import { IndexPatternCreationConfig, UrlHandler, IndexPatternCreationOption } from './config';
import { CONFIG_ROLLUPS } from '../../constants';
// @ts-ignore
import { RollupIndexPatternCreationConfig } from './rollup_creation_config';

export class IndexPatternCreationManager {
private configs: IndexPatternCreationConfig[] = [];
interface IndexPatternCreationManagerStart {
httpClient: HttpStart;
uiSettings: CoreStart['uiSettings'];
}

setup(httpClient: HttpSetup) {
return {
addCreationConfig: (Config: typeof IndexPatternCreationConfig) => {
const config = new Config({ httpClient });
export class IndexPatternCreationManager {
start({ httpClient, uiSettings }: IndexPatternCreationManagerStart) {
const getConfigs = memoize(() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you help me understand why this is memoized? The provided function doesn't accept any arguments and we're not passing a second resolver argument to memoize, so I don't see how the memoize function could use any map cache keys to memoize the results of the provided function.

Maybe it makes more sense to use once instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, that makes sense

const configs: IndexPatternCreationConfig[] = [];
configs.push(new IndexPatternCreationConfig({ httpClient }));

if (this.configs.findIndex((c) => c.key === config.key) !== -1) {
throw new Error(`${config.key} exists in IndexPatternCreationManager.`);
}
if (uiSettings.isDeclared(CONFIG_ROLLUPS) && uiSettings.get(CONFIG_ROLLUPS)) {
configs.push(new RollupIndexPatternCreationConfig({ httpClient }));
}

this.configs.push(config);
},
};
}
return configs;
});

start() {
const getType = (key: string | undefined): IndexPatternCreationConfig => {
const configs = getConfigs();
if (key) {
const index = this.configs.findIndex((config) => config.key === key);
const config = this.configs[index];
const index = configs.findIndex((config) => config.key === key);
const config = configs[index];

if (config) {
return config;
Expand All @@ -48,7 +53,7 @@ export class IndexPatternCreationManager {
const options: IndexPatternCreationOption[] = [];

await Promise.all(
this.configs.map(async (config) => {
getConfigs().map(async (config) => {
const option = config.getIndexPatternCreationOption
? await config.getIndexPatternCreationOption(urlHandler)
: null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,43 +1,44 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import React from 'react';
import { i18n } from '@kbn/i18n';

import { RollupPrompt } from './components/rollup_prompt';
import { IndexPatternCreationConfig } from '../../../../../src/plugins/index_pattern_management/public';
import { IndexPatternCreationConfig } from '.';

const rollupIndexPatternTypeName = i18n.translate(
'xpack.rollupJobs.editRollupIndexPattern.createIndex.defaultTypeName',
'indexPatternManagement.editRollupIndexPattern.createIndex.defaultTypeName',
{ defaultMessage: 'rollup index pattern' }
);

const rollupIndexPatternButtonText = i18n.translate(
'xpack.rollupJobs.editRollupIndexPattern.createIndex.defaultButtonText',
'indexPatternManagement.editRollupIndexPattern.createIndex.defaultButtonText',
{ defaultMessage: 'Rollup index pattern' }
);

const rollupIndexPatternButtonDescription = i18n.translate(
'xpack.rollupJobs.editRollupIndexPattern.createIndex.defaultButtonDescription',
'indexPatternManagement.editRollupIndexPattern.createIndex.defaultButtonDescription',
{ defaultMessage: 'Perform limited aggregations against summarized data' }
);

const rollupIndexPatternNoMatchError = i18n.translate(
'xpack.rollupJobs.editRollupIndexPattern.createIndex.noMatchError',
'indexPatternManagement.editRollupIndexPattern.createIndex.noMatchError',
{ defaultMessage: 'Rollup index pattern error: must match one rollup index' }
);

const rollupIndexPatternTooManyMatchesError = i18n.translate(
'xpack.rollupJobs.editRollupIndexPattern.createIndex.tooManyMatchesError',
'indexPatternManagement.editRollupIndexPattern.createIndex.tooManyMatchesError',
{ defaultMessage: 'Rollup index pattern error: can only match one rollup index' }
);

const rollupIndexPatternIndexLabel = i18n.translate(
'xpack.rollupJobs.editRollupIndexPattern.createIndex.indexLabel',
'indexPatternManagement.editRollupIndexPattern.createIndex.indexLabel',
{ defaultMessage: 'Rollup' }
);

Expand Down Expand Up @@ -127,7 +128,7 @@ export class RollupIndexPatternCreationConfig extends IndexPatternCreationConfig

if (error) {
const errorMessage = i18n.translate(
'xpack.rollupJobs.editRollupIndexPattern.createIndex.uncaughtError',
'indexPatternManagement.editRollupIndexPattern.createIndex.uncaughtError',
{
defaultMessage: 'Rollup index pattern error: {error}',
values: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
* Side Public License, v 1.
*/

import { HttpSetup } from '../../../../core/public';
import { IndexPatternCreationManager, IndexPatternCreationConfig } from './creation';
import { IndexPatternListManager, IndexPatternListConfig } from './list';
interface SetupDependencies {
httpClient: HttpSetup;
import { HttpStart, CoreStart } from '../../../../core/public';
import { IndexPatternCreationManager } from './creation';
import { IndexPatternListManager } from './list';

interface StartDependencies {
httpClient: HttpStart;
uiSettings: CoreStart['uiSettings'];
}

/**
Expand All @@ -27,23 +29,12 @@ export class IndexPatternManagementService {
this.indexPatternListConfig = new IndexPatternListManager();
}

public setup({ httpClient }: SetupDependencies) {
const creationManagerSetup = this.indexPatternCreationManager.setup(httpClient);
creationManagerSetup.addCreationConfig(IndexPatternCreationConfig);

const indexPatternListConfigSetup = this.indexPatternListConfig.setup();
indexPatternListConfigSetup.addListConfig(IndexPatternListConfig);

return {
creation: creationManagerSetup,
list: indexPatternListConfigSetup,
};
}
public setup() {}

public start() {
public start({ httpClient, uiSettings }: StartDependencies) {
return {
creation: this.indexPatternCreationManager.start(),
list: this.indexPatternListConfig.start(),
creation: this.indexPatternCreationManager.start({ httpClient, uiSettings }),
list: this.indexPatternListConfig.start({ uiSettings }),
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@

export { IndexPatternListConfig } from './config';
export { IndexPatternListManager } from './manager';
// @ts-ignore
export { RollupIndexPatternListConfig } from './rollup_list_config';
38 changes: 21 additions & 17 deletions src/plugins/index_pattern_management/public/service/list/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,35 @@

import { IIndexPattern, IFieldType } from 'src/plugins/data/public';
import { SimpleSavedObject } from 'src/core/public';
import { memoize } from 'lodash';
import { CoreStart } from '../../../../../core/public';
import { IndexPatternListConfig, IndexPatternTag } from './config';
import { CONFIG_ROLLUPS } from '../../constants';
// @ts-ignore
import { RollupIndexPatternListConfig } from './rollup_list_config';

export class IndexPatternListManager {
private configs: IndexPatternListConfig[] = [];
interface IndexPatternListManagerStart {
uiSettings: CoreStart['uiSettings'];
}

setup() {
return {
addListConfig: (Config: typeof IndexPatternListConfig) => {
const config = new Config();
export class IndexPatternListManager {
start({ uiSettings }: IndexPatternListManagerStart) {
const getConfigs = memoize(() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here.

const configs: IndexPatternListConfig[] = [];
configs.push(new IndexPatternListConfig());

if (this.configs.findIndex((c) => c.key === config.key) !== -1) {
throw new Error(`${config.key} exists in IndexPatternListManager.`);
}
this.configs.push(config);
},
};
}
if (uiSettings.isDeclared(CONFIG_ROLLUPS) && uiSettings.get(CONFIG_ROLLUPS)) {
configs.push(new RollupIndexPatternListConfig());
}

start() {
return configs;
});
return {
getIndexPatternTags: (
indexPattern: IIndexPattern | SimpleSavedObject<IIndexPattern>,
isDefault: boolean
) =>
this.configs.reduce(
getConfigs().reduce(
(tags: IndexPatternTag[], config) =>
config.getIndexPatternTags
? tags.concat(config.getIndexPatternTags(indexPattern, isDefault))
Expand All @@ -41,14 +45,14 @@ export class IndexPatternListManager {
),

getFieldInfo: (indexPattern: IIndexPattern, field: IFieldType): string[] =>
this.configs.reduce(
getConfigs().reduce(
(info: string[], config) =>
config.getFieldInfo ? info.concat(config.getFieldInfo(indexPattern, field)) : info,
[]
),

areScriptedFieldsEnabled: (indexPattern: IIndexPattern): boolean =>
this.configs.every((config) =>
getConfigs().every((config) =>
config.areScriptedFieldsEnabled ? config.areScriptedFieldsEnabled(indexPattern) : true
),
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { IndexPatternListConfig } from '../../../../../src/plugins/index_pattern_management/public';
import { IndexPatternListConfig } from '.';

function isRollup(indexPattern) {
return (
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/rollup/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"server": true,
"ui": true,
"requiredPlugins": [
"indexPatternManagement",
"management",
"licensing",
"features"
Expand Down
Loading