From 330c966f4f7837d337a46268469ed3528d0062dd Mon Sep 17 00:00:00 2001 From: Shahzad Date: Tue, 28 Jul 2020 16:30:58 +0200 Subject: [PATCH] [Uptime] Reduce miscellaneous uptime bundle size (#70632) Co-authored-by: Elastic Machine --- .../triggers_actions_ui/public/index.ts | 1 + .../plugins/uptime/common/constants/index.ts | 2 - x-pack/plugins/uptime/public/app.ts | 7 -- x-pack/plugins/uptime/public/apps/index.ts | 7 -- x-pack/plugins/uptime/public/apps/plugin.ts | 39 ++++---- .../render_app.tsx} | 44 ++++----- .../plugins/uptime/public/apps/template.html | 1 - .../uptime/public/{ => apps}/uptime_app.tsx | 23 +++-- .../public/apps/uptime_overview_fetcher.ts | 15 ++- .../components/monitor/ml/manage_ml_job.tsx | 2 +- .../monitor/ml/ml_flyout_container.tsx | 3 +- .../embeddables/__tests__/map_config.test.ts | 2 +- .../location_map/embeddables/map_config.ts | 2 +- .../alerts/alerts_containers/alert_tls.tsx | 3 - .../alerts/anomaly_alert/anomaly_alert.tsx | 3 +- .../alerts/toggle_alert_flyout_button.tsx | 2 +- .../overview/kuery_bar/kuery_bar.tsx | 7 +- .../actions_popover/actions_popover.tsx | 4 +- .../actions_popover/integration_group.tsx | 9 +- .../monitor_status_list.tsx | 5 +- .../monitor_list_status_column.tsx | 5 +- .../contexts/uptime_settings_context.tsx | 2 +- .../public/contexts/uptime_theme_context.tsx | 2 +- x-pack/plugins/uptime/public/index.ts | 2 +- .../__tests__/monitor_status.test.ts | 21 ++--- .../lib/alert_types/duration_anomaly.tsx | 18 +--- .../lazy_wrapper/duration_anomaly.tsx | 32 +++++++ .../lazy_wrapper/monitor_status.tsx | 32 +++++++ .../alert_types/lazy_wrapper/tls_alert.tsx | 32 +++++++ .../lazy_wrapper/validate_monitor_status.ts | 56 +++++++++++ .../public/lib/alert_types/monitor_status.tsx | 94 +++++-------------- .../lib/alert_types/monitor_status_title.tsx | 17 ---- .../uptime/public/lib/alert_types/tls.tsx | 17 +--- .../observability_integration/build_href.ts | 9 +- .../observability_integration/get_apm_href.ts | 3 +- .../get_infra_href.ts | 12 ++- .../get_logging_href.ts | 12 ++- x-pack/plugins/uptime/public/lib/lib.ts | 13 --- .../uptime/public/pages/certificates.tsx | 3 +- .../plugins/uptime/public/pages/settings.tsx | 12 ++- .../plugins/uptime/public/state/api/utils.ts | 6 +- .../public/state/effects/index_status.ts | 2 +- x-pack/plugins/uptime/server/kibana.index.ts | 2 +- .../server/lib/alerts/duration_anomaly.ts | 2 +- .../uptime/server/lib/alerts/status_check.ts | 2 +- .../plugins/uptime/server/lib/alerts/tls.ts | 3 +- 46 files changed, 327 insertions(+), 265 deletions(-) delete mode 100644 x-pack/plugins/uptime/public/app.ts delete mode 100644 x-pack/plugins/uptime/public/apps/index.ts rename x-pack/plugins/uptime/public/{lib/adapters/framework/new_platform_adapter.tsx => apps/render_app.tsx} (72%) delete mode 100644 x-pack/plugins/uptime/public/apps/template.html rename x-pack/plugins/uptime/public/{ => apps}/uptime_app.tsx (84%) create mode 100644 x-pack/plugins/uptime/public/lib/alert_types/lazy_wrapper/duration_anomaly.tsx create mode 100644 x-pack/plugins/uptime/public/lib/alert_types/lazy_wrapper/monitor_status.tsx create mode 100644 x-pack/plugins/uptime/public/lib/alert_types/lazy_wrapper/tls_alert.tsx create mode 100644 x-pack/plugins/uptime/public/lib/alert_types/lazy_wrapper/validate_monitor_status.ts delete mode 100644 x-pack/plugins/uptime/public/lib/alert_types/monitor_status_title.tsx diff --git a/x-pack/plugins/triggers_actions_ui/public/index.ts b/x-pack/plugins/triggers_actions_ui/public/index.ts index 1048e15eb1184..7808e2a7f608d 100644 --- a/x-pack/plugins/triggers_actions_ui/public/index.ts +++ b/x-pack/plugins/triggers_actions_ui/public/index.ts @@ -19,6 +19,7 @@ export { ActionType, ActionTypeRegistryContract, AlertTypeParamsExpressionProps, + ValidationResult, ActionVariable, } from './types'; export { diff --git a/x-pack/plugins/uptime/common/constants/index.ts b/x-pack/plugins/uptime/common/constants/index.ts index 0ddb995301266..29ae9e47dfb8a 100644 --- a/x-pack/plugins/uptime/common/constants/index.ts +++ b/x-pack/plugins/uptime/common/constants/index.ts @@ -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'; diff --git a/x-pack/plugins/uptime/public/app.ts b/x-pack/plugins/uptime/public/app.ts deleted file mode 100644 index b068f8a9becda..0000000000000 --- a/x-pack/plugins/uptime/public/app.ts +++ /dev/null @@ -1,7 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import './apps/index'; diff --git a/x-pack/plugins/uptime/public/apps/index.ts b/x-pack/plugins/uptime/public/apps/index.ts deleted file mode 100644 index 65b80d08d4f20..0000000000000 --- a/x-pack/plugins/uptime/public/apps/index.ts +++ /dev/null @@ -1,7 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -export { UptimePlugin } from './plugin'; diff --git a/x-pack/plugins/uptime/public/apps/plugin.ts b/x-pack/plugins/uptime/public/apps/plugin.ts index 9af4dea9dbb44..cf750434ab324 100644 --- a/x-pack/plugins/uptime/public/apps/plugin.ts +++ b/x-pack/plugins/uptime/public/apps/plugin.ts @@ -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, @@ -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; @@ -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({ @@ -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, diff --git a/x-pack/plugins/uptime/public/lib/adapters/framework/new_platform_adapter.tsx b/x-pack/plugins/uptime/public/apps/render_app.tsx similarity index 72% rename from x-pack/plugins/uptime/public/lib/adapters/framework/new_platform_adapter.tsx rename to x-pack/plugins/uptime/public/apps/render_app.tsx index d6185f2c2589a..f834f8b5cdd3c 100644 --- a/x-pack/plugins/uptime/public/lib/adapters/framework/new_platform_adapter.tsx +++ b/x-pack/plugins/uptime/public/apps/render_app.tsx @@ -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 }, @@ -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', { @@ -72,15 +72,9 @@ export const getKibanaFrameworkAdapter = ( setBreadcrumbs: core.chrome.setBreadcrumbs, }; - return { - render: async (element: any) => { - if (element) { - ReactDOM.render(, element); - } + ReactDOM.render(, element); - return () => { - ReactDOM.unmountComponentAtNode(element); - }; - }, + return () => { + ReactDOM.unmountComponentAtNode(element); }; -}; +} diff --git a/x-pack/plugins/uptime/public/apps/template.html b/x-pack/plugins/uptime/public/apps/template.html deleted file mode 100644 index a6fb47048a9b1..0000000000000 --- a/x-pack/plugins/uptime/public/apps/template.html +++ /dev/null @@ -1 +0,0 @@ -
\ No newline at end of file diff --git a/x-pack/plugins/uptime/public/uptime_app.tsx b/x-pack/plugins/uptime/public/apps/uptime_app.tsx similarity index 84% rename from x-pack/plugins/uptime/public/uptime_app.tsx rename to x-pack/plugins/uptime/public/apps/uptime_app.tsx index 4208d79e761ed..41370f9fff492 100644 --- a/x-pack/plugins/uptime/public/uptime_app.tsx +++ b/x-pack/plugins/uptime/public/apps/uptime_app.tsx @@ -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; @@ -86,6 +87,8 @@ const Application = (props: UptimeAppProps) => { ); }, [canSave, renderGlobalHelpControls, setBadge]); + kibanaService.core = core; + store.dispatch(setBasePath(basePath)); return ( diff --git a/x-pack/plugins/uptime/public/apps/uptime_overview_fetcher.ts b/x-pack/plugins/uptime/public/apps/uptime_overview_fetcher.ts index d1e394dd4da6b..7e5c18f13b29e 100644 --- a/x-pack/plugins/uptime/public/apps/uptime_overview_fetcher.ts +++ b/x-pack/plugins/uptime/public/apps/uptime_overview_fetcher.ts @@ -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, @@ -52,3 +54,12 @@ export async function fetchUptimeOverviewData({ }; return response; } + +export function UptimeDataHelper(coreStart: CoreStart | null) { + kibanaService.core = coreStart!; + + return { + indexStatus: fetchIndexStatus, + overviewData: fetchUptimeOverviewData, + }; +} diff --git a/x-pack/plugins/uptime/public/components/monitor/ml/manage_ml_job.tsx b/x-pack/plugins/uptime/public/components/monitor/ml/manage_ml_job.tsx index 87496e91c906c..7a2899558891d 100644 --- a/x-pack/plugins/uptime/public/components/monitor/ml/manage_ml_job.tsx +++ b/x-pack/plugins/uptime/public/components/monitor/ml/manage_ml_job.tsx @@ -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, diff --git a/x-pack/plugins/uptime/public/components/monitor/ml/ml_flyout_container.tsx b/x-pack/plugins/uptime/public/components/monitor/ml/ml_flyout_container.tsx index 84634f328621f..e4fe1901729d3 100644 --- a/x-pack/plugins/uptime/public/components/monitor/ml/ml_flyout_container.tsx +++ b/x-pack/plugins/uptime/public/components/monitor/ml/ml_flyout_container.tsx @@ -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; diff --git a/x-pack/plugins/uptime/public/components/monitor/status_details/location_map/embeddables/__tests__/map_config.test.ts b/x-pack/plugins/uptime/public/components/monitor/status_details/location_map/embeddables/__tests__/map_config.test.ts index 09a41bd9eb4b9..18b43434da24b 100644 --- a/x-pack/plugins/uptime/public/components/monitor/status_details/location_map/embeddables/__tests__/map_config.test.ts +++ b/x-pack/plugins/uptime/public/components/monitor/status_details/location_map/embeddables/__tests__/map_config.test.ts @@ -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 { diff --git a/x-pack/plugins/uptime/public/components/monitor/status_details/location_map/embeddables/map_config.ts b/x-pack/plugins/uptime/public/components/monitor/status_details/location_map/embeddables/map_config.ts index e766641102a24..6f9b7e4d39c16 100644 --- a/x-pack/plugins/uptime/public/components/monitor/status_details/location_map/embeddables/map_config.ts +++ b/x-pack/plugins/uptime/public/components/monitor/status_details/location_map/embeddables/map_config.ts @@ -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, diff --git a/x-pack/plugins/uptime/public/components/overview/alerts/alerts_containers/alert_tls.tsx b/x-pack/plugins/uptime/public/components/overview/alerts/alerts_containers/alert_tls.tsx index c7657c34220fc..70adcdb563bce 100644 --- a/x-pack/plugins/uptime/public/components/overview/alerts/alerts_containers/alert_tls.tsx +++ b/x-pack/plugins/uptime/public/components/overview/alerts/alerts_containers/alert_tls.tsx @@ -24,6 +24,3 @@ export const AlertTls: React.FC<{}> = () => { /> ); }; - -// eslint-disable-next-line import/no-default-export -export { AlertTls as default }; diff --git a/x-pack/plugins/uptime/public/components/overview/alerts/anomaly_alert/anomaly_alert.tsx b/x-pack/plugins/uptime/public/components/overview/alerts/anomaly_alert/anomaly_alert.tsx index 4b84012575ae9..1428a7f526fc2 100644 --- a/x-pack/plugins/uptime/public/components/overview/alerts/anomaly_alert/anomaly_alert.tsx +++ b/x-pack/plugins/uptime/public/components/overview/alerts/anomaly_alert/anomaly_alert.tsx @@ -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); diff --git a/x-pack/plugins/uptime/public/components/overview/alerts/toggle_alert_flyout_button.tsx b/x-pack/plugins/uptime/public/components/overview/alerts/toggle_alert_flyout_button.tsx index 18514bd92d7a0..067972a452f27 100644 --- a/x-pack/plugins/uptime/public/components/overview/alerts/toggle_alert_flyout_button.tsx +++ b/x-pack/plugins/uptime/public/components/overview/alerts/toggle_alert_flyout_button.tsx @@ -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'; diff --git a/x-pack/plugins/uptime/public/components/overview/kuery_bar/kuery_bar.tsx b/x-pack/plugins/uptime/public/components/overview/kuery_bar/kuery_bar.tsx index 9c6a4e5d418a7..9e373949aea12 100644 --- a/x-pack/plugins/uptime/public/components/overview/kuery_bar/kuery_bar.tsx +++ b/x-pack/plugins/uptime/public/components/overview/kuery_bar/kuery_bar.tsx @@ -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'; @@ -94,7 +93,7 @@ export function KueryBar({ setState({ ...state, suggestions: [] }); setSuggestionLimit(15); - const currentRequest = uniqueId(); + const currentRequest = htmlIdGenerator()(); currentRequestCheck = currentRequest; try { @@ -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; } diff --git a/x-pack/plugins/uptime/public/components/overview/monitor_list/monitor_list_drawer/actions_popover/actions_popover.tsx b/x-pack/plugins/uptime/public/components/overview/monitor_list/monitor_list_drawer/actions_popover/actions_popover.tsx index 2070a374e75d0..9e96f0ca76535 100644 --- a/x-pack/plugins/uptime/public/components/overview/monitor_list/monitor_list_drawer/actions_popover/actions_popover.tsx +++ b/x-pack/plugins/uptime/public/components/overview/monitor_list/monitor_list_drawer/actions_popover/actions_popover.tsx @@ -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'; @@ -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 ( diff --git a/x-pack/plugins/uptime/public/components/overview/monitor_list/monitor_list_drawer/actions_popover/integration_group.tsx b/x-pack/plugins/uptime/public/components/overview/monitor_list/monitor_list_drawer/actions_popover/integration_group.tsx index 38aa9287b0c47..ff3b5d67375fe 100644 --- a/x-pack/plugins/uptime/public/components/overview/monitor_list/monitor_list_drawer/actions_popover/integration_group.tsx +++ b/x-pack/plugins/uptime/public/components/overview/monitor_list/monitor_list_drawer/actions_popover/integration_group.tsx @@ -27,9 +27,12 @@ interface IntegrationGroupProps { export const extractSummaryValues = (summary: Pick) => { const domain = summary.state.url?.domain ?? ''; - const podUid = summary.state.summaryPings?.[0]?.kubernetes?.pod?.uid ?? undefined; - const containerId = summary.state.summaryPings?.[0]?.container?.id ?? undefined; - const ip = summary.state.summaryPings?.[0]?.monitor.ip ?? undefined; + + const firstCheck = summary.state.summaryPings?.[0]; + + const podUid = firstCheck?.kubernetes?.pod?.uid ?? undefined; + const containerId = firstCheck?.container?.id ?? undefined; + const ip = firstCheck?.monitor.ip ?? undefined; return { domain, diff --git a/x-pack/plugins/uptime/public/components/overview/monitor_list/monitor_list_drawer/monitor_status_list.tsx b/x-pack/plugins/uptime/public/components/overview/monitor_list/monitor_list_drawer/monitor_status_list.tsx index 334de6e376074..96536a357a450 100644 --- a/x-pack/plugins/uptime/public/components/overview/monitor_list/monitor_list_drawer/monitor_status_list.tsx +++ b/x-pack/plugins/uptime/public/components/overview/monitor_list/monitor_list_drawer/monitor_status_list.tsx @@ -5,7 +5,6 @@ */ import React from 'react'; -import { upperFirst } from 'lodash'; import { EuiCallOut, EuiSpacer } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n/react'; import { LocationLink } from '../../../common/location_link'; @@ -29,9 +28,9 @@ export const MonitorStatusList = ({ summaryPings }: MonitorStatusListProps) => { const location = ping.observer?.geo?.name ?? UNNAMED_LOCATION; if (ping.monitor.status === STATUS.UP) { - upChecks.add(upperFirst(location)); + upChecks.add(location); } else if (ping.monitor.status === STATUS.DOWN) { - downChecks.add(upperFirst(location)); + downChecks.add(location); } }); diff --git a/x-pack/plugins/uptime/public/components/overview/monitor_list/monitor_list_status_column.tsx b/x-pack/plugins/uptime/public/components/overview/monitor_list/monitor_list_status_column.tsx index 68ddf512e4d3c..7140211d18807 100644 --- a/x-pack/plugins/uptime/public/components/overview/monitor_list/monitor_list_status_column.tsx +++ b/x-pack/plugins/uptime/public/components/overview/monitor_list/monitor_list_status_column.tsx @@ -7,7 +7,6 @@ import React from 'react'; import moment from 'moment'; import { i18n } from '@kbn/i18n'; -import { upperFirst } from 'lodash'; import styled from 'styled-components'; import { EuiHealth, EuiFlexGroup, EuiFlexItem, EuiText, EuiToolTip } from '@elastic/eui'; import { parseTimestamp } from './parse_timestamp'; @@ -83,9 +82,9 @@ export const getLocationStatus = (summaryPings: Ping[], status: string) => { const location = summaryPing?.observer?.geo?.name ?? UNNAMED_LOCATION; if (summaryPing.monitor.status === STATUS.UP) { - upPings.add(upperFirst(location)); + upPings.add(location); } else if (summaryPing.monitor.status === STATUS.DOWN) { - downPings.add(upperFirst(location)); + downPings.add(location); } }); diff --git a/x-pack/plugins/uptime/public/contexts/uptime_settings_context.tsx b/x-pack/plugins/uptime/public/contexts/uptime_settings_context.tsx index 142c6e17c5fd9..4c08e76a11aae 100644 --- a/x-pack/plugins/uptime/public/contexts/uptime_settings_context.tsx +++ b/x-pack/plugins/uptime/public/contexts/uptime_settings_context.tsx @@ -5,7 +5,7 @@ */ import React, { createContext, useMemo } from 'react'; -import { UptimeAppProps } from '../uptime_app'; +import { UptimeAppProps } from '../apps/uptime_app'; import { CLIENT_DEFAULTS, CONTEXT_DEFAULTS } from '../../common/constants'; import { CommonlyUsedRange } from '../components/common/uptime_date_picker'; import { useGetUrlParams } from '../hooks'; diff --git a/x-pack/plugins/uptime/public/contexts/uptime_theme_context.tsx b/x-pack/plugins/uptime/public/contexts/uptime_theme_context.tsx index ca2fb50cdbc67..51e8bcaed986f 100644 --- a/x-pack/plugins/uptime/public/contexts/uptime_theme_context.tsx +++ b/x-pack/plugins/uptime/public/contexts/uptime_theme_context.tsx @@ -9,7 +9,7 @@ import React, { createContext, useMemo } from 'react'; import euiDarkVars from '@elastic/eui/dist/eui_theme_dark.json'; import { EUI_CHARTS_THEME_DARK, EUI_CHARTS_THEME_LIGHT } from '@elastic/eui/dist/eui_charts_theme'; import { DARK_THEME, LIGHT_THEME, PartialTheme, Theme } from '@elastic/charts'; -import { UptimeAppColors } from '../uptime_app'; +import { UptimeAppColors } from '../apps/uptime_app'; export interface UptimeThemeContextValues { colors: UptimeAppColors; diff --git a/x-pack/plugins/uptime/public/index.ts b/x-pack/plugins/uptime/public/index.ts index 48cf2c90ad07b..cd6efa9016830 100644 --- a/x-pack/plugins/uptime/public/index.ts +++ b/x-pack/plugins/uptime/public/index.ts @@ -5,7 +5,7 @@ */ import { PluginInitializerContext } from 'kibana/public'; -import { UptimePlugin } from './apps'; +import { UptimePlugin } from './apps/plugin'; export const plugin = (initializerContext: PluginInitializerContext) => new UptimePlugin(initializerContext); diff --git a/x-pack/plugins/uptime/public/lib/alert_types/__tests__/monitor_status.test.ts b/x-pack/plugins/uptime/public/lib/alert_types/__tests__/monitor_status.test.ts index cfcb414f4815d..e999768d4e55d 100644 --- a/x-pack/plugins/uptime/public/lib/alert_types/__tests__/monitor_status.test.ts +++ b/x-pack/plugins/uptime/public/lib/alert_types/__tests__/monitor_status.test.ts @@ -4,7 +4,8 @@ * you may not use this file except in compliance with the Elastic License. */ -import { validate, initMonitorStatusAlertType } from '../monitor_status'; +import { initMonitorStatusAlertType } from '../monitor_status'; +import { validateMonitorStatusParams as validate } from '../lazy_wrapper/validate_monitor_status'; describe('monitor status alert type', () => { describe('validate', () => { @@ -206,19 +207,11 @@ describe('monitor status alert type', () => { ", "iconClass": "uptimeApp", "id": "xpack.uptime.alerts.monitorStatus", - "name": - - , + "name": , "requiresAppContext": false, "validate": [Function], } diff --git a/x-pack/plugins/uptime/public/lib/alert_types/duration_anomaly.tsx b/x-pack/plugins/uptime/public/lib/alert_types/duration_anomaly.tsx index f0eb305461582..c1f802c2d0c91 100644 --- a/x-pack/plugins/uptime/public/lib/alert_types/duration_anomaly.tsx +++ b/x-pack/plugins/uptime/public/lib/alert_types/duration_anomaly.tsx @@ -5,30 +5,22 @@ */ import React from 'react'; -import { Provider as ReduxProvider } from 'react-redux'; import { AlertTypeModel } from '../../../../triggers_actions_ui/public'; -import { CLIENT_ALERT_TYPES } from '../../../common/constants'; +import { CLIENT_ALERT_TYPES } from '../../../common/constants/alerts'; import { DurationAnomalyTranslations } from './translations'; import { AlertTypeInitializer } from '.'; -import { KibanaContextProvider } from '../../../../../../src/plugins/kibana_react/public'; -import { store } from '../../state'; const { name, defaultActionMessage } = DurationAnomalyTranslations; -const AnomalyAlertExpression = React.lazy(() => - import('../../components/overview/alerts/anomaly_alert/anomaly_alert') -); +const DurationAnomalyAlert = React.lazy(() => import('./lazy_wrapper/duration_anomaly')); + export const initDurationAnomalyAlertType: AlertTypeInitializer = ({ core, plugins, }): AlertTypeModel => ({ id: CLIENT_ALERT_TYPES.DURATION_ANOMALY, iconClass: 'uptimeApp', - alertParamsExpression: (params: any) => ( - - - - - + alertParamsExpression: (params: unknown) => ( + ), name, validate: () => ({ errors: {} }), diff --git a/x-pack/plugins/uptime/public/lib/alert_types/lazy_wrapper/duration_anomaly.tsx b/x-pack/plugins/uptime/public/lib/alert_types/lazy_wrapper/duration_anomaly.tsx new file mode 100644 index 0000000000000..60f2d2e803b7b --- /dev/null +++ b/x-pack/plugins/uptime/public/lib/alert_types/lazy_wrapper/duration_anomaly.tsx @@ -0,0 +1,32 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import React from 'react'; +import { Provider as ReduxProvider } from 'react-redux'; +import { CoreStart } from 'kibana/public'; +import { store } from '../../../state'; +import { AnomalyAlertComponent } from '../../../components/overview/alerts/anomaly_alert/anomaly_alert'; +import { KibanaContextProvider } from '../../../../../../../src/plugins/kibana_react/public'; +import { ClientPluginsStart } from '../../../apps/plugin'; +import { kibanaService } from '../../../state/kibana_service'; + +interface Props { + core: CoreStart; + plugins: ClientPluginsStart; + params: any; +} + +// eslint-disable-next-line import/no-default-export +export default function DurationAnomalyAlert({ core, plugins, params }: Props) { + kibanaService.core = core; + return ( + + + + + + ); +} diff --git a/x-pack/plugins/uptime/public/lib/alert_types/lazy_wrapper/monitor_status.tsx b/x-pack/plugins/uptime/public/lib/alert_types/lazy_wrapper/monitor_status.tsx new file mode 100644 index 0000000000000..f6b10d0fbf968 --- /dev/null +++ b/x-pack/plugins/uptime/public/lib/alert_types/lazy_wrapper/monitor_status.tsx @@ -0,0 +1,32 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import React from 'react'; +import { Provider as ReduxProvider } from 'react-redux'; +import { CoreStart } from 'kibana/public'; +import { store } from '../../../state'; +import { KibanaContextProvider } from '../../../../../../../src/plugins/kibana_react/public'; +import { ClientPluginsStart } from '../../../apps/plugin'; +import { AlertMonitorStatus } from '../../../components/overview/alerts/alerts_containers'; +import { kibanaService } from '../../../state/kibana_service'; + +interface Props { + core: CoreStart; + plugins: ClientPluginsStart; + params: any; +} + +// eslint-disable-next-line import/no-default-export +export default function MonitorStatusAlert({ core, plugins, params }: Props) { + kibanaService.core = core; + return ( + + + + + + ); +} diff --git a/x-pack/plugins/uptime/public/lib/alert_types/lazy_wrapper/tls_alert.tsx b/x-pack/plugins/uptime/public/lib/alert_types/lazy_wrapper/tls_alert.tsx new file mode 100644 index 0000000000000..413734b63ced5 --- /dev/null +++ b/x-pack/plugins/uptime/public/lib/alert_types/lazy_wrapper/tls_alert.tsx @@ -0,0 +1,32 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import React from 'react'; +import { Provider as ReduxProvider } from 'react-redux'; +import { CoreStart } from 'kibana/public'; +import { store } from '../../../state'; +import { KibanaContextProvider } from '../../../../../../../src/plugins/kibana_react/public'; +import { ClientPluginsStart } from '../../../apps/plugin'; +import { AlertTls } from '../../../components/overview/alerts/alerts_containers/alert_tls'; +import { kibanaService } from '../../../state/kibana_service'; + +interface Props { + core: CoreStart; + plugins: ClientPluginsStart; + params: any; +} + +// eslint-disable-next-line import/no-default-export +export default function TLSAlert({ core, plugins, params: _params }: Props) { + kibanaService.core = core; + return ( + + + + + + ); +} diff --git a/x-pack/plugins/uptime/public/lib/alert_types/lazy_wrapper/validate_monitor_status.ts b/x-pack/plugins/uptime/public/lib/alert_types/lazy_wrapper/validate_monitor_status.ts new file mode 100644 index 0000000000000..709669c24ed0a --- /dev/null +++ b/x-pack/plugins/uptime/public/lib/alert_types/lazy_wrapper/validate_monitor_status.ts @@ -0,0 +1,56 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { PathReporter } from 'io-ts/lib/PathReporter'; +import { isRight } from 'fp-ts/lib/Either'; +import { + AtomicStatusCheckParamsType, + MonitorAvailabilityType, + StatusCheckParamsType, +} from '../../../../common/runtime_types/alerts'; +import { ValidationResult } from '../../../../../triggers_actions_ui/public'; + +export function validateMonitorStatusParams(alertParams: any): ValidationResult { + const errors: Record = {}; + const decoded = AtomicStatusCheckParamsType.decode(alertParams); + const oldDecoded = StatusCheckParamsType.decode(alertParams); + const availabilityDecoded = MonitorAvailabilityType.decode(alertParams); + + if (!isRight(decoded) && !isRight(oldDecoded) && !isRight(availabilityDecoded)) { + return { + errors: { + typeCheckFailure: 'Provided parameters do not conform to the expected type.', + typeCheckParsingMessage: PathReporter.report(decoded), + }, + }; + } + + if ( + !(alertParams.shouldCheckAvailability ?? false) && + !(alertParams.shouldCheckStatus ?? false) + ) { + return { + errors: { + noAlertSelected: 'Alert must check for monitor status or monitor availability.', + }, + }; + } + + if (isRight(decoded) && decoded.right.shouldCheckStatus) { + const { numTimes, timerangeCount } = decoded.right; + if (numTimes < 1) { + errors.invalidNumTimes = 'Number of alert check down times must be an integer greater than 0'; + } + if (isNaN(timerangeCount)) { + errors.timeRangeStartValueNaN = 'Specified time range value must be a number'; + } + if (timerangeCount <= 0) { + errors.invalidTimeRangeValue = 'Time range value must be greater than 0'; + } + } + + return { errors }; +} diff --git a/x-pack/plugins/uptime/public/lib/alert_types/monitor_status.tsx b/x-pack/plugins/uptime/public/lib/alert_types/monitor_status.tsx index cb24df2357d01..e4da3eb9ef7ae 100644 --- a/x-pack/plugins/uptime/public/lib/alert_types/monitor_status.tsx +++ b/x-pack/plugins/uptime/public/lib/alert_types/monitor_status.tsx @@ -4,70 +4,19 @@ * you may not use this file except in compliance with the Elastic License. */ -import { Provider as ReduxProvider } from 'react-redux'; import React from 'react'; -import { isRight } from 'fp-ts/lib/Either'; -import { PathReporter } from 'io-ts/lib/PathReporter'; -import { AlertTypeModel } from '../../../../triggers_actions_ui/public'; +import { FormattedMessage } from '@kbn/i18n/react'; +import { AlertTypeModel, ValidationResult } from '../../../../triggers_actions_ui/public'; import { AlertTypeInitializer } from '.'; -import { - AtomicStatusCheckParamsType, - StatusCheckParamsType, - MonitorAvailabilityType, -} from '../../../common/runtime_types'; -import { MonitorStatusTitle } from './monitor_status_title'; -import { CLIENT_ALERT_TYPES } from '../../../common/constants'; -import { MonitorStatusTranslations } from './translations'; -import { KibanaContextProvider } from '../../../../../../src/plugins/kibana_react/public'; -import { store } from '../../state'; - -export const validate = (alertParams: any) => { - const errors: Record = {}; - const decoded = AtomicStatusCheckParamsType.decode(alertParams); - const oldDecoded = StatusCheckParamsType.decode(alertParams); - const availabilityDecoded = MonitorAvailabilityType.decode(alertParams); - - if (!isRight(decoded) && !isRight(oldDecoded) && !isRight(availabilityDecoded)) { - return { - errors: { - typeCheckFailure: 'Provided parameters do not conform to the expected type.', - typeCheckParsingMessage: PathReporter.report(decoded), - }, - }; - } - - if ( - !(alertParams.shouldCheckAvailability ?? false) && - !(alertParams.shouldCheckStatus ?? false) - ) { - return { - errors: { - noAlertSelected: 'Alert must check for monitor status or monitor availability.', - }, - }; - } - - if (isRight(decoded) && decoded.right.shouldCheckStatus) { - const { numTimes, timerangeCount } = decoded.right; - if (numTimes < 1) { - errors.invalidNumTimes = 'Number of alert check down times must be an integer greater than 0'; - } - if (isNaN(timerangeCount)) { - errors.timeRangeStartValueNaN = 'Specified time range value must be a number'; - } - if (timerangeCount <= 0) { - errors.invalidTimeRangeValue = 'Time range value must be greater than 0'; - } - } - return { errors }; -}; +import { CLIENT_ALERT_TYPES } from '../../../common/constants/alerts'; +import { MonitorStatusTranslations } from './translations'; const { defaultActionMessage } = MonitorStatusTranslations; -const AlertMonitorStatus = React.lazy(() => - import('../../components/overview/alerts/alerts_containers/alert_monitor_status') -); +const MonitorStatusAlert = React.lazy(() => import('./lazy_wrapper/monitor_status')); + +let validateFunc: (alertParams: any) => ValidationResult; export const initMonitorStatusAlertType: AlertTypeInitializer = ({ core, @@ -75,21 +24,26 @@ export const initMonitorStatusAlertType: AlertTypeInitializer = ({ }): AlertTypeModel => ({ id: CLIENT_ALERT_TYPES.MONITOR_STATUS, name: ( - - - + ), iconClass: 'uptimeApp', - alertParamsExpression: (params: any) => { - return ( - - - - - - ); + alertParamsExpression: (params: any) => ( + + ), + validate: (alertParams: any) => { + if (!validateFunc) { + (async function loadValidate() { + const { validateMonitorStatusParams } = await import( + './lazy_wrapper/validate_monitor_status' + ); + validateFunc = validateMonitorStatusParams; + })(); + } + return validateFunc && validateFunc(alertParams); }, - validate, defaultActionMessage, requiresAppContext: false, }); diff --git a/x-pack/plugins/uptime/public/lib/alert_types/monitor_status_title.tsx b/x-pack/plugins/uptime/public/lib/alert_types/monitor_status_title.tsx deleted file mode 100644 index 1e2751a4ac388..0000000000000 --- a/x-pack/plugins/uptime/public/lib/alert_types/monitor_status_title.tsx +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import React from 'react'; -import { FormattedMessage } from '@kbn/i18n/react'; - -export const MonitorStatusTitle = () => { - return ( - - ); -}; diff --git a/x-pack/plugins/uptime/public/lib/alert_types/tls.tsx b/x-pack/plugins/uptime/public/lib/alert_types/tls.tsx index c541ea4ae1331..9019fc216192c 100644 --- a/x-pack/plugins/uptime/public/lib/alert_types/tls.tsx +++ b/x-pack/plugins/uptime/public/lib/alert_types/tls.tsx @@ -5,27 +5,18 @@ */ import React from 'react'; -import { Provider as ReduxProvider } from 'react-redux'; import { AlertTypeModel } from '../../../../triggers_actions_ui/public'; -import { CLIENT_ALERT_TYPES } from '../../../common/constants'; +import { CLIENT_ALERT_TYPES } from '../../../common/constants/alerts'; import { TlsTranslations } from './translations'; import { AlertTypeInitializer } from '.'; -import { KibanaContextProvider } from '../../../../../../src/plugins/kibana_react/public'; -import { store } from '../../state'; const { name, defaultActionMessage } = TlsTranslations; -const TlsAlertExpression = React.lazy(() => - import('../../components/overview/alerts/alerts_containers/alert_tls') -); +const TLSAlert = React.lazy(() => import('./lazy_wrapper/tls_alert')); export const initTlsAlertType: AlertTypeInitializer = ({ core, plugins }): AlertTypeModel => ({ id: CLIENT_ALERT_TYPES.TLS, iconClass: 'uptimeApp', - alertParamsExpression: (_params: any) => ( - - - - - + alertParamsExpression: (params: any) => ( + ), name, validate: () => ({ errors: {} }), diff --git a/x-pack/plugins/uptime/public/lib/helper/observability_integration/build_href.ts b/x-pack/plugins/uptime/public/lib/helper/observability_integration/build_href.ts index 94383262b0acd..8c96a469da492 100644 --- a/x-pack/plugins/uptime/public/lib/helper/observability_integration/build_href.ts +++ b/x-pack/plugins/uptime/public/lib/helper/observability_integration/build_href.ts @@ -4,24 +4,23 @@ * you may not use this file except in compliance with the Elastic License. */ -import { get } from 'lodash'; import { Ping } from '../../../../common/runtime_types'; /** * Builds URLs to the designated features by extracting values from the provided * monitor object on a given path. Then returns the result of a provided function * to place the value in its rightful place on the URI string. - * @param checks array of summary checks containing the data to extract - * @param path the location on the object of the desired data + * @param summaryPings array of summary checks containing the data to extract + * @param getData the location on the object of the desired data * @param getHref a function that returns the full URL */ export const buildHref = ( summaryPings: Ping[], - path: string, + getData: (ping: Ping) => string | undefined, getHref: (value: string | string[] | undefined) => string | undefined ): string | undefined => { const queryValue = summaryPings - .map((ping) => get(ping, path, undefined)) + .map((ping) => getData(ping)) .filter((value: string | undefined) => value !== undefined); if (queryValue.length === 0) { return getHref(undefined); diff --git a/x-pack/plugins/uptime/public/lib/helper/observability_integration/get_apm_href.ts b/x-pack/plugins/uptime/public/lib/helper/observability_integration/get_apm_href.ts index 0ff5a8acb3367..a1d69950cb61a 100644 --- a/x-pack/plugins/uptime/public/lib/helper/observability_integration/get_apm_href.ts +++ b/x-pack/plugins/uptime/public/lib/helper/observability_integration/get_apm_href.ts @@ -4,7 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ -import { get } from 'lodash'; import { addBasePath } from './add_base_path'; import { MonitorSummary } from '../../../../common/runtime_types'; @@ -17,6 +16,6 @@ export const getApmHref = ( addBasePath( basePath, `/app/apm#/services?kuery=${encodeURI( - `url.domain: "${get(summary, 'state.url.domain')}"` + `url.domain: "${summary?.state?.url?.domain}"` )}&rangeFrom=${dateRangeStart}&rangeTo=${dateRangeEnd}` ); diff --git a/x-pack/plugins/uptime/public/lib/helper/observability_integration/get_infra_href.ts b/x-pack/plugins/uptime/public/lib/helper/observability_integration/get_infra_href.ts index 33d24a0f081b4..c225382350eac 100644 --- a/x-pack/plugins/uptime/public/lib/helper/observability_integration/get_infra_href.ts +++ b/x-pack/plugins/uptime/public/lib/helper/observability_integration/get_infra_href.ts @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { MonitorSummary } from '../../../../common/runtime_types'; +import { MonitorSummary, Ping } from '../../../../common/runtime_types'; import { addBasePath } from './add_base_path'; import { buildHref } from './build_href'; @@ -22,7 +22,7 @@ export const getInfraContainerHref = ( `/app/metrics/link-to/container-detail/${encodeURIComponent(ret)}` ); }; - return buildHref(summary.state.summaryPings || [], 'container.id', getHref); + return buildHref(summary.state.summaryPings || [], (ping: Ping) => ping?.container?.id, getHref); }; export const getInfraKubernetesHref = ( @@ -37,7 +37,11 @@ export const getInfraKubernetesHref = ( return addBasePath(basePath, `/app/metrics/link-to/pod-detail/${encodeURIComponent(ret)}`); }; - return buildHref(summary.state.summaryPings || [], 'kubernetes.pod.uid', getHref); + return buildHref( + summary.state.summaryPings || [], + (ping: Ping) => ping?.kubernetes?.pod?.uid, + getHref + ); }; export const getInfraIpHref = (summary: MonitorSummary, basePath: string) => { @@ -63,5 +67,5 @@ export const getInfraIpHref = (summary: MonitorSummary, basePath: string) => { `/app/metrics/inventory?waffleFilter=(expression:'${encodeURIComponent(ips)}',kind:kuery)` ); }; - return buildHref(summary.state.summaryPings || [], 'monitor.ip', getHref); + return buildHref(summary.state.summaryPings || [], (ping: Ping) => ping?.monitor?.ip, getHref); }; diff --git a/x-pack/plugins/uptime/public/lib/helper/observability_integration/get_logging_href.ts b/x-pack/plugins/uptime/public/lib/helper/observability_integration/get_logging_href.ts index c4fee330e9763..32709882d1d21 100644 --- a/x-pack/plugins/uptime/public/lib/helper/observability_integration/get_logging_href.ts +++ b/x-pack/plugins/uptime/public/lib/helper/observability_integration/get_logging_href.ts @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { MonitorSummary } from '../../../../common/runtime_types'; +import { MonitorSummary, Ping } from '../../../../common/runtime_types'; import { addBasePath } from './add_base_path'; import { buildHref } from './build_href'; @@ -22,7 +22,7 @@ export const getLoggingContainerHref = ( `/app/logs?logFilter=${encodeURI(`(expression:'container.id : ${ret}',kind:kuery)`)}` ); }; - return buildHref(summary.state.summaryPings || [], 'container.id', getHref); + return buildHref(summary.state.summaryPings || [], (ping: Ping) => ping?.container?.id, getHref); }; export const getLoggingKubernetesHref = (summary: MonitorSummary, basePath: string) => { @@ -36,7 +36,11 @@ export const getLoggingKubernetesHref = (summary: MonitorSummary, basePath: stri `/app/logs?logFilter=${encodeURI(`(expression:'pod.uid : ${ret}',kind:kuery)`)}` ); }; - return buildHref(summary.state.summaryPings || [], 'kubernetes.pod.uid', getHref); + return buildHref( + summary.state.summaryPings || [], + (ping: Ping) => ping?.kubernetes?.pod?.uid, + getHref + ); }; export const getLoggingIpHref = (summary: MonitorSummary, basePath: string) => { @@ -50,5 +54,5 @@ export const getLoggingIpHref = (summary: MonitorSummary, basePath: string) => { `/app/logs?logFilter=(expression:'${encodeURIComponent(`host.ip : ${ret}`)}',kind:kuery)` ); }; - return buildHref(summary.state.summaryPings || [], 'monitor.ip', getHref); + return buildHref(summary.state.summaryPings || [], (ping: Ping) => ping?.monitor?.ip, getHref); }; diff --git a/x-pack/plugins/uptime/public/lib/lib.ts b/x-pack/plugins/uptime/public/lib/lib.ts index 187dcee7adb1a..ac95f018a80a2 100644 --- a/x-pack/plugins/uptime/public/lib/lib.ts +++ b/x-pack/plugins/uptime/public/lib/lib.ts @@ -4,19 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ -import { ReactElement } from 'react'; -import { AppUnmount } from 'kibana/public'; import { UMBadge } from '../badge'; -import { UptimeAppProps } from '../uptime_app'; - -export interface UMFrontendLibs { - framework: UMFrameworkAdapter; -} export type UMUpdateBadge = (badge: UMBadge) => void; - -export type BootstrapUptimeApp = (props: UptimeAppProps) => ReactElement; - -export interface UMFrameworkAdapter { - render(element: any): Promise; -} diff --git a/x-pack/plugins/uptime/public/pages/certificates.tsx b/x-pack/plugins/uptime/public/pages/certificates.tsx index 58a56a5555323..e46d228c6d21f 100644 --- a/x-pack/plugins/uptime/public/pages/certificates.tsx +++ b/x-pack/plugins/uptime/public/pages/certificates.tsx @@ -21,13 +21,14 @@ import { FormattedMessage } from '@kbn/i18n/react'; import { useTrackPageview } from '../../../observability/public'; import { PageHeader } from './page_header'; import { useBreadcrumbs } from '../hooks/use_breadcrumbs'; -import { OVERVIEW_ROUTE, SETTINGS_ROUTE, CLIENT_ALERT_TYPES } from '../../common/constants'; +import { OVERVIEW_ROUTE, SETTINGS_ROUTE } from '../../common/constants'; import { getDynamicSettings } from '../state/actions/dynamic_settings'; import { UptimeRefreshContext } from '../contexts'; import * as labels from './translations'; import { certificatesSelector, getCertificatesAction } from '../state/certificates/certificates'; import { CertificateList, CertificateSearch, CertSort } from '../components/certificates'; import { ToggleAlertFlyoutButton } from '../components/overview/alerts/alerts_containers'; +import { CLIENT_ALERT_TYPES } from '../../common/constants/alerts'; const DEFAULT_PAGE_SIZE = 10; const LOCAL_STORAGE_KEY = 'xpack.uptime.certList.pageSize'; diff --git a/x-pack/plugins/uptime/public/pages/settings.tsx b/x-pack/plugins/uptime/public/pages/settings.tsx index 602911cd41aab..89c12d0efdac1 100644 --- a/x-pack/plugins/uptime/public/pages/settings.tsx +++ b/x-pack/plugins/uptime/public/pages/settings.tsx @@ -17,7 +17,6 @@ import { } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n/react'; import { useDispatch, useSelector } from 'react-redux'; -import { isEqual } from 'lodash'; import { useHistory } from 'react-router-dom'; import { selectDynamicSettings } from '../state/selectors'; import { getDynamicSettings, setDynamicSettings } from '../state/actions/dynamic_settings'; @@ -80,6 +79,14 @@ const getFieldErrors = (formFields: DynamicSettings | null): SettingsPageFieldEr return null; }; +const isDirtyForm = (formFields: DynamicSettings | null, settings?: DynamicSettings) => { + return ( + settings?.certAgeThreshold !== formFields?.certAgeThreshold || + settings?.certExpirationThreshold !== formFields?.certExpirationThreshold || + settings?.heartbeatIndices !== formFields?.heartbeatIndices + ); +}; + export const SettingsPage: React.FC = () => { const dss = useSelector(selectDynamicSettings); @@ -121,7 +128,8 @@ export const SettingsPage: React.FC = () => { const resetForm = () => setFormFields(dss.settings ? { ...dss.settings } : null); - const isFormDirty = !isEqual(dss.settings, formFields); + const isFormDirty = isDirtyForm(formFields, dss.settings); + const canEdit: boolean = !!useKibana().services?.application?.capabilities.uptime.configureSettings || false; const isFormDisabled = dss.loading || !canEdit; diff --git a/x-pack/plugins/uptime/public/state/api/utils.ts b/x-pack/plugins/uptime/public/state/api/utils.ts index 4f3765275c49a..e0cec56dd52cd 100644 --- a/x-pack/plugins/uptime/public/state/api/utils.ts +++ b/x-pack/plugins/uptime/public/state/api/utils.ts @@ -8,7 +8,11 @@ import { PathReporter } from 'io-ts/lib/PathReporter'; import { isRight } from 'fp-ts/lib/Either'; import { HttpFetchQuery, HttpSetup } from 'src/core/public'; import * as t from 'io-ts'; -import { isObject } from 'lodash'; + +function isObject(value: unknown) { + const type = typeof value; + return value != null && (type === 'object' || type === 'function'); +} // TODO: Copied from https://github.com/elastic/kibana/blob/master/x-pack/plugins/security_solution/common/format_errors.ts // We should figure out a better way to share this diff --git a/x-pack/plugins/uptime/public/state/effects/index_status.ts b/x-pack/plugins/uptime/public/state/effects/index_status.ts index a4b85312849a2..3917159381eb5 100644 --- a/x-pack/plugins/uptime/public/state/effects/index_status.ts +++ b/x-pack/plugins/uptime/public/state/effects/index_status.ts @@ -6,8 +6,8 @@ import { takeLeading } from 'redux-saga/effects'; import { indexStatusAction } from '../actions'; -import { fetchIndexStatus } from '../api'; import { fetchEffectFactory } from './fetch_effect'; +import { fetchIndexStatus } from '../api/index_status'; export function* fetchIndexStatusEffect() { yield takeLeading( diff --git a/x-pack/plugins/uptime/server/kibana.index.ts b/x-pack/plugins/uptime/server/kibana.index.ts index 2bf0d84a49de1..ab8d7a068b19d 100644 --- a/x-pack/plugins/uptime/server/kibana.index.ts +++ b/x-pack/plugins/uptime/server/kibana.index.ts @@ -5,7 +5,7 @@ */ import { Request, Server } from 'hapi'; -import { PLUGIN } from '../common/constants'; +import { PLUGIN } from '../common/constants/plugin'; import { compose } from './lib/compose/kibana'; import { initUptimeServer } from './uptime_server'; import { UptimeCorePlugins, UptimeCoreSetup } from './lib/adapters/framework'; diff --git a/x-pack/plugins/uptime/server/lib/alerts/duration_anomaly.ts b/x-pack/plugins/uptime/server/lib/alerts/duration_anomaly.ts index 7dd357e99b83d..a71913d0eea9a 100644 --- a/x-pack/plugins/uptime/server/lib/alerts/duration_anomaly.ts +++ b/x-pack/plugins/uptime/server/lib/alerts/duration_anomaly.ts @@ -8,7 +8,7 @@ import moment from 'moment'; import { schema } from '@kbn/config-schema'; import { ILegacyScopedClusterClient } from 'kibana/server'; import { updateState } from './common'; -import { ACTION_GROUP_DEFINITIONS } from '../../../common/constants'; +import { ACTION_GROUP_DEFINITIONS } from '../../../common/constants/alerts'; import { commonStateTranslations, durationAnomalyTranslations } from './translations'; import { AnomaliesTableRecord } from '../../../../ml/common/types/anomalies'; import { getSeverityType } from '../../../../ml/common/util/anomaly_utils'; diff --git a/x-pack/plugins/uptime/server/lib/alerts/status_check.ts b/x-pack/plugins/uptime/server/lib/alerts/status_check.ts index 2117ac4b7ed4e..a34d7eb292eef 100644 --- a/x-pack/plugins/uptime/server/lib/alerts/status_check.ts +++ b/x-pack/plugins/uptime/server/lib/alerts/status_check.ts @@ -21,7 +21,7 @@ import { MonitorAvailabilityType, DynamicSettings, } from '../../../common/runtime_types'; -import { ACTION_GROUP_DEFINITIONS } from '../../../common/constants'; +import { ACTION_GROUP_DEFINITIONS } from '../../../common/constants/alerts'; import { savedObjectsAdapter } from '../saved_objects'; import { updateState } from './common'; import { commonStateTranslations } from './translations'; diff --git a/x-pack/plugins/uptime/server/lib/alerts/tls.ts b/x-pack/plugins/uptime/server/lib/alerts/tls.ts index 61e738b088d50..d4853ad7a9cb0 100644 --- a/x-pack/plugins/uptime/server/lib/alerts/tls.ts +++ b/x-pack/plugins/uptime/server/lib/alerts/tls.ts @@ -9,7 +9,8 @@ import { schema } from '@kbn/config-schema'; import { UptimeAlertTypeFactory } from './types'; import { savedObjectsAdapter } from '../saved_objects'; import { updateState } from './common'; -import { ACTION_GROUP_DEFINITIONS, DYNAMIC_SETTINGS_DEFAULTS } from '../../../common/constants'; +import { ACTION_GROUP_DEFINITIONS } from '../../../common/constants/alerts'; +import { DYNAMIC_SETTINGS_DEFAULTS } from '../../../common/constants'; import { Cert, CertResult } from '../../../common/runtime_types'; import { commonStateTranslations, tlsTranslations } from './translations'; import { DEFAULT_FROM, DEFAULT_TO } from '../../rest_api/certs/certs';