diff --git a/x-pack/plugins/triggers_actions_ui/public/index.ts b/x-pack/plugins/triggers_actions_ui/public/index.ts index 55653f49001b9..5bcc7f20ce59c 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, } from './types'; export { ConnectorAddFlyout, 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 b6fd2a1b354e0..cf750434ab324 100644 --- a/x-pack/plugins/uptime/public/apps/plugin.ts +++ b/x-pack/plugins/uptime/public/apps/plugin.ts @@ -12,9 +12,11 @@ import { AppMountParameters, } from 'kibana/public'; import { DEFAULT_APP_CATEGORIES } from '../../../../../src/core/public'; -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, @@ -25,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; @@ -65,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({ @@ -93,7 +102,6 @@ export class UptimePlugin } 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/apps/render_app.tsx b/x-pack/plugins/uptime/public/apps/render_app.tsx index fb45bed8fe639..f834f8b5cdd3c 100644 --- a/x-pack/plugins/uptime/public/apps/render_app.tsx +++ b/x-pack/plugins/uptime/public/apps/render_app.tsx @@ -13,10 +13,10 @@ import { DEFAULT_DARK_MODE, DEFAULT_TIMEPICKER_QUICK_RANGES, INTEGRATED_SOLUTIONS, - PLUGIN, } from '../../common/constants'; -import { UptimeApp, UptimeAppProps } from '../uptime_app'; +import { UptimeApp, UptimeAppProps } from './uptime_app'; import { ClientPluginsSetup, ClientPluginsStart } from './plugin'; +import { PLUGIN } from '../../common/constants/plugin'; export function renderApp( core: CoreStart, 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 5c3674761af84..6049c514bce33 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 { EuiButtonEmpty, 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 f516c225553aa..bbbda01c12f0a 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 { EuiCallOut } from '@elastic/eui'; -import { htmlIdGenerator } from '@elastic/eui/lib/services'; +import { EuiCallOut, htmlIdGenerator } from '@elastic/eui'; import styled from 'styled-components'; import { FormattedMessage } from '@kbn/i18n/react'; import { Typeahead } from './typeahead'; 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 8c261df739855..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 @@ -10,17 +10,17 @@ 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) => ping?.path) + .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_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/pages/certificates.tsx b/x-pack/plugins/uptime/public/pages/certificates.tsx index 673cfa00abb11..3d77d18af695b 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/state/api/utils.ts b/x-pack/plugins/uptime/public/state/api/utils.ts index cf5eacb9d9b50..e0cec56dd52cd 100644 --- a/x-pack/plugins/uptime/public/state/api/utils.ts +++ b/x-pack/plugins/uptime/public/state/api/utils.ts @@ -9,7 +9,7 @@ import { isRight } from 'fp-ts/lib/Either'; import { HttpFetchQuery, HttpSetup } from 'src/core/public'; import * as t from 'io-ts'; -function isObject(value) { +function isObject(value: unknown) { const type = typeof value; return value != null && (type === 'object' || type === 'function'); } 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/public/state/kibana_service.ts b/x-pack/plugins/uptime/public/state/kibana_service.ts index f1eb3af9da667..e88345e6da3cf 100644 --- a/x-pack/plugins/uptime/public/state/kibana_service.ts +++ b/x-pack/plugins/uptime/public/state/kibana_service.ts @@ -7,7 +7,7 @@ import { CoreStart } from 'kibana/public'; import { apiService } from './api/utils'; -class KibanaService { +export class KibanaService { private static instance: KibanaService; private _core!: CoreStart; diff --git a/x-pack/plugins/uptime/server/kibana.index.ts b/x-pack/plugins/uptime/server/kibana.index.ts index d68bbabe82b86..3d824ffa4f56c 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';