diff --git a/src/core/server/integration_tests/saved_objects/migrations/check_registered_types.test.ts b/src/core/server/integration_tests/saved_objects/migrations/check_registered_types.test.ts index 9d7c1463620e7d..057dd9973bb234 100644 --- a/src/core/server/integration_tests/saved_objects/migrations/check_registered_types.test.ts +++ b/src/core/server/integration_tests/saved_objects/migrations/check_registered_types.test.ts @@ -132,7 +132,7 @@ describe('checking migration metadata changes on all registered SO types', () => "siem-ui-timeline-pinned-event": "e2697b38751506c7fce6e8b7207a830483dc4283", "space": "c4a0acce1bd4b9cce85154f2a350624a53111c59", "spaces-usage-stats": "922d3235bbf519e3fb3b260e27248b1df8249b79", - "synthetics-monitor": "111811218f7e34f40980665a4eb99976f457bb23", + "synthetics-monitor": "d784b64a3def47d3f3d1f367df71ae41ef33cb3c", "synthetics-privates-locations": "dd00385f4a27ef062c3e57312eeb3799872fa4af", "tag": "39413f4578cc2128c9a0fda97d0acd1c8862c47a", "task": "ef53d0f070bd54957b8fe22fae3b1ff208913f76", diff --git a/x-pack/plugins/synthetics/common/runtime_types/monitor_management/monitor_types.ts b/x-pack/plugins/synthetics/common/runtime_types/monitor_management/monitor_types.ts index f05729e29b49c1..1f3c6c7a315475 100644 --- a/x-pack/plugins/synthetics/common/runtime_types/monitor_management/monitor_types.ts +++ b/x-pack/plugins/synthetics/common/runtime_types/monitor_management/monitor_types.ts @@ -391,6 +391,7 @@ export type MonitorManagementListResult = t.TypeOf { await page.waitForSelector(`[data-test-subj="syntheticsOverviewGridItem"]`); await page.click('[data-test-subj="syntheticsOverviewSortButton"]'); await page.click('button:has-text("Z -> A")'); - await page.waitForSelector('text=Loading'); await page.waitForSelector(`text=${testMonitor1}`); await page.waitForSelector(`text=${testMonitor2}`); await page.waitForSelector(`text=${testMonitor3}`); @@ -85,7 +84,6 @@ journey('Overview Sorting', async ({ page, params }) => { await page.waitForSelector(`[data-test-subj="syntheticsOverviewGridItem"]`); await page.click('[data-test-subj="syntheticsOverviewSortButton"]'); await page.click('button:has-text("Last modified")'); - await page.waitForSelector('text=Loading'); await page.waitForSelector(`text=${testMonitor1}`); await page.waitForSelector(`text=${testMonitor2}`); await page.waitForSelector(`text=${testMonitor3}`); @@ -99,14 +97,12 @@ journey('Overview Sorting', async ({ page, params }) => { expect(await correctFirstMonitor.count()).toBe(1); expect(await correctSecondMonitor.count()).toBe(1); expect(await correctThirdMonitor.count()).toBe(1); - await page.waitForTimeout(30000); }); step('sort last updated desc', async () => { await page.waitForSelector(`[data-test-subj="syntheticsOverviewGridItem"]`); await page.click('[data-test-subj="syntheticsOverviewSortButton"]'); await page.click('button:has-text("Oldest first")'); - await page.waitForSelector('text=Loading'); await page.waitForSelector(`text=${testMonitor1}`); await page.waitForSelector(`text=${testMonitor2}`); await page.waitForSelector(`text=${testMonitor3}`); @@ -120,7 +116,6 @@ journey('Overview Sorting', async ({ page, params }) => { expect(await correctFirstMonitor.count()).toBe(1); expect(await correctSecondMonitor.count()).toBe(1); expect(await correctThirdMonitor.count()).toBe(1); - await page.waitForTimeout(30000); }); step('delete monitors', async () => { diff --git a/x-pack/plugins/synthetics/public/apps/locators/edit_monitor.ts b/x-pack/plugins/synthetics/public/apps/locators/edit_monitor.ts index 81139421817e9b..edc05addd6633b 100644 --- a/x-pack/plugins/synthetics/public/apps/locators/edit_monitor.ts +++ b/x-pack/plugins/synthetics/public/apps/locators/edit_monitor.ts @@ -7,10 +7,10 @@ import { syntheticsEditMonitorLocatorID } from '@kbn/observability-plugin/common'; -async function navigate({ monitorId }: { monitorId: string }) { +async function navigate({ configId }: { configId: string }) { return { app: 'synthetics', - path: `/edit-monitor/${monitorId}`, + path: `/edit-monitor/${configId}`, state: {}, }; } diff --git a/x-pack/plugins/synthetics/public/apps/locators/monitor_detail.ts b/x-pack/plugins/synthetics/public/apps/locators/monitor_detail.ts index f3633583567544..de26b30e220224 100644 --- a/x-pack/plugins/synthetics/public/apps/locators/monitor_detail.ts +++ b/x-pack/plugins/synthetics/public/apps/locators/monitor_detail.ts @@ -7,11 +7,11 @@ import { syntheticsMonitorDetailLocatorID } from '@kbn/observability-plugin/common'; -async function navigate({ monitorId, locationId }: { monitorId: string; locationId?: string }) { +async function navigate({ configId, locationId }: { configId: string; locationId?: string }) { const locationUrlQueryParam = locationId ? `?locationId=${locationId}` : ''; return { app: 'synthetics', - path: `/monitor/${monitorId}${locationUrlQueryParam}`, + path: `/monitor/${configId}${locationUrlQueryParam}`, state: {}, }; } diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/monitor_summary/monitor_details_panel.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/monitor_summary/monitor_details_panel.tsx index c5e39ca9b5fce6..bfe3f499389871 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/monitor_summary/monitor_details_panel.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/monitor_summary/monitor_details_panel.tsx @@ -36,15 +36,15 @@ export const MonitorDetailsPanel = () => { const { euiTheme } = useEuiTheme(); const { latestPing } = useMonitorLatestPing(); - const { monitorId } = useParams<{ monitorId: string }>(); + const { monitorId: configId } = useParams<{ monitorId: string }>(); const dispatch = useDispatch(); const { monitor, loading } = useSelectedMonitor(); if ( - (latestPing && latestPing?.config_id !== monitorId) || - (monitor && monitor[ConfigKey.CONFIG_ID] !== monitorId) + (latestPing && latestPing?.config_id !== configId) || + (monitor && monitor[ConfigKey.CONFIG_ID] !== configId) ) { return ; } @@ -69,10 +69,10 @@ export const MonitorDetailsPanel = () => { {monitor && ( { - dispatch(getMonitorAction.get({ monitorId })); + dispatch(getMonitorAction.get({ monitorId: configId })); }} /> )} diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitors_page/hooks/use_edit_monitor_locator.ts b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitors_page/hooks/use_edit_monitor_locator.ts index fde26d1935f779..bb531a1dbe9beb 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitors_page/hooks/use_edit_monitor_locator.ts +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitors_page/hooks/use_edit_monitor_locator.ts @@ -10,7 +10,7 @@ import { useEffect, useState } from 'react'; import { syntheticsEditMonitorLocatorID } from '@kbn/observability-plugin/common'; import { useSyntheticsStartPlugins } from '../../../contexts'; -export function useEditMonitorLocator({ monitorId }: { monitorId: string }) { +export function useEditMonitorLocator({ configId }: { configId: string }) { const [editUrl, setEditUrl] = useState(undefined); const locator = useSyntheticsStartPlugins()?.share?.url.locators.get( syntheticsEditMonitorLocatorID @@ -19,12 +19,12 @@ export function useEditMonitorLocator({ monitorId }: { monitorId: string }) { useEffect(() => { async function generateUrl() { const url = await locator?.getUrl({ - monitorId, + configId, }); setEditUrl(url); } generateUrl(); - }, [locator, monitorId]); + }, [locator, configId]); return editUrl; } diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitors_page/hooks/use_monitor_detail_locator.ts b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitors_page/hooks/use_monitor_detail_locator.ts index fc526f26b885a5..d1b75ef5e0ca36 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitors_page/hooks/use_monitor_detail_locator.ts +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitors_page/hooks/use_monitor_detail_locator.ts @@ -10,10 +10,10 @@ import { syntheticsMonitorDetailLocatorID } from '@kbn/observability-plugin/comm import { useSyntheticsStartPlugins } from '../../../contexts'; export function useMonitorDetailLocator({ - monitorId, + configId, locationId, }: { - monitorId: string; + configId: string; locationId?: string; }) { const [monitorUrl, setMonitorUrl] = useState(undefined); @@ -24,13 +24,13 @@ export function useMonitorDetailLocator({ useEffect(() => { async function generateUrl() { const url = await locator?.getUrl({ - monitorId, + configId, locationId, }); setMonitorUrl(url); } generateUrl(); - }, [locator, monitorId, locationId]); + }, [locator, configId, locationId]); return monitorUrl; } diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitors_page/management/monitor_list_table/columns.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitors_page/management/monitor_list_table/columns.tsx index 9ac01508447d51..ad62c16c1ff694 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitors_page/management/monitor_list_table/columns.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitors_page/management/monitor_list_table/columns.tsx @@ -137,7 +137,7 @@ export function getMonitorListColumns({ }), render: (_enabled: boolean, monitor: EncryptedSyntheticsSavedMonitor) => ( void; initialLoading?: boolean; @@ -23,7 +23,7 @@ interface Props { } export const MonitorEnabled = ({ - id, + configId, monitor, reloadPage, initialLoading = false, @@ -41,7 +41,7 @@ export const MonitorEnabled = ({ }, [monitorName]); const { isEnabled, updateMonitorEnabledState, status } = useMonitorEnableHandler({ - id, + configId, isEnabled: monitor[ConfigKey.ENABLED], reloadPage, labels: statusLabels, diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitors_page/overview/overview/actions_popover.test.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitors_page/overview/overview/actions_popover.test.tsx index cad8a173a1ba59..29147eca0b6021 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitors_page/overview/overview/actions_popover.test.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitors_page/overview/overview/actions_popover.test.tsx @@ -27,6 +27,7 @@ describe('ActionsPopover', () => { isEnabled: true, name: 'Monitor 1', id: 'somelongstring', + configId: '1lkjelre', }; }); diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitors_page/overview/overview/actions_popover.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitors_page/overview/overview/actions_popover.tsx index 6433f1ac5cb0c2..e097096d4960d3 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitors_page/overview/overview/actions_popover.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitors_page/overview/overview/actions_popover.tsx @@ -87,10 +87,10 @@ export function ActionsPopover({ const locationName = useLocationName({ locationId: monitor.location.id }); const detailUrl = useMonitorDetailLocator({ - monitorId: monitor.id, + configId: monitor.configId, locationId: monitor.location.id, }); - const editUrl = useEditMonitorLocator({ monitorId: monitor.id }); + const editUrl = useEditMonitorLocator({ configId: monitor.configId }); const labels = useMemo( () => ({ @@ -101,7 +101,7 @@ export function ActionsPopover({ [monitor.name] ); const { status, isEnabled, updateMonitorEnabledState } = useMonitorEnableHandler({ - id: monitor.id, + configId: monitor.configId, isEnabled: monitor.isEnabled, labels, }); @@ -125,7 +125,9 @@ export function ActionsPopover({ disabled: !locationName, onClick: () => { if (locationName) { - dispatch(setFlyoutConfig({ monitorId: monitor.id, location: locationName })); + dispatch( + setFlyoutConfig({ configId: monitor.configId, location: locationName, id: monitor.id }) + ); setIsPopoverOpen(false); } }, diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitors_page/overview/overview/metric_item.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitors_page/overview/overview/metric_item.tsx index 0b3c1cf7012780..fc981113d94d03 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitors_page/overview/overview/metric_item.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitors_page/overview/overview/metric_item.tsx @@ -36,12 +36,12 @@ export const MetricItem = ({ data: Array<{ x: number; y: number }>; averageDuration: number; loaded: boolean; - onClick: (id: string, location: string) => void; + onClick: (params: { id: string; configId: string; location: string }) => void; }) => { const [isMouseOver, setIsMouseOver] = useState(false); const [isPopoverOpen, setIsPopoverOpen] = useState(false); const locationName = useLocationName({ locationId: monitor.location?.id }); - const { locations } = useStatusByLocation(monitor.id); + const { locations } = useStatusByLocation(monitor.configId); const ping = locations.find((loc) => loc.observer?.geo?.name === locationName); const theme = useTheme(); @@ -67,11 +67,15 @@ export const MetricItem = ({ > monitor.id && locationName && onClick(monitor.id, locationName)} + onElementClick={() => + monitor.configId && + locationName && + onClick({ configId: monitor.configId, id: monitor.id, location: locationName }) + } baseTheme={DARK_THEME} /> { const onCloseMock = jest.fn(); const { getByLabelText } = render( { const { getByText } = render( { const { getByRole } = render( { const { getByRole, getByText, getAllByRole } = render( void; onEnabledChange: () => void; - onLocationChange: (id: string, location: string) => void; + onLocationChange: (params: { configId: string; id: string; location: string }) => void; currentDurationChartFrom?: string; currentDurationChartTo?: string; previousDurationChartFrom?: string; @@ -162,14 +163,14 @@ function DetailFlyoutDurationChart({ function LocationSelect({ locations, currentLocation, - id, + configId, setCurrentLocation, monitor, onEnabledChange, }: { locations: ReturnType['locations']; currentLocation: string; - id: string; + configId: string; monitor: EncryptedSyntheticsMonitor; onEnabledChange: () => void; setCurrentLocation: (location: string) => void; @@ -235,7 +236,7 @@ function LocationSelect({ {ENABLED_ITEM_TEXT} - + @@ -254,7 +255,7 @@ function LoadingState() { } export function MonitorDetailFlyout(props: Props) { - const { id, onLocationChange } = props; + const { id, configId, onLocationChange } = props; const { data: { monitors }, } = useSelector(selectOverviewState); @@ -265,12 +266,12 @@ export function MonitorDetailFlyout(props: Props) { }, [id, monitors]); const setLocation = useCallback( - (location: string) => onLocationChange(id, location), - [id, onLocationChange] + (location: string) => onLocationChange({ id, configId, location }), + [id, configId, onLocationChange] ); const detailLink = useMonitorDetailLocator({ - monitorId: id, + configId: id, }); const { @@ -278,14 +279,14 @@ export function MonitorDetailFlyout(props: Props) { error, status, }: FetcherResult> = useFetcher( - () => fetchSyntheticsMonitor(id), - [id] + () => fetchSyntheticsMonitor(configId), + [configId] ); const [isActionsPopoverOpen, setIsActionsPopoverOpen] = useState(false); - const monitorDetail = useMonitorDetail(id, props.location); - const locationStatuses = useStatusByLocation(id); + const monitorDetail = useMonitorDetail(configId, props.location); + const locationStatuses = useStatusByLocation(configId); const locations = locationStatuses.locations?.filter((l: any) => !!l?.observer?.geo?.name) ?? []; const isOverlay = useIsWithinMaxBreakpoint('xl'); @@ -328,7 +329,7 @@ export function MonitorDetailFlyout(props: Props) { currentLocation={props.location} locations={locations} setCurrentLocation={setLocation} - id={id} + configId={configId} monitor={monitorSavedObject.attributes} onEnabledChange={props.onEnabledChange} /> diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitors_page/overview/overview/overview_grid.test.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitors_page/overview/overview/overview_grid.test.tsx index 64178aa9aa1466..c9fbc00b8e590d 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitors_page/overview/overview/overview_grid.test.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitors_page/overview/overview/overview_grid.test.tsx @@ -18,6 +18,7 @@ describe('Overview Grid', () => { for (let i = 0; i < 20; i++) { data.push({ id: `${i}`, + configId: `${i}`, location: { id: 'us_central', isServiceManaged: true, @@ -27,6 +28,7 @@ describe('Overview Grid', () => { }); data.push({ id: `${i}`, + configId: `${i}`, location: { id: 'us_east', isServiceManaged: true, diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitors_page/overview/overview/overview_grid.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitors_page/overview/overview/overview_grid.tsx index 649cb1048af35c..18cb013c8b14b5 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitors_page/overview/overview/overview_grid.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitors_page/overview/overview/overview_grid.tsx @@ -58,7 +58,8 @@ export const OverviewGrid = memo(() => { const dispatch = useDispatch(); const setFlyoutConfigCallback = useCallback( - (monitorId: string, location: string) => dispatch(setFlyoutConfig({ monitorId, location })), + ({ configId, id, location }: { configId: string; id: string; location: string }) => + dispatch(setFlyoutConfig({ configId, id, location })), [dispatch] ); const hideFlyout = useCallback(() => dispatch(setFlyoutConfig(null)), [dispatch]); @@ -153,9 +154,10 @@ export const OverviewGrid = memo(() => { )} - {flyoutConfig?.monitorId && flyoutConfig?.location && ( + {flyoutConfig?.configId && flyoutConfig?.location && ( void; + onClick: (params: { id: string; configId: string; location: string }) => void; }) => { const { data, loading, averageDuration } = useLast50DurationChart({ locationId: monitor.location?.id, diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/hooks/use_monitor_detail.ts b/x-pack/plugins/synthetics/public/apps/synthetics/hooks/use_monitor_detail.ts index 63a9f556f4b2bc..119f44a642c264 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/hooks/use_monitor_detail.ts +++ b/x-pack/plugins/synthetics/public/apps/synthetics/hooks/use_monitor_detail.ts @@ -11,7 +11,7 @@ import { SYNTHETICS_INDEX_PATTERN } from '../../../../common/constants'; import { Ping } from '../../../../common/runtime_types'; export const useMonitorDetail = ( - monitorId: string, + configId: string, location: string ): { data?: Ping; loading?: boolean } => { const params = { @@ -23,7 +23,7 @@ export const useMonitorDetail = ( filter: [ { term: { - config_id: monitorId, + config_id: configId, }, }, { @@ -44,7 +44,7 @@ export const useMonitorDetail = ( }; const { data: result, loading } = useEsSearch( params, - [monitorId, location], + [configId, location], { name: 'getMonitorStatusByLocation', } diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/hooks/use_monitor_enable_handler.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/hooks/use_monitor_enable_handler.tsx index 0049fcdad8fad8..2f90f6cd70b8be 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/hooks/use_monitor_enable_handler.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/hooks/use_monitor_enable_handler.tsx @@ -18,18 +18,18 @@ export interface EnableStateMonitorLabels { } export function useMonitorEnableHandler({ - id, + configId, reloadPage, labels, }: { - id: string; + configId: string; isEnabled: boolean; reloadPage?: () => void; labels: EnableStateMonitorLabels; }) { const dispatch = useDispatch(); const upsertStatuses = useSelector(selectMonitorUpsertStatuses); - const status: FETCH_STATUS | undefined = upsertStatuses[id]?.status; + const status: FETCH_STATUS | undefined = upsertStatuses[configId]?.status; const [nextEnabled, setNextEnabled] = useState(null); useEffect(() => { @@ -42,7 +42,7 @@ export function useMonitorEnableHandler({ (enabled: boolean) => { dispatch( fetchUpsertMonitorAction({ - id, + id: configId, monitor: { [ConfigKey.ENABLED]: enabled }, success: { message: enabled ? labels.enabledSuccessLabel : labels.disabledSuccessLabel, @@ -63,7 +63,7 @@ export function useMonitorEnableHandler({ }, [ dispatch, - id, + configId, labels.disabledSuccessLabel, labels.enabledSuccessLabel, labels.failureLabel, diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/state/overview/models.ts b/x-pack/plugins/synthetics/public/apps/synthetics/state/overview/models.ts index cc3bb35322a76a..00669b83c98d77 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/state/overview/models.ts +++ b/x-pack/plugins/synthetics/public/apps/synthetics/state/overview/models.ts @@ -19,7 +19,8 @@ export interface MonitorOverviewPageState { } export type MonitorOverviewFlyoutConfig = { - monitorId: string; + configId: string; + id: string; location: string; } | null; diff --git a/x-pack/plugins/synthetics/server/legacy_uptime/lib/saved_objects/synthetics_monitor.ts b/x-pack/plugins/synthetics/server/legacy_uptime/lib/saved_objects/synthetics_monitor.ts index ab25be0f3f3d64..a228e4047e4e78 100644 --- a/x-pack/plugins/synthetics/server/legacy_uptime/lib/saved_objects/synthetics_monitor.ts +++ b/x-pack/plugins/synthetics/server/legacy_uptime/lib/saved_objects/synthetics_monitor.ts @@ -109,6 +109,9 @@ export const getSyntheticsMonitorSavedObjectType = ( custom_heartbeat_id: { type: 'keyword', }, + id: { + type: 'keyword', + }, tags: { type: 'keyword', fields: { diff --git a/x-pack/plugins/synthetics/server/routes/monitor_cruds/get_monitor.ts b/x-pack/plugins/synthetics/server/routes/monitor_cruds/get_monitor.ts index 54b3b0bda02175..72c24a7886ca2a 100644 --- a/x-pack/plugins/synthetics/server/routes/monitor_cruds/get_monitor.ts +++ b/x-pack/plugins/synthetics/server/routes/monitor_cruds/get_monitor.ts @@ -104,14 +104,16 @@ export const getSyntheticsMonitorOverviewRoute: SyntheticsRestApiRouteFactory = /* collect all monitor ids for use * in filtering overview requests */ result.saved_objects.forEach((monitor) => { - const id = monitor.id; - allMonitorIds.push(id); + const id = monitor.attributes[ConfigKey.MONITOR_QUERY_ID]; + const configId = monitor.attributes[ConfigKey.CONFIG_ID]; + allMonitorIds.push(configId); - /* for reach location, add a config item */ + /* for each location, add a config item */ const locations = monitor.attributes[ConfigKey.LOCATIONS]; locations.forEach((location) => { const config = { id, + configId, name: monitor.attributes[ConfigKey.NAME], location, isEnabled: monitor.attributes[ConfigKey.ENABLED], diff --git a/x-pack/test/api_integration/apis/synthetics/get_monitor_overview.ts b/x-pack/test/api_integration/apis/synthetics/get_monitor_overview.ts index 575de013a96dd0..5683671fc55273 100644 --- a/x-pack/test/api_integration/apis/synthetics/get_monitor_overview.ts +++ b/x-pack/test/api_integration/apis/synthetics/get_monitor_overview.ts @@ -4,20 +4,31 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ - +import uuid from 'uuid'; import { SimpleSavedObject } from '@kbn/core/public'; -import { SyntheticsMonitor, MonitorFields } from '@kbn/synthetics-plugin/common/runtime_types'; +import { + ConfigKey, + SyntheticsMonitor, + MonitorFields, +} from '@kbn/synthetics-plugin/common/runtime_types'; import { SYNTHETICS_API_URLS, API_URLS } from '@kbn/synthetics-plugin/common/constants'; import expect from '@kbn/expect'; import { FtrProviderContext } from '../../ftr_provider_context'; import { getFixtureJson } from '../uptime/rest/helper/get_fixture_json'; export default function ({ getService }: FtrProviderContext) { - // Failing: See https://github.com/elastic/kibana/issues/145270 - describe.skip('GetMonitorsOverview', function () { + describe('GetMonitorsOverview', function () { this.tags('skipCloud'); const supertest = getService('supertest'); + const kibanaServer = getService('kibanaServer'); + const security = getService('security'); + + const username = 'admin'; + const roleName = `synthetics_admin`; + const password = `${username}-password`; + const SPACE_ID = `test-space-${uuid.v4()}`; + const SPACE_NAME = `test-space-name ${uuid.v4()}`; let _monitors: MonitorFields[]; let monitors: MonitorFields[]; @@ -25,7 +36,7 @@ export default function ({ getService }: FtrProviderContext) { const deleteMonitor = async (id: string) => { try { await supertest - .delete(`${API_URLS.SYNTHETICS_MONITORS}/${id}`) + .delete(`/s/${SPACE_ID}${API_URLS.SYNTHETICS_MONITORS}/${id}`) .set('kbn-xsrf', 'true') .expect(200); } catch (e) { @@ -36,7 +47,7 @@ export default function ({ getService }: FtrProviderContext) { const saveMonitor = async (monitor: MonitorFields) => { const res = await supertest - .post(API_URLS.SYNTHETICS_MONITORS) + .post(`/s/${SPACE_ID}${API_URLS.SYNTHETICS_MONITORS}`) .set('kbn-xsrf', 'true') .send(monitor); @@ -45,8 +56,24 @@ export default function ({ getService }: FtrProviderContext) { before(async () => { await supertest.post(API_URLS.SYNTHETICS_ENABLEMENT).set('kbn-xsrf', 'true').expect(200); + await kibanaServer.spaces.create({ id: SPACE_ID, name: SPACE_NAME }); + await security.role.create(roleName, { + kibana: [ + { + feature: { + uptime: ['all'], + }, + spaces: ['*'], + }, + ], + }); + await security.user.create(username, { + password, + roles: [roleName], + full_name: 'a kibana user', + }); const { body } = await supertest - .get(API_URLS.SYNTHETICS_MONITORS) + .get(`/s/${SPACE_ID}${API_URLS.SYNTHETICS_MONITORS}`) .set('kbn-xsrf', 'true') .expect(200); await Promise.all([ @@ -68,6 +95,12 @@ export default function ({ getService }: FtrProviderContext) { } }); + after(async () => { + await kibanaServer.spaces.delete(SPACE_ID); + await security.user.delete(username); + await security.role.delete(roleName); + }); + describe('returns total number of monitor combinations', () => { it('returns the correct response', async () => { let savedMonitors: SimpleSavedObject[] = []; @@ -76,7 +109,7 @@ export default function ({ getService }: FtrProviderContext) { savedMonitors = savedResponse; const apiResponse = await supertest.get( - SYNTHETICS_API_URLS.SYNTHETICS_OVERVIEW + '?perPage=20' + `/s/${SPACE_ID}${SYNTHETICS_API_URLS.SYNTHETICS_OVERVIEW}` ); expect(apiResponse.body.total).eql(monitors.length * 2); @@ -99,9 +132,11 @@ export default function ({ getService }: FtrProviderContext) { const savedResponse = await Promise.all(monitors.map(saveMonitor)); savedMonitors = savedResponse; - const apiResponse = await supertest.get(SYNTHETICS_API_URLS.SYNTHETICS_OVERVIEW).query({ - query: '19', - }); + const apiResponse = await supertest + .get(`/s/${SPACE_ID}${SYNTHETICS_API_URLS.SYNTHETICS_OVERVIEW}`) + .query({ + query: '19', + }); expect(apiResponse.body.total).eql(2); expect(apiResponse.body.allMonitorIds.sort()).eql( @@ -119,5 +154,98 @@ export default function ({ getService }: FtrProviderContext) { } }); }); + + describe('Overview Item', () => { + it('returns the correct response', async () => { + let savedMonitors: Array> = []; + const customHeartbeatId = 'example_custom_heartbeat_id'; + try { + const savedResponse = await Promise.all( + [ + monitors[0], + { ...monitors[1], custom_heartbeat_id: 'example_custom_heartbeat_id' }, + ].map(saveMonitor) + ); + savedMonitors = savedResponse; + + const apiResponse = await supertest.get( + `/s/${SPACE_ID}${SYNTHETICS_API_URLS.SYNTHETICS_OVERVIEW}` + ); + expect(apiResponse.body.monitors).eql([ + { + id: savedMonitors[0].attributes[ConfigKey.MONITOR_QUERY_ID], + configId: savedMonitors[0].id, + name: 'test-monitor-name 0', + location: { + id: 'eu-west-01', + label: 'Europe West', + geo: { + lat: 33.2343132435, + lon: 73.2342343434, + }, + url: 'https://example-url.com', + isServiceManaged: true, + }, + isEnabled: true, + }, + { + id: savedMonitors[0].attributes[ConfigKey.MONITOR_QUERY_ID], + configId: savedMonitors[0].id, + name: 'test-monitor-name 0', + location: { + id: 'eu-west-02', + label: 'Europe West', + geo: { + lat: 33.2343132435, + lon: 73.2342343434, + }, + url: 'https://example-url.com', + isServiceManaged: true, + }, + isEnabled: true, + }, + { + id: savedMonitors[1].attributes[ConfigKey.MONITOR_QUERY_ID], + configId: savedMonitors[1].id, + name: 'test-monitor-name 1', + location: { + id: 'eu-west-01', + label: 'Europe West', + geo: { + lat: 33.2343132435, + lon: 73.2342343434, + }, + url: 'https://example-url.com', + isServiceManaged: true, + }, + isEnabled: true, + }, + { + id: savedMonitors[1].attributes[ConfigKey.MONITOR_QUERY_ID], + configId: savedMonitors[1].id, + name: 'test-monitor-name 1', + location: { + id: 'eu-west-02', + label: 'Europe West', + geo: { + lat: 33.2343132435, + lon: 73.2342343434, + }, + url: 'https://example-url.com', + isServiceManaged: true, + }, + isEnabled: true, + }, + ]); + expect(savedMonitors[1].attributes[ConfigKey.MONITOR_QUERY_ID]).eql(customHeartbeatId); + } finally { + await Promise.all( + savedMonitors.map((monitor) => { + return deleteMonitor(monitor.id); + }) + ); + } + }); + }); }); }