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 1 commit
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
Next Next commit
@kbn/ml-embeddables
  • Loading branch information
walterra committed Sep 24, 2024
commit d5c3014a09c5460a6e0dc566b7789a9a76ef7915
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,7 @@
"@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",
Expand Down
2 changes: 2 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 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
12 changes: 12 additions & 0 deletions x-pack/packages/ml/embeddables/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +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.
*/

export {
ANOMALY_SINGLE_METRIC_VIEWER_EMBEDDABLE_TYPE,
ANOMALY_SWIMLANE_EMBEDDABLE_TYPE,
ANOMALY_EXPLORER_CHARTS_EMBEDDABLE_TYPE,
} from './constants';
12 changes: 12 additions & 0 deletions x-pack/packages/ml/embeddables/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +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.
*/

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 OR AGPL-3.0-only OR SSPL-1.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": []
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { DataPublicPluginStart } from '@kbn/data-plugin/public';
import { GuidedOnboardingPluginStart } from '@kbn/guided-onboarding-plugin/public';
import { IndexMappingProps } from '@kbn/index-management-shared-types';
import { LensPublicStart } from '@kbn/lens-plugin/public';
import { MlPluginStart } from '@kbn/ml-plugin/public';
import type { MlPluginStart } from '@kbn/ml-plugin/public';
import { ELASTICSEARCH_URL_PLACEHOLDER } from '@kbn/search-api-panels/constants';
import { ConnectorDefinition } from '@kbn/search-connectors-plugin/public';
import type { SearchHomepagePluginStart } from '@kbn/search-homepage/public';
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/enterprise_search/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { i18n } from '@kbn/i18n';
import type { IndexManagementPluginStart } from '@kbn/index-management-shared-types';
import { LensPublicStart } from '@kbn/lens-plugin/public';
import { LicensingPluginStart } from '@kbn/licensing-plugin/public';
import { MlPluginStart } from '@kbn/ml-plugin/public';
import type { MlPluginStart } from '@kbn/ml-plugin/public';
import type { NavigationPublicPluginStart } from '@kbn/navigation-plugin/public';
import { ELASTICSEARCH_URL_PLACEHOLDER } from '@kbn/search-api-panels/constants';
import { SearchConnectorsPluginStart } from '@kbn/search-connectors-plugin/public';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
} from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { TrainedModelStat } from '@kbn/ml-plugin/common/types/trained_models';
import { MlPluginStart } from '@kbn/ml-plugin/public';
import type { MlPluginStart } from '@kbn/ml-plugin/public';
import classNames from 'classnames';
import React, { useEffect } from 'react';
import { EUI_SIZE, TYPE_DEFINITION } from '../../../../constants';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { useCallback } from 'react';
import { MlPluginStart } from '@kbn/ml-plugin/public';
import type { MlPluginStart } from '@kbn/ml-plugin/public';
import React, { useEffect } from 'react';
import { InferenceTaskType } from '@elastic/elasticsearch/lib/api/types';
import { ElserModels } from '@kbn/ml-trained-models-utils';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { i18n } from '@kbn/i18n';
import { Index } from '@kbn/index-management-shared-types';
import { MlPluginStart } from '@kbn/ml-plugin/public';
import type { MlPluginStart } from '@kbn/ml-plugin/public';
import { useState, useEffect } from 'react';
import { normalize } from '../components/mappings_editor/lib';
import { isLocalModel } from '../components/mappings_editor/lib/utils';
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/index_management/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
import { CloudSetup } from '@kbn/cloud-plugin/public';
import { ConsolePluginStart } from '@kbn/console-plugin/public';
import { ManagementSetup } from '@kbn/management-plugin/public';
import { MlPluginStart } from '@kbn/ml-plugin/public';
import type { MlPluginStart } from '@kbn/ml-plugin/public';
import { SharePluginSetup, SharePluginStart } from '@kbn/share-plugin/public';
import { UsageCollectionSetup } from '@kbn/usage-collection-plugin/public';
import { LicensingPluginStart } from '@kbn/licensing-plugin/public';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import type { FC } from 'react';
import React, { useCallback, useMemo, useState } from 'react';
import { isEqual } from 'lodash';

import type {
EuiContextMenuPanelDescriptor,
EuiContextMenuPanelItemDescriptor,
Expand All @@ -26,6 +27,7 @@ import {
EuiTitle,
htmlIdGenerator,
} from '@elastic/eui';

import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n-react';
import useDebounce from 'react-use/lib/useDebounce';
Expand All @@ -41,11 +43,12 @@ import {
withSuspense,
} from '@kbn/presentation-util-plugin/public';
import { useTimeBuckets } from '@kbn/ml-time-buckets';
import { ANOMALY_SWIMLANE_EMBEDDABLE_TYPE } from '@kbn/ml-embeddables';

import type { JobId } from '../../../common/types/anomaly_detection_jobs';
import { getDefaultSwimlanePanelTitle } from '../../embeddables/anomaly_swimlane/anomaly_swimlane_embeddable';
import { useCasesModal } from '../contexts/kibana/use_cases_modal';
import type { AnomalySwimLaneEmbeddableState } from '../..';
import { ANOMALY_SWIMLANE_EMBEDDABLE_TYPE } from '../..';
import type { SwimlaneType } from './explorer_constants';
import { OVERALL_LABEL, SWIMLANE_TYPE, VIEW_BY_JOB_LABEL } from './explorer_constants';
import { useMlKibana } from '../contexts/kibana';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ import {
withSuspense,
} from '@kbn/presentation-util-plugin/public';
import { useTimeRangeUpdates } from '@kbn/ml-date-picker';
import { ANOMALY_SINGLE_METRIC_VIEWER_EMBEDDABLE_TYPE } from '@kbn/ml-embeddables';
import type { JobId } from '../../../../../common/types/anomaly_detection_jobs/job';
import { useMlKibana } from '../../../contexts/kibana';
import { useCasesModal } from '../../../contexts/kibana/use_cases_modal';
import { getDefaultSingleMetricViewerPanelTitle } from '../../../../embeddables/single_metric_viewer/get_default_panel_title';
import type { MlEntity } from '../../../../embeddables';
import { ANOMALY_SINGLE_METRIC_VIEWER_EMBEDDABLE_TYPE } from '../../../../embeddables/constants';
import type { SingleMetricViewerEmbeddableState } from '../../../../embeddables/types';

interface Props {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { setStubKibanaServices } from '@kbn/presentation-panel-plugin/public/moc
import { render, waitFor, screen } from '@testing-library/react';
import React from 'react';
import { of } from 'rxjs';
import { ANOMALY_SWIMLANE_EMBEDDABLE_TYPE } from '../constants';
import { ANOMALY_SWIMLANE_EMBEDDABLE_TYPE } from '@kbn/ml-embeddables';
import { getAnomalySwimLaneEmbeddableFactory } from './anomaly_swimlane_embeddable_factory';
import type { AnomalySwimLaneEmbeddableApi, AnomalySwimLaneEmbeddableState } from './types';
import { embeddablePluginMock } from '@kbn/embeddable-plugin/public/mocks';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import React, { useCallback, useState } from 'react';
import useUnmount from 'react-use/lib/useUnmount';
import type { Observable } from 'rxjs';
import { BehaviorSubject, combineLatest, map, of, Subscription } from 'rxjs';
import { ANOMALY_SWIMLANE_EMBEDDABLE_TYPE } from '@kbn/ml-embeddables';
import type { AnomalySwimlaneEmbeddableServices } from '..';
import { ANOMALY_SWIMLANE_EMBEDDABLE_TYPE } from '..';
import type { MlDependencies } from '../../application/app';
import { Y_AXIS_LABEL_WIDTH } from '../../application/explorer/constants';
import type { AppStateSelectedCells } from '../../application/explorer/explorer_utils';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ import type {
SerializedTitles,
} from '@kbn/presentation-publishing';
import { apiIsOfType } from '@kbn/presentation-publishing';
import { ANOMALY_SWIMLANE_EMBEDDABLE_TYPE } from '@kbn/ml-embeddables';
import type { SwimlaneType } from '../../application/explorer/explorer_constants';

import type { JobId } from '../../../common/types/anomaly_detection_jobs';
import type { AppStateSelectedCells } from '../../application/explorer/explorer_utils';
import { ANOMALY_SWIMLANE_EMBEDDABLE_TYPE } from '../constants';
import type {
AnomalySwimlaneEmbeddableCustomInput,
AnomalySwimlaneEmbeddableUserInput,
Expand Down
6 changes: 3 additions & 3 deletions x-pack/plugins/ml/public/embeddables/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
*/

import type { EmbeddableSetup } from '@kbn/embeddable-plugin/public';
import type { MlCoreSetup } from '../plugin';
import {
ANOMALY_SINGLE_METRIC_VIEWER_EMBEDDABLE_TYPE,
ANOMALY_SWIMLANE_EMBEDDABLE_TYPE,
ANOMALY_EXPLORER_CHARTS_EMBEDDABLE_TYPE,
} from './constants';
} from '@kbn/ml-embeddables';

import type { MlCoreSetup } from '../plugin';

export * from './constants';
export * from './types';

export function registerEmbeddables(embeddable: EmbeddableSetup, core: MlCoreSetup) {
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/ml/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export type { DataRecognizerConfigResponse } from '../common/types/modules';

export type { AnomalySwimLaneEmbeddableApi, AnomalySwimLaneEmbeddableState } from './embeddables';

export { ANOMALY_SWIMLANE_EMBEDDABLE_TYPE } from './embeddables/constants';
export { CONTROLLED_BY_SWIM_LANE_FILTER } from './ui_actions/constants';

export type { MlLocator } from './locator';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import type { PublishesWritableUnifiedSearch } from '@kbn/presentation-publishin
import type { HasSerializedChildState } from '@kbn/presentation-containers';
import React, { useEffect, useMemo, useRef, type FC } from 'react';
import { BehaviorSubject } from 'rxjs';
import { ANOMALY_SWIMLANE_EMBEDDABLE_TYPE } from '@kbn/ml-embeddables';
import type {
AnomalySwimLaneEmbeddableApi,
AnomalySwimlaneEmbeddableCustomInput,
AnomalySwimLaneEmbeddableState,
} from '../embeddables';
import { ANOMALY_SWIMLANE_EMBEDDABLE_TYPE } from '../embeddables';

export interface AnomalySwimLaneProps extends AnomalySwimlaneEmbeddableCustomInput {
id?: string;
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/ml/public/ui_actions/create_swim_lane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import type { PresentationContainer } from '@kbn/presentation-containers';
import type { EmbeddableApiContext } from '@kbn/presentation-publishing';
import type { UiActionsActionDefinition } from '@kbn/ui-actions-plugin/public';
import { IncompatibleActionError } from '@kbn/ui-actions-plugin/public';
import { ANOMALY_SWIMLANE_EMBEDDABLE_TYPE } from '@kbn/ml-embeddables';
import { ML_APP_NAME, PLUGIN_ICON, PLUGIN_ID } from '../../common/constants/app';
import { ANOMALY_SWIMLANE_EMBEDDABLE_TYPE } from '../embeddables';
import type { AnomalySwimLaneEmbeddableApi } from '../embeddables/anomaly_swimlane/types';
import type { MlCoreSetup } from '../plugin';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import moment from 'moment';
import React, { useMemo } from 'react';
import { ANOMALY_SWIMLANE_EMBEDDABLE_TYPE } from '@kbn/ml-plugin/public';
import { ANOMALY_SWIMLANE_EMBEDDABLE_TYPE } from '@kbn/ml-embeddables';
import { MissingEmbeddableFactoryCallout } from '../../../../../components/missing_embeddable_factory_callout';
import { partitionField } from '../../../../../../common/infra_ml';
import { TimeRange } from '../../../../../../common/time/time_range';
Expand Down
4 changes: 4 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5695,6 +5695,10 @@
version "0.0.0"
uid ""

"@kbn/ml-embeddables@link:x-pack/packages/ml/embeddables":
version "0.0.0"
uid ""

"@kbn/ml-error-utils@link:x-pack/packages/ml/error_utils":
version "0.0.0"
uid ""
Expand Down