Skip to content

Commit

Permalink
[7.x] [Uptime] Reduce miscellaneous uptime bundle size (elastic#70632) (
Browse files Browse the repository at this point in the history
elastic#73733)

Co-authored-by: Elastic Machine <[email protected]>
Co-authored-by: Shahzad <[email protected]>
Co-authored-by: Justin Kambic <[email protected]>
  • Loading branch information
4 people authored Jul 30, 2020
1 parent b393516 commit 4f92b68
Show file tree
Hide file tree
Showing 46 changed files with 327 additions and 265 deletions.
1 change: 1 addition & 0 deletions x-pack/plugins/triggers_actions_ui/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export {
ActionType,
ActionTypeRegistryContract,
AlertTypeParamsExpressionProps,
ValidationResult,
ActionVariable,
} from './types';
export {
Expand Down
2 changes: 0 additions & 2 deletions x-pack/plugins/uptime/common/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@
* you may not use this file except in compliance with the Elastic License.
*/

export * from './alerts';
export { CHART_FORMAT_LIMITS } from './chart_format_limits';
export { CLIENT_DEFAULTS } from './client_defaults';
export { CONTEXT_DEFAULTS } from './context_defaults';
export * from './capabilities';
export * from './settings_defaults';
export { PLUGIN } from './plugin';
export { QUERY } from './query';
export * from './ui';
export * from './rest_api';
7 changes: 0 additions & 7 deletions x-pack/plugins/uptime/public/app.ts

This file was deleted.

7 changes: 0 additions & 7 deletions x-pack/plugins/uptime/public/apps/index.ts

This file was deleted.

39 changes: 20 additions & 19 deletions x-pack/plugins/uptime/public/apps/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ import {
AppMountParameters,
} from 'kibana/public';
import { DEFAULT_APP_CATEGORIES } from '../../../../../src/core/public';
import { UMFrontendLibs } from '../lib/lib';
import { PLUGIN } from '../../common/constants';
import { FeatureCatalogueCategory } from '../../../../../src/plugins/home/public';
import { HomePublicPluginSetup } from '../../../../../src/plugins/home/public';

import {
FeatureCatalogueCategory,
HomePublicPluginSetup,
} from '../../../../../src/plugins/home/public';
import { EmbeddableStart } from '../../../../../src/plugins/embeddable/public';
import {
TriggersAndActionsUIPublicPluginSetup,
Expand All @@ -26,10 +27,8 @@ import {
DataPublicPluginStart,
} from '../../../../../src/plugins/data/public';
import { alertTypeInitializers } from '../lib/alert_types';
import { kibanaService } from '../state/kibana_service';
import { fetchIndexStatus } from '../state/api';
import { ObservabilityPluginSetup } from '../../../observability/public';
import { fetchUptimeOverviewData } from './uptime_overview_fetcher';
import { FetchDataParams, ObservabilityPluginSetup } from '../../../observability/public';
import { PLUGIN } from '../../common/constants/plugin';

export interface ClientPluginsSetup {
data: DataPublicPluginSetup;
Expand Down Expand Up @@ -66,14 +65,23 @@ export class UptimePlugin
category: FeatureCatalogueCategory.DATA,
});
}
const getUptimeDataHelper = async () => {
const [coreStart] = await core.getStartServices();
const { UptimeDataHelper } = await import('./uptime_overview_fetcher');

return UptimeDataHelper(coreStart);
};
plugins.observability.dashboard.register({
appName: 'uptime',
hasData: async () => {
const status = await fetchIndexStatus();
const dataHelper = await getUptimeDataHelper();
const status = await dataHelper.indexStatus();
return status.docCount > 0;
},
fetchData: fetchUptimeOverviewData,
fetchData: async (params: FetchDataParams) => {
const dataHelper = await getUptimeDataHelper();
return await dataHelper.overviewData(params);
},
});

core.application.register({
Expand All @@ -85,22 +93,15 @@ export class UptimePlugin
category: DEFAULT_APP_CATEGORIES.observability,
mount: async (params: AppMountParameters) => {
const [coreStart, corePlugins] = await core.getStartServices();
const { getKibanaFrameworkAdapter } = await import(
'../lib/adapters/framework/new_platform_adapter'
);

const { element } = params;
const { renderApp } = await import('./render_app');

const libs: UMFrontendLibs = {
framework: getKibanaFrameworkAdapter(coreStart, plugins, corePlugins),
};
return libs.framework.render(element);
return renderApp(coreStart, plugins, corePlugins, params);
},
});
}

public start(start: CoreStart, plugins: ClientPluginsStart): void {
kibanaService.core = start;
alertTypeInitializers.forEach((init) => {
const alertInitializer = init({
core: start,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { CoreStart } from 'src/core/public';
import React from 'react';
import ReactDOM from 'react-dom';
import { i18n as i18nFormatter } from '@kbn/i18n';
import { UptimeApp, UptimeAppProps } from '../../../uptime_app';
import { getIntegratedAppAvailability } from './capabilities_adapter';
import { AppMountParameters, CoreStart } from 'kibana/public';
import { getIntegratedAppAvailability } from '../lib/adapters/framework/capabilities_adapter';
import {
INTEGRATED_SOLUTIONS,
PLUGIN,
DEFAULT_DARK_MODE,
DEFAULT_TIMEPICKER_QUICK_RANGES,
} from '../../../../common/constants';
import { UMFrameworkAdapter } from '../../lib';
import { ClientPluginsStart, ClientPluginsSetup } from '../../../apps/plugin';
INTEGRATED_SOLUTIONS,
} from '../../common/constants';
import { UptimeApp, UptimeAppProps } from './uptime_app';
import { ClientPluginsSetup, ClientPluginsStart } from './plugin';
import { PLUGIN } from '../../common/constants/plugin';

export const getKibanaFrameworkAdapter = (
export function renderApp(
core: CoreStart,
plugins: ClientPluginsSetup,
startPlugins: ClientPluginsStart
): UMFrameworkAdapter => {
startPlugins: ClientPluginsStart,
{ element }: AppMountParameters
) {
const {
application: { capabilities },
chrome: { setBadge, setHelpExtension },
Expand All @@ -40,17 +40,17 @@ export const getKibanaFrameworkAdapter = (
const canSave = (capabilities.uptime.save ?? false) as boolean;

const props: UptimeAppProps = {
basePath: basePath.get(),
plugins,
canSave,
core,
i18n,
startPlugins,
basePath: basePath.get(),
darkMode: core.uiSettings.get(DEFAULT_DARK_MODE),
commonlyUsedRanges: core.uiSettings.get(DEFAULT_TIMEPICKER_QUICK_RANGES),
i18n,
isApmAvailable: apm,
isInfraAvailable: infrastructure,
isLogsAvailable: logs,
plugins,
startPlugins,
renderGlobalHelpControls: () =>
setHelpExtension({
appName: i18nFormatter.translate('xpack.uptime.header.appName', {
Expand All @@ -72,15 +72,9 @@ export const getKibanaFrameworkAdapter = (
setBreadcrumbs: core.chrome.setBreadcrumbs,
};

return {
render: async (element: any) => {
if (element) {
ReactDOM.render(<UptimeApp {...props} />, element);
}
ReactDOM.render(<UptimeApp {...props} />, element);

return () => {
ReactDOM.unmountComponentAtNode(element);
};
},
return () => {
ReactDOM.unmountComponentAtNode(element);
};
};
}
1 change: 0 additions & 1 deletion x-pack/plugins/uptime/public/apps/template.html

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,25 @@ import { i18n } from '@kbn/i18n';
import React, { useEffect } from 'react';
import { Provider as ReduxProvider } from 'react-redux';
import { BrowserRouter as Router } from 'react-router-dom';
import { I18nStart, ChromeBreadcrumb, CoreStart } from 'src/core/public';
import { KibanaContextProvider } from '../../../../src/plugins/kibana_react/public';
import { ClientPluginsSetup, ClientPluginsStart } from './apps/plugin';
import { UMUpdateBadge } from './lib/lib';
import { I18nStart, ChromeBreadcrumb, CoreStart } from 'kibana/public';
import { KibanaContextProvider } from '../../../../../src/plugins/kibana_react/public';
import { ClientPluginsSetup, ClientPluginsStart } from './plugin';
import { UMUpdateBadge } from '../lib/lib';
import {
UptimeRefreshContextProvider,
UptimeSettingsContextProvider,
UptimeThemeContextProvider,
UptimeStartupPluginsContextProvider,
} from './contexts';
import { CommonlyUsedRange } from './components/common/uptime_date_picker';
import { setBasePath } from './state/actions';
import { PageRouter } from './routes';
} from '../contexts';
import { CommonlyUsedRange } from '../components/common/uptime_date_picker';
import { setBasePath } from '../state/actions';
import { PageRouter } from '../routes';
import {
UptimeAlertsContextProvider,
UptimeAlertsFlyoutWrapper,
} from './components/overview/alerts';
import { store } from './state';
} from '../components/overview/alerts';
import { store } from '../state';
import { kibanaService } from '../state/kibana_service';

export interface UptimeAppColors {
danger: string;
Expand Down Expand Up @@ -86,6 +87,8 @@ const Application = (props: UptimeAppProps) => {
);
}, [canSave, renderGlobalHelpControls, setBadge]);

kibanaService.core = core;

store.dispatch(setBasePath(basePath));

return (
Expand Down
15 changes: 13 additions & 2 deletions x-pack/plugins/uptime/public/apps/uptime_overview_fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { fetchPingHistogram, fetchSnapshotCount } from '../state/api';
import { CoreStart } from 'kibana/public';
import { UptimeFetchDataResponse, FetchDataParams } from '../../../observability/public';
import { fetchIndexStatus, fetchPingHistogram, fetchSnapshotCount } from '../state/api';
import { kibanaService } from '../state/kibana_service';

export async function fetchUptimeOverviewData({
async function fetchUptimeOverviewData({
absoluteTime,
relativeTime,
bucketSize,
Expand Down Expand Up @@ -52,3 +54,12 @@ export async function fetchUptimeOverviewData({
};
return response;
}

export function UptimeDataHelper(coreStart: CoreStart | null) {
kibanaService.core = coreStart!;

return {
indexStatus: fetchIndexStatus,
overviewData: fetchUptimeOverviewData,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import React, { useContext, useState } from 'react';

import { EuiButton, EuiContextMenu, EuiIcon, EuiPopover } from '@elastic/eui';
import { useSelector, useDispatch } from 'react-redux';
import { CLIENT_ALERT_TYPES } from '../../../../common/constants';
import { CLIENT_ALERT_TYPES } from '../../../../common/constants/alerts';
import {
canDeleteMLJobSelector,
hasMLJobSelector,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ import {
import { MLJobLink } from './ml_job_link';
import * as labels from './translations';
import { MLFlyoutView } from './ml_flyout';
import { CLIENT_ALERT_TYPES, ML_JOB_ID } from '../../../../common/constants';
import { ML_JOB_ID } from '../../../../common/constants';
import { UptimeRefreshContext, UptimeSettingsContext } from '../../../contexts';
import { useGetUrlParams } from '../../../hooks';
import { getDynamicSettings } from '../../../state/actions/dynamic_settings';
import { useMonitorId } from '../../../hooks';
import { kibanaService } from '../../../state/kibana_service';
import { toMountPoint } from '../../../../../../../src/plugins/kibana_react/public';
import { CLIENT_ALERT_TYPES } from '../../../../common/constants/alerts';

interface Props {
onClose: () => void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { getLayerList } from '../map_config';
import { mockLayerList } from './__mocks__/mock';
import { LocationPoint } from '../embedded_map';
import { UptimeAppColors } from '../../../../../../uptime_app';
import { UptimeAppColors } from '../../../../../../apps/uptime_app';

jest.mock('uuid', () => {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import lowPolyLayerFeatures from './low_poly_layer.json';
import { LocationPoint } from './embedded_map';
import { UptimeAppColors } from '../../../../../uptime_app';
import { UptimeAppColors } from '../../../../../apps/uptime_app';

/**
* Returns `Source/Destination Point-to-point` Map LayerList configuration, with a source,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,3 @@ export const AlertTls: React.FC<{}> = () => {
/>
);
};

// eslint-disable-next-line import/no-default-export
export { AlertTls as default };
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ interface Props {
setAlertParams: (key: string, value: any) => void;
}

// eslint-disable-next-line import/no-default-export
export default function AnomalyAlertComponent({ setAlertParams, alertParams }: Props) {
export function AnomalyAlertComponent({ setAlertParams, alertParams }: Props) {
const [severity, setSeverity] = useState(DEFAULT_SEVERITY);

const monitorIdStore = useSelector(monitorIdSelector);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
import React, { useState } from 'react';
import { FormattedMessage } from '@kbn/i18n/react';
import { useKibana } from '../../../../../../../src/plugins/kibana_react/public';
import { CLIENT_ALERT_TYPES } from '../../../../common/constants';
import { CLIENT_ALERT_TYPES } from '../../../../common/constants/alerts';
import { ToggleFlyoutTranslations } from './translations';
import { ToggleAlertFlyoutButtonProps } from './alerts_containers';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
*/

import React, { useState, useEffect } from 'react';
import { uniqueId, startsWith } from 'lodash';
import { EuiCallOut } from '@elastic/eui';
import { EuiCallOut, htmlIdGenerator } from '@elastic/eui';
import styled from 'styled-components';
import { FormattedMessage } from '@kbn/i18n/react';
import { Typeahead } from './typeahead';
Expand Down Expand Up @@ -94,7 +93,7 @@ export function KueryBar({
setState({ ...state, suggestions: [] });
setSuggestionLimit(15);

const currentRequest = uniqueId();
const currentRequest = htmlIdGenerator()();
currentRequestCheck = currentRequest;

try {
Expand All @@ -116,7 +115,7 @@ export function KueryBar({
},
],
})) || []
).filter((suggestion: QuerySuggestion) => !startsWith(suggestion.text, 'span.'));
).filter((suggestion: QuerySuggestion) => !suggestion.text.startsWith('span.'));
if (currentRequest !== currentRequestCheck) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { get } from 'lodash';
import { i18n } from '@kbn/i18n';
import React from 'react';
import { EuiPopover, EuiButton } from '@elastic/eui';
Expand All @@ -25,7 +24,8 @@ export const ActionsPopoverComponent = ({
}: ActionsPopoverProps) => {
const popoverId = `${summary.monitor_id}_popover`;

const monitorUrl: string | undefined = get(summary, 'state.url.full', undefined);
const monitorUrl: string | undefined = summary?.state?.url?.full;

const isPopoverOpen: boolean =
!!popoverState && popoverState.open && popoverState.id === popoverId;
return (
Expand Down
Loading

0 comments on commit 4f92b68

Please sign in to comment.