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

[ML] Reduce ml async bundle loading on Kibana page load #193761

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -609,13 +609,15 @@ x-pack/packages/ml/data_grid @elastic/ml-ui
x-pack/packages/ml/data_view_utils @elastic/ml-ui
x-pack/packages/ml/date_picker @elastic/ml-ui
x-pack/packages/ml/date_utils @elastic/ml-ui
x-pack/packages/ml/embeddables @elastic/ml-ui
x-pack/packages/ml/error_utils @elastic/ml-ui
x-pack/packages/ml/field_stats_flyout @elastic/ml-ui
x-pack/packages/ml/in_memory_table @elastic/ml-ui
x-pack/packages/ml/is_defined @elastic/ml-ui
x-pack/packages/ml/is_populated_object @elastic/ml-ui
x-pack/packages/ml/kibana_theme @elastic/ml-ui
x-pack/packages/ml/local_storage @elastic/ml-ui
x-pack/packages/ml/locator @elastic/ml-ui
x-pack/packages/ml/nested_property @elastic/ml-ui
x-pack/packages/ml/number_utils @elastic/ml-ui
x-pack/packages/ml/parse_interval @elastic/ml-ui
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -644,13 +644,15 @@
"@kbn/ml-data-view-utils": "link:x-pack/packages/ml/data_view_utils",
"@kbn/ml-date-picker": "link:x-pack/packages/ml/date_picker",
"@kbn/ml-date-utils": "link:x-pack/packages/ml/date_utils",
"@kbn/ml-embeddables": "link:x-pack/packages/ml/embeddables",
"@kbn/ml-error-utils": "link:x-pack/packages/ml/error_utils",
"@kbn/ml-field-stats-flyout": "link:x-pack/packages/ml/field_stats_flyout",
"@kbn/ml-in-memory-table": "link:x-pack/packages/ml/in_memory_table",
"@kbn/ml-is-defined": "link:x-pack/packages/ml/is_defined",
"@kbn/ml-is-populated-object": "link:x-pack/packages/ml/is_populated_object",
"@kbn/ml-kibana-theme": "link:x-pack/packages/ml/kibana_theme",
"@kbn/ml-local-storage": "link:x-pack/packages/ml/local_storage",
"@kbn/ml-locator": "link:x-pack/packages/ml/locator",
"@kbn/ml-nested-property": "link:x-pack/packages/ml/nested_property",
"@kbn/ml-number-utils": "link:x-pack/packages/ml/number_utils",
"@kbn/ml-parse-interval": "link:x-pack/packages/ml/parse_interval",
Expand Down
4 changes: 4 additions & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -1212,6 +1212,8 @@
"@kbn/ml-date-picker/*": ["x-pack/packages/ml/date_picker/*"],
"@kbn/ml-date-utils": ["x-pack/packages/ml/date_utils"],
"@kbn/ml-date-utils/*": ["x-pack/packages/ml/date_utils/*"],
"@kbn/ml-embeddables": ["x-pack/packages/ml/embeddables"],
"@kbn/ml-embeddables/*": ["x-pack/packages/ml/embeddables/*"],
"@kbn/ml-error-utils": ["x-pack/packages/ml/error_utils"],
"@kbn/ml-error-utils/*": ["x-pack/packages/ml/error_utils/*"],
"@kbn/ml-field-stats-flyout": ["x-pack/packages/ml/field_stats_flyout"],
Expand All @@ -1226,6 +1228,8 @@
"@kbn/ml-kibana-theme/*": ["x-pack/packages/ml/kibana_theme/*"],
"@kbn/ml-local-storage": ["x-pack/packages/ml/local_storage"],
"@kbn/ml-local-storage/*": ["x-pack/packages/ml/local_storage/*"],
"@kbn/ml-locator": ["x-pack/packages/ml/locator"],
"@kbn/ml-locator/*": ["x-pack/packages/ml/locator/*"],
"@kbn/ml-nested-property": ["x-pack/packages/ml/nested_property"],
"@kbn/ml-nested-property/*": ["x-pack/packages/ml/nested_property/*"],
"@kbn/ml-number-utils": ["x-pack/packages/ml/number_utils"],
Expand Down
3 changes: 3 additions & 0 deletions x-pack/packages/ml/embeddables/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# @kbn/ml-embeddables

Empty package generated by @kbn/generate
15 changes: 15 additions & 0 deletions x-pack/packages/ml/embeddables/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* 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.
*/

export {
ANOMALY_SINGLE_METRIC_VIEWER_EMBEDDABLE_TYPE,
ANOMALY_SWIMLANE_EMBEDDABLE_TYPE,
ANOMALY_EXPLORER_CHARTS_EMBEDDABLE_TYPE,
type AnomalyExplorerChartsEmbeddableType,
type AnomalySwimLaneEmbeddableType,
type MlEmbeddableTypes,
} from './constants';
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@
* 2.0.
*/

export const CONTROLLED_BY_SWIM_LANE_FILTER = 'anomaly-swim-lane';
export const CONTROLLED_BY_ANOMALY_CHARTS_FILTER = 'anomaly-charts';
module.exports = {
preset: '@kbn/test/jest_node',
rootDir: '../../../..',
roots: ['<rootDir>/x-pack/packages/ml/embeddables'],
};
5 changes: 5 additions & 0 deletions x-pack/packages/ml/embeddables/kibana.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "shared-common",
"id": "@kbn/ml-embeddables",
"owner": "@elastic/ml-ui"
}
6 changes: 6 additions & 0 deletions x-pack/packages/ml/embeddables/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "@kbn/ml-embeddables",
"private": true,
"version": "1.0.0",
"license": "Elastic License 2.0"
}
17 changes: 17 additions & 0 deletions x-pack/packages/ml/embeddables/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"extends": "../../../../tsconfig.base.json",
"compilerOptions": {
"outDir": "target/types",
"types": [
"jest",
"node"
]
},
"include": [
"**/*.ts",
],
"exclude": [
"target/**/*"
],
"kbn_references": []
}
3 changes: 3 additions & 0 deletions x-pack/packages/ml/locator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# @kbn/ml-locator

Empty package generated by @kbn/generate
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
*/

import { setStateToKbnUrl } from '@kbn/kibana-utils-plugin/public';
import { ML_PAGES } from '../../../common/constants/locator';
import type { ChangePointDetectionUrlState } from '../../../common/types/locator';
import { ML_PAGES } from '../constants';
import type { ChangePointDetectionUrlState } from '../types';

/**
* Creates URL to the Change Point Detection page
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { isEmpty } from 'lodash';
import { setStateToKbnUrl } from '@kbn/kibana-utils-plugin/public';
import type { ListingPageUrlState } from '@kbn/ml-url-state';
import type {
AppPageState,
AnomalyDetectionUrlState,
ExplorerAppState,
ExplorerGlobalState,
Expand All @@ -18,11 +19,10 @@ import type {
TimeSeriesExplorerAppState,
TimeSeriesExplorerGlobalState,
TimeSeriesExplorerUrlState,
} from '../../../common/types/locator';
import { ML_PAGES } from '../../../common/constants/locator';
} from '../types';
import { ML_PAGES } from '../constants';
import { formatGenericMlUrl } from './common';
import { getGroupQueryText, getJobQueryText } from '../../../common/util/string_utils';
import type { AppPageState } from '../../../common/types/common';
import { getGroupQueryText, getJobQueryText } from './string_utils';

/**
* Creates URL to the Anomaly Detection Job management page
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { isEmpty } from 'lodash';
import { setStateToKbnUrl } from '@kbn/kibana-utils-plugin/public';
import type { MlGenericUrlState } from '../../../common/types/locator';
import type { MlGenericUrlState } from '../types';

export function extractParams<UrlState>(urlState: UrlState) {
// page should be guaranteed to exist here but <UrlState> is unknown
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ import { setStateToKbnUrl } from '@kbn/kibana-utils-plugin/public';
import type { ListingPageUrlState } from '@kbn/ml-url-state';
import { formatGenericMlUrl } from './common';
import type {
AppPageState,
DataFrameAnalyticsExplorationQueryState,
DataFrameAnalyticsExplorationUrlState,
DataFrameAnalyticsUrlState,
ExplorationPageUrlState,
MlGenericUrlState,
MlCommonGlobalState,
} from '../../../common/types/locator';
import { ML_PAGES } from '../../../common/constants/locator';
import { getGroupQueryText, getJobQueryText } from '../../../common/util/string_utils';
import type { AppPageState } from '../../../common/types/common';
} from '../types';
import { ML_PAGES } from '../constants';
import { getGroupQueryText, getJobQueryText } from './string_utils';

export function formatDataFrameAnalyticsJobManagementUrl(
appBasePath: string,
Expand Down
24 changes: 24 additions & 0 deletions x-pack/packages/ml/locator/formatters/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* 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.
*/

export { extractParams, formatGenericMlUrl } from './common';
export {
formatAnomalyDetectionJobManagementUrl,
formatAnomalyDetectionCreateJobSelectType,
formatAnomalyDetectionCreateJobSelectIndex,
formatSuppliedConfigurationsManagementUrl,
formatExplorerUrl,
formatSingleMetricViewerUrl,
} from './anomaly_detection';
export {
formatDataFrameAnalyticsJobManagementUrl,
formatDataFrameAnalyticsExplorationUrl,
formatDataFrameAnalyticsCreateJobUrl,
formatDataFrameAnalyticsMapUrl,
} from './data_frame_analytics';
export { formatNotificationsUrl } from './notifications';
export { formatEditCalendarUrl, formatEditFilterUrl } from './settings';
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
*/
import { setStateToKbnUrl } from '@kbn/kibana-utils-plugin/public';
import { isPopulatedObject } from '@kbn/ml-is-populated-object';
import { ML_PAGES } from '../../../common/constants/locator';
import type { NotificationsUrlState } from '../../../common/types/locator';
import { ML_PAGES } from '../constants';
import type { NotificationsUrlState } from '../types';

export interface NotificationsAppState {
level?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
*/

import { setStateToKbnUrl } from '@kbn/kibana-utils-plugin/public';
import type { CalendarEditUrlState, FilterEditUrlState } from '../../../common/types/locator';
import { ML_PAGES } from '../../../common/constants/locator';
import type { CalendarEditUrlState, FilterEditUrlState } from '../types';
import { ML_PAGES } from '../constants';

export function formatEditCalendarUrl(
appBasePath: string,
Expand Down
23 changes: 23 additions & 0 deletions x-pack/packages/ml/locator/formatters/string_utils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* 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.
*/

import { getGroupQueryText } from './string_utils';

describe('getGroupQueryText', () => {
const groupIdOne = 'test_group_id_1';
const groupIdTwo = 'test_group_id_2';

it('should get query string for selected group ids', () => {
const actual = getGroupQueryText([groupIdOne, groupIdTwo]);
expect(actual).toBe(`groups:(${groupIdOne} or ${groupIdTwo})`);
});

it('should get query string for selected group id', () => {
const actual = getGroupQueryText([groupIdOne]);
expect(actual).toBe(`groups:(${groupIdOne})`);
});
});
14 changes: 14 additions & 0 deletions x-pack/packages/ml/locator/formatters/string_utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* 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.
*/

export function getGroupQueryText(groupIds: string[]): string {
return `groups:(${groupIds.join(' or ')})`;
}

export function getJobQueryText(jobIds: string | string[]): string {
return Array.isArray(jobIds) ? `id:(${jobIds.join(' OR ')})` : `id:${jobIds}`;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@

import { setStateToKbnUrl } from '@kbn/kibana-utils-plugin/public';
import type { ListingPageUrlState } from '@kbn/ml-url-state';
import type { MemoryUsageUrlState, TrainedModelsUrlState } from '../../../common/types/locator';
import { ML_PAGES } from '../../../common/constants/locator';
import type { AppPageState } from '../../../common/types/common';
import type { AppPageState, MemoryUsageUrlState, TrainedModelsUrlState } from '../types';
import { ML_PAGES } from '../constants';

export function formatTrainedModelsManagementUrl(
appBasePath: string,
Expand Down
20 changes: 20 additions & 0 deletions x-pack/packages/ml/locator/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* 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.
*/

export { formatExplorerUrl } from './formatters';
export { ML_APP_LOCATOR, ML_PAGES, type MlPages } from './constants';
export { MlLocatorDefinition, type MlLocatorParams, type MlLocator } from './ml_locator';
export { useMlHref } from './use_ml_href';
export type {
AnomalyExplorerFilterUrlState,
AnomalyExplorerSwimLaneUrlState,
AnomalyDetectionQueryState,
ExpandablePanels,
ExplorationPageUrlState,
ExplorerAppState,
TimeSeriesExplorerAppState,
} from './types';
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
* 2.0.
*/

export * from './common';
export * from './anomaly_detection';
export * from './data_frame_analytics';
export * from './settings';
module.exports = {
preset: '@kbn/test/jest_node',
rootDir: '../../../..',
roots: ['<rootDir>/x-pack/packages/ml/locator'],
};
5 changes: 5 additions & 0 deletions x-pack/packages/ml/locator/kibana.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "shared-browser",
"id": "@kbn/ml-locator",
"owner": "@elastic/ml-ui"
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { MlLocatorDefinition } from './ml_locator';
import { ML_PAGES } from '../../common/constants/locator';
import { ML_PAGES } from './constants';
import { ANALYSIS_CONFIG_TYPE } from '@kbn/ml-data-frame-analytics-utils';

describe('ML locator', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import type {
MlLocatorParams,
MlLocator,
ChangePointDetectionQueryState,
} from '../../common/types/locator';
import { ML_APP_LOCATOR, ML_PAGES } from '../../common/constants/locator';
} from './types';
import { ML_APP_LOCATOR, ML_PAGES } from './constants';
import {
formatAnomalyDetectionCreateJobSelectIndex,
formatAnomalyDetectionCreateJobSelectType,
Expand Down
6 changes: 6 additions & 0 deletions x-pack/packages/ml/locator/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "@kbn/ml-locator",
"private": true,
"version": "1.0.0",
"license": "Elastic License 2.0"
}
30 changes: 30 additions & 0 deletions x-pack/packages/ml/locator/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"extends": "../../../../tsconfig.base.json",
"compilerOptions": {
"outDir": "target/types",
"types": [
"jest",
"node",
"react",
"@emotion/react/types/css-prop"
]
},
"include": [
"**/*.ts",
"**/*.tsx",
],
"exclude": [
"target/**/*"
],
"kbn_references": [
"@kbn/kibana-utils-plugin",
"@kbn/ml-url-state",
"@kbn/ml-is-populated-object",
"@kbn/share-plugin",
"@kbn/ml-data-frame-analytics-utils",
"@kbn/utility-types",
"@kbn/data-plugin",
"@kbn/ml-anomaly-utils",
"@kbn/ml-query-utils",
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,16 @@ import type { DataFrameAnalysisConfigType } from '@kbn/ml-data-frame-analytics-u
import type { InfluencersFilterQuery } from '@kbn/ml-anomaly-utils';
import type { SearchQueryLanguage } from '@kbn/ml-query-utils';
import type { ListingPageUrlState } from '@kbn/ml-url-state';
import type { JobId } from './anomaly_detection_jobs/job';
import type { ML_PAGES } from '../constants/locator';
import type { MlPages, ML_PAGES } from './constants';

type JobId = string;

type OptionalPageState = object | undefined;

export type AppPageState<T> = {
[key in MlPages]?: Partial<T>;
};

export type MLPageState<PageType, PageState> = PageState extends OptionalPageState
? { page: PageType; pageState?: PageState }
: PageState extends object
Expand Down
Loading