From 397c8060f6019319d0f14062533e3201a7599e12 Mon Sep 17 00:00:00 2001 From: shahzad Date: Mon, 30 Mar 2020 16:09:45 +0200 Subject: [PATCH 1/5] update monitor status API --- .../uptime/common/constants/rest_api.ts | 1 - .../monitor/status_bar_container.tsx | 12 ++--- .../__snapshots__/monitor.test.tsx.snap | 2 +- .../plugins/uptime/public/pages/monitor.tsx | 53 +++---------------- .../public/state/actions/monitor_status.ts | 4 -- .../uptime/public/state/api/monitor_status.ts | 14 +---- .../public/state/effects/monitor_status.ts | 9 ---- .../public/state/reducers/monitor_status.ts | 37 ++++--------- .../uptime/public/state/selectors/index.ts | 4 +- .../server/lib/requests/get_latest_monitor.ts | 26 ++------- .../uptime/server/lib/requests/get_monitor.ts | 49 ----------------- .../uptime/server/lib/requests/index.ts | 1 - .../plugins/uptime/server/rest_api/index.ts | 2 - .../uptime/server/rest_api/monitors/index.ts | 2 +- .../uptime/server/rest_api/monitors/status.ts | 25 +-------- .../rest/fixtures/selected_monitor.json | 28 ---------- .../api_integration/apis/uptime/rest/index.ts | 1 - .../apis/uptime/rest/selected_monitor.ts | 23 -------- 18 files changed, 33 insertions(+), 260 deletions(-) delete mode 100644 x-pack/plugins/uptime/server/lib/requests/get_monitor.ts delete mode 100644 x-pack/test/api_integration/apis/uptime/rest/fixtures/selected_monitor.json delete mode 100644 x-pack/test/api_integration/apis/uptime/rest/selected_monitor.ts diff --git a/x-pack/legacy/plugins/uptime/common/constants/rest_api.ts b/x-pack/legacy/plugins/uptime/common/constants/rest_api.ts index 7fafe6584d83..86e2b03e13f2 100644 --- a/x-pack/legacy/plugins/uptime/common/constants/rest_api.ts +++ b/x-pack/legacy/plugins/uptime/common/constants/rest_api.ts @@ -10,7 +10,6 @@ export enum API_URLS { MONITOR_LOCATIONS = `/api/uptime/monitor/locations`, MONITOR_DURATION = `/api/uptime/monitor/duration`, MONITOR_DETAILS = `/api/uptime/monitor/details`, - MONITOR_SELECTED = `/api/uptime/monitor/selected`, MONITOR_STATUS = `/api/uptime/monitor/status`, PINGS = '/api/uptime/pings', PING_HISTOGRAM = `/api/uptime/ping/histogram`, diff --git a/x-pack/legacy/plugins/uptime/public/components/connected/monitor/status_bar_container.tsx b/x-pack/legacy/plugins/uptime/public/components/connected/monitor/status_bar_container.tsx index 9e7834ae6f24..dd6f7a89cf9a 100644 --- a/x-pack/legacy/plugins/uptime/public/components/connected/monitor/status_bar_container.tsx +++ b/x-pack/legacy/plugins/uptime/public/components/connected/monitor/status_bar_container.tsx @@ -8,9 +8,9 @@ import React, { useContext, useEffect } from 'react'; import { connect } from 'react-redux'; import { Dispatch } from 'redux'; import { AppState } from '../../../state'; -import { monitorLocationsSelector, selectMonitorStatus } from '../../../state/selectors'; +import { monitorLocationsSelector, monitorStatusSelector } from '../../../state/selectors'; import { MonitorStatusBarComponent } from '../../functional/monitor_status_details/monitor_status_bar'; -import { getMonitorStatusAction, getSelectedMonitorAction } from '../../../state/actions'; +import { getMonitorStatusAction } from '../../../state/actions'; import { useUrlParams } from '../../../hooks'; import { Ping } from '../../../../common/graphql/types'; import { MonitorLocations } from '../../../../common/runtime_types/monitor'; @@ -23,7 +23,6 @@ interface StateProps { interface DispatchProps { loadMonitorStatus: typeof getMonitorStatusAction; - loadSelectedMonitor: typeof getSelectedMonitorAction; } interface OwnProps { @@ -34,7 +33,6 @@ type Props = OwnProps & StateProps & DispatchProps; const Container: React.FC = ({ loadMonitorStatus, - loadSelectedMonitor, monitorId, monitorStatus, monitorLocations, @@ -46,8 +44,7 @@ const Container: React.FC = ({ useEffect(() => { loadMonitorStatus({ dateStart, dateEnd, monitorId }); - loadSelectedMonitor({ monitorId }); - }, [monitorId, dateStart, dateEnd, loadMonitorStatus, lastRefresh, loadSelectedMonitor]); + }, [monitorId, dateStart, dateEnd, loadMonitorStatus, lastRefresh]); return ( = ({ }; const mapStateToProps = (state: AppState, ownProps: OwnProps) => ({ - monitorStatus: selectMonitorStatus(state), + monitorStatus: monitorStatusSelector(state), monitorLocations: monitorLocationsSelector(state, ownProps.monitorId), }); const mapDispatchToProps = (dispatch: Dispatch): DispatchProps => ({ - loadSelectedMonitor: params => dispatch(getSelectedMonitorAction(params)), loadMonitorStatus: params => dispatch(getMonitorStatusAction(params)), }); diff --git a/x-pack/legacy/plugins/uptime/public/pages/__tests__/__snapshots__/monitor.test.tsx.snap b/x-pack/legacy/plugins/uptime/public/pages/__tests__/__snapshots__/monitor.test.tsx.snap index f637af397bbe..6064caa868bf 100644 --- a/x-pack/legacy/plugins/uptime/public/pages/__tests__/__snapshots__/monitor.test.tsx.snap +++ b/x-pack/legacy/plugins/uptime/public/pages/__tests__/__snapshots__/monitor.test.tsx.snap @@ -51,6 +51,6 @@ exports[`MonitorPage shallow renders expected elements for valid props 1`] = ` } } > - + `; diff --git a/x-pack/legacy/plugins/uptime/public/pages/monitor.tsx b/x-pack/legacy/plugins/uptime/public/pages/monitor.tsx index 3de636cac6ec..8ff8ea002397 100644 --- a/x-pack/legacy/plugins/uptime/public/pages/monitor.tsx +++ b/x-pack/legacy/plugins/uptime/public/pages/monitor.tsx @@ -5,45 +5,24 @@ */ import { EuiSpacer } from '@elastic/eui'; -import React, { useContext, useState, useEffect } from 'react'; +import React, { useContext, useState } from 'react'; import { useParams } from 'react-router-dom'; -import { connect, MapDispatchToPropsFunction, MapStateToPropsParam } from 'react-redux'; +import { useSelector } from 'react-redux'; import { MonitorCharts, PingList } from '../components/functional'; import { UptimeRefreshContext } from '../contexts'; import { useUptimeTelemetry, useUrlParams, UptimePage } from '../hooks'; import { useTrackPageview } from '../../../../../plugins/observability/public'; import { MonitorStatusDetails } from '../components/connected'; import { Ping } from '../../common/graphql/types'; -import { AppState } from '../state'; -import { selectSelectedMonitor } from '../state/selectors'; -import { getSelectedMonitorAction } from '../state/actions'; +import { monitorStatusSelector } from '../state/selectors'; import { PageHeader } from './page_header'; import { useBreadcrumbs } from '../hooks/use_breadcrumbs'; -interface StateProps { - selectedMonitor: Ping | null; -} - -interface DispatchProps { - dispatchGetMonitorStatus: (monitorId: string) => void; -} - -type Props = StateProps & DispatchProps; - -export const MonitorPageComponent: React.FC = ({ - selectedMonitor, - dispatchGetMonitorStatus, -}: Props) => { +export const MonitorPage: React.FC = () => { // decode 64 base string, it was decoded to make it a valid url, since monitor id can be a url let { monitorId } = useParams(); monitorId = atob(monitorId || ''); - useEffect(() => { - if (monitorId) { - dispatchGetMonitorStatus(monitorId); - } - }, [dispatchGetMonitorStatus, monitorId]); - const [pingListPageCount, setPingListPageCount] = useState(10); const { refreshApp } = useContext(UptimeRefreshContext); const [getUrlParams, updateUrlParams] = useUrlParams(); @@ -53,11 +32,13 @@ export const MonitorPageComponent: React.FC = ({ const [selectedLocation, setSelectedLocation] = useState(undefined); const [pingListIndex, setPingListIndex] = useState(0); + const selectedMonitor: Ping = useSelector(monitorStatusSelector); + const sharedVariables = { dateRangeStart, dateRangeEnd, - location: selectedLocation, monitorId, + location: selectedLocation, }; useUptimeTelemetry(UptimePage.Monitor); @@ -65,7 +46,7 @@ export const MonitorPageComponent: React.FC = ({ useTrackPageview({ app: 'uptime', path: 'monitor' }); useTrackPageview({ app: 'uptime', path: 'monitor', delay: 15000 }); - const nameOrId = selectedMonitor?.monitor?.name || selectedMonitor?.monitor?.id || ''; + const nameOrId = selectedMonitor?.monitor?.name || monitorId || ''; useBreadcrumbs([{ text: nameOrId }]); return ( <> @@ -97,21 +78,3 @@ export const MonitorPageComponent: React.FC = ({ ); }; - -const mapStateToProps: MapStateToPropsParam = state => ({ - selectedMonitor: selectSelectedMonitor(state), -}); - -const mapDispatchToProps: MapDispatchToPropsFunction = (dispatch, own) => { - return { - dispatchGetMonitorStatus: (monitorId: string) => { - dispatch( - getSelectedMonitorAction({ - monitorId, - }) - ); - }, - }; -}; - -export const MonitorPage = connect(mapStateToProps, mapDispatchToProps)(MonitorPageComponent); diff --git a/x-pack/legacy/plugins/uptime/public/state/actions/monitor_status.ts b/x-pack/legacy/plugins/uptime/public/state/actions/monitor_status.ts index 7917628abf7d..a8f37d38ebae 100644 --- a/x-pack/legacy/plugins/uptime/public/state/actions/monitor_status.ts +++ b/x-pack/legacy/plugins/uptime/public/state/actions/monitor_status.ts @@ -7,10 +7,6 @@ import { createAction } from 'redux-actions'; import { QueryParams } from './types'; import { Ping } from '../../../common/graphql/types'; -export const getSelectedMonitorAction = createAction<{ monitorId: string }>('GET_SELECTED_MONITOR'); -export const getSelectedMonitorActionSuccess = createAction('GET_SELECTED_MONITOR_SUCCESS'); -export const getSelectedMonitorActionFail = createAction('GET_SELECTED_MONITOR_FAIL'); - export const getMonitorStatusAction = createAction('GET_MONITOR_STATUS'); export const getMonitorStatusActionSuccess = createAction('GET_MONITOR_STATUS_SUCCESS'); export const getMonitorStatusActionFail = createAction('GET_MONITOR_STATUS_FAIL'); diff --git a/x-pack/legacy/plugins/uptime/public/state/api/monitor_status.ts b/x-pack/legacy/plugins/uptime/public/state/api/monitor_status.ts index 0f7608ba57ea..f9e171adda33 100644 --- a/x-pack/legacy/plugins/uptime/public/state/api/monitor_status.ts +++ b/x-pack/legacy/plugins/uptime/public/state/api/monitor_status.ts @@ -7,19 +7,7 @@ import { QueryParams } from '../actions/types'; import { Ping } from '../../../common/graphql/types'; import { apiService } from './utils'; -import { API_URLS } from '../../../common/constants/rest_api'; - -export interface APIParams { - monitorId: string; -} - -export const fetchSelectedMonitor = async ({ monitorId }: APIParams): Promise => { - const queryParams = { - monitorId, - }; - - return await apiService.get(API_URLS.MONITOR_SELECTED, queryParams); -}; +import { API_URLS } from '../../../common/constants'; export const fetchMonitorStatus = async ({ monitorId, diff --git a/x-pack/legacy/plugins/uptime/public/state/effects/monitor_status.ts b/x-pack/legacy/plugins/uptime/public/state/effects/monitor_status.ts index 1207ab20bc71..1c2c1c7b644b 100644 --- a/x-pack/legacy/plugins/uptime/public/state/effects/monitor_status.ts +++ b/x-pack/legacy/plugins/uptime/public/state/effects/monitor_status.ts @@ -25,13 +25,4 @@ export function* fetchMonitorStatusEffect() { getMonitorStatusActionFail ) ); - - yield takeLatest( - getSelectedMonitorAction, - fetchEffectFactory( - fetchSelectedMonitor, - getSelectedMonitorActionSuccess, - getSelectedMonitorActionFail - ) - ); } diff --git a/x-pack/legacy/plugins/uptime/public/state/reducers/monitor_status.ts b/x-pack/legacy/plugins/uptime/public/state/reducers/monitor_status.ts index c2dfbd7f90ff..6cfaa9f8f59c 100644 --- a/x-pack/legacy/plugins/uptime/public/state/reducers/monitor_status.ts +++ b/x-pack/legacy/plugins/uptime/public/state/reducers/monitor_status.ts @@ -5,9 +5,6 @@ */ import { handleActions, Action } from 'redux-actions'; import { - getSelectedMonitorAction, - getSelectedMonitorActionSuccess, - getSelectedMonitorActionFail, getMonitorStatusAction, getMonitorStatusActionSuccess, getMonitorStatusActionFail, @@ -17,13 +14,11 @@ import { QueryParams } from '../actions/types'; export interface MonitorStatusState { status: Ping | null; - monitor: Ping | null; loading: boolean; } const initialState: MonitorStatusState = { status: null, - monitor: null, loading: false, }; @@ -31,32 +26,22 @@ type MonitorStatusPayload = QueryParams & Ping; export const monitorStatusReducer = handleActions( { - [String(getSelectedMonitorAction)]: (state, action: Action) => ({ - ...state, - loading: true, - }), - - [String(getSelectedMonitorActionSuccess)]: (state, action: Action) => ({ - ...state, - loading: false, - monitor: { ...action.payload } as Ping, - }), - - [String(getSelectedMonitorActionFail)]: (state, action: Action) => ({ - ...state, - loading: false, - }), - [String(getMonitorStatusAction)]: (state, action: Action) => ({ ...state, loading: true, }), - [String(getMonitorStatusActionSuccess)]: (state, action: Action) => ({ - ...state, - loading: false, - status: { ...action.payload } as Ping, - }), + [String(getMonitorStatusActionSuccess)]: (state, action: Action) => { + return { + ...state, + loading: false, + // Keeping url from prev request to display, if there is no latest status + status: { + url: action.payload?.url || state.status?.url, + ...action.payload, + } as Ping, + }; + }, [String(getMonitorStatusActionFail)]: (state, action: Action) => ({ ...state, diff --git a/x-pack/legacy/plugins/uptime/public/state/selectors/index.ts b/x-pack/legacy/plugins/uptime/public/state/selectors/index.ts index 21e01bd7d827..0fc3c7151cb3 100644 --- a/x-pack/legacy/plugins/uptime/public/state/selectors/index.ts +++ b/x-pack/legacy/plugins/uptime/public/state/selectors/index.ts @@ -22,9 +22,7 @@ export const monitorLocationsSelector = (state: AppState, monitorId: string) => return state.monitor.monitorLocationsList?.get(monitorId); }; -export const selectSelectedMonitor = (state: AppState) => state.monitorStatus.monitor; - -export const selectMonitorStatus = (state: AppState) => state.monitorStatus.status; +export const monitorStatusSelector = (state: AppState) => state.monitorStatus.status; export const selectDynamicSettings = (state: AppState) => { return state.dynamicSettings; diff --git a/x-pack/plugins/uptime/server/lib/requests/get_latest_monitor.ts b/x-pack/plugins/uptime/server/lib/requests/get_latest_monitor.ts index 176963a99868..f19249a4875b 100644 --- a/x-pack/plugins/uptime/server/lib/requests/get_latest_monitor.ts +++ b/x-pack/plugins/uptime/server/lib/requests/get_latest_monitor.ts @@ -26,8 +26,6 @@ export const getLatestMonitor: UMElasticsearchQueryFn { - // TODO: Write tests for this function - const params = { index: dynamicSettings.heartbeatIndices, body: { @@ -46,30 +44,16 @@ export const getLatestMonitor: UMElasticsearchQueryFn = async ({ - callES, - dynamicSettings, - monitorId, -}) => { - const params = { - index: dynamicSettings.heartbeatIndices, - body: { - size: 1, - _source: ['url', 'monitor', 'observer'], - query: { - bool: { - filter: [ - { - term: { - 'monitor.id': monitorId, - }, - }, - ], - }, - }, - sort: [ - { - '@timestamp': { - order: 'desc', - }, - }, - ], - }, - }; - - const result = await callES('search', params); - - return result.hits.hits[0]?._source; -}; diff --git a/x-pack/plugins/uptime/server/lib/requests/index.ts b/x-pack/plugins/uptime/server/lib/requests/index.ts index 7225d329d3c7..445adc3c15a9 100644 --- a/x-pack/plugins/uptime/server/lib/requests/index.ts +++ b/x-pack/plugins/uptime/server/lib/requests/index.ts @@ -7,7 +7,6 @@ export { getFilterBar, GetFilterBarParams } from './get_filter_bar'; export { getUptimeIndexPattern as getIndexPattern } from './get_index_pattern'; export { getLatestMonitor, GetLatestMonitorParams } from './get_latest_monitor'; -export { getMonitor, GetMonitorParams } from './get_monitor'; export { getMonitorDurationChart, GetMonitorChartsParams } from './get_monitor_duration'; export { getMonitorDetails, GetMonitorDetailsParams } from './get_monitor_details'; export { getMonitorLocations, GetMonitorLocationsParams } from './get_monitor_locations'; diff --git a/x-pack/plugins/uptime/server/rest_api/index.ts b/x-pack/plugins/uptime/server/rest_api/index.ts index 561997c3567d..c84ea7103795 100644 --- a/x-pack/plugins/uptime/server/rest_api/index.ts +++ b/x-pack/plugins/uptime/server/rest_api/index.ts @@ -11,7 +11,6 @@ import { createLogPageViewRoute } from './telemetry'; import { createGetSnapshotCount } from './snapshot'; import { UMRestApiRouteFactory } from './types'; import { - createGetMonitorRoute, createGetMonitorDetailsRoute, createGetMonitorLocationsRoute, createGetStatusBarRoute, @@ -31,7 +30,6 @@ export const restApiRoutes: UMRestApiRouteFactory[] = [ createGetIndexStatusRoute, createGetDynamicSettingsRoute, createPostDynamicSettingsRoute, - createGetMonitorRoute, createGetMonitorDetailsRoute, createGetMonitorLocationsRoute, createGetStatusBarRoute, diff --git a/x-pack/plugins/uptime/server/rest_api/monitors/index.ts b/x-pack/plugins/uptime/server/rest_api/monitors/index.ts index 7f1f10081dc4..7da717b50c14 100644 --- a/x-pack/plugins/uptime/server/rest_api/monitors/index.ts +++ b/x-pack/plugins/uptime/server/rest_api/monitors/index.ts @@ -6,4 +6,4 @@ export { createGetMonitorDetailsRoute } from './monitors_details'; export { createGetMonitorLocationsRoute } from './monitor_locations'; -export { createGetMonitorRoute, createGetStatusBarRoute } from './status'; +export { createGetStatusBarRoute } from './status'; diff --git a/x-pack/plugins/uptime/server/rest_api/monitors/status.ts b/x-pack/plugins/uptime/server/rest_api/monitors/status.ts index e1fcaf54f282..9bccd64c4bd6 100644 --- a/x-pack/plugins/uptime/server/rest_api/monitors/status.ts +++ b/x-pack/plugins/uptime/server/rest_api/monitors/status.ts @@ -7,30 +7,7 @@ import { schema } from '@kbn/config-schema'; import { UMServerLibs } from '../../lib/lib'; import { UMRestApiRouteFactory } from '../types'; -import { API_URLS } from '../../../../../legacy/plugins/uptime/common/constants/rest_api'; - -export const createGetMonitorRoute: UMRestApiRouteFactory = (libs: UMServerLibs) => ({ - method: 'GET', - path: API_URLS.MONITOR_SELECTED, - - validate: { - query: schema.object({ - monitorId: schema.string(), - }), - }, - options: { - tags: ['access:uptime-read'], - }, - handler: async ({ callES, dynamicSettings }, _context, request, response): Promise => { - const { monitorId } = request.query; - - return response.ok({ - body: { - ...(await libs.requests.getMonitor({ callES, dynamicSettings, monitorId })), - }, - }); - }, -}); +import { API_URLS } from '../../../../../legacy/plugins/uptime/common/constants'; export const createGetStatusBarRoute: UMRestApiRouteFactory = (libs: UMServerLibs) => ({ method: 'GET', diff --git a/x-pack/test/api_integration/apis/uptime/rest/fixtures/selected_monitor.json b/x-pack/test/api_integration/apis/uptime/rest/fixtures/selected_monitor.json deleted file mode 100644 index d8367ea67052..000000000000 --- a/x-pack/test/api_integration/apis/uptime/rest/fixtures/selected_monitor.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "monitor": { - "check_group": "d76f0762-d445-11e9-88e3-3e80641b9c71", - "duration": { - "us": 24627 - }, - "id": "0002-up", - "ip": "127.0.0.1", - "name": "", - "status": "up", - "type": "http" - }, - "observer": { - "geo": { - "location": "37.926868, -78.024902", - "name": "mpls" - }, - "hostname": "avc-x1x" - }, - "url": { - "domain": "localhost", - "full": "http://localhost:5678/pattern?r=200x1", - "path": "/pattern", - "port": 5678, - "query": "r=200x1", - "scheme": "http" - } -} diff --git a/x-pack/test/api_integration/apis/uptime/rest/index.ts b/x-pack/test/api_integration/apis/uptime/rest/index.ts index b2236e1bb630..f89bec589847 100644 --- a/x-pack/test/api_integration/apis/uptime/rest/index.ts +++ b/x-pack/test/api_integration/apis/uptime/rest/index.ts @@ -47,7 +47,6 @@ export default function({ getService, loadTestFile }: FtrProviderContext) { before('load heartbeat data', async () => await esArchiver.load('uptime/full_heartbeat')); after('unload', async () => await esArchiver.unload('uptime/full_heartbeat')); loadTestFile(require.resolve('./monitor_latest_status')); - loadTestFile(require.resolve('./selected_monitor')); loadTestFile(require.resolve('./ping_histogram')); loadTestFile(require.resolve('./monitor_duration')); loadTestFile(require.resolve('./doc_count')); diff --git a/x-pack/test/api_integration/apis/uptime/rest/selected_monitor.ts b/x-pack/test/api_integration/apis/uptime/rest/selected_monitor.ts deleted file mode 100644 index ed034f58a5f5..000000000000 --- a/x-pack/test/api_integration/apis/uptime/rest/selected_monitor.ts +++ /dev/null @@ -1,23 +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 { expectFixtureEql } from '../graphql/helpers/expect_fixture_eql'; -import { FtrProviderContext } from '../../../ftr_provider_context'; - -export default function({ getService }: FtrProviderContext) { - describe('get selected monitor by ID', () => { - const monitorId = '0002-up'; - - const supertest = getService('supertest'); - - it('returns the monitor for give ID', async () => { - const apiResponse = await supertest.get( - `/api/uptime/monitor/selected?monitorId=${monitorId}` - ); - expectFixtureEql(apiResponse.body, 'selected_monitor'); - }); - }); -} From 7cca960dc8961bcfc417b8b90231879e93e6a176 Mon Sep 17 00:00:00 2001 From: shahzad Date: Mon, 30 Mar 2020 16:17:18 +0200 Subject: [PATCH 2/5] update fixture --- .../rest/fixtures/monitor_latest_status.json | 117 +++++------------- 1 file changed, 29 insertions(+), 88 deletions(-) diff --git a/x-pack/test/api_integration/apis/uptime/rest/fixtures/monitor_latest_status.json b/x-pack/test/api_integration/apis/uptime/rest/fixtures/monitor_latest_status.json index 1702cb2c2100..4dd6e8bdbacc 100644 --- a/x-pack/test/api_integration/apis/uptime/rest/fixtures/monitor_latest_status.json +++ b/x-pack/test/api_integration/apis/uptime/rest/fixtures/monitor_latest_status.json @@ -1,89 +1,30 @@ { - "@timestamp": "2019-09-11T03:40:34.371Z", - "agent": { - "ephemeral_id": "412a92a8-2142-4b1a-a7a2-1afd32e12f85", - "hostname": "avc-x1x", - "id": "04e1d082-65bc-4929-8d65-d0768a2621c4", - "type": "heartbeat", - "version": "8.0.0" - }, - "ecs": { - "version": "1.1.0" - }, - "event": { - "dataset": "uptime" - }, - "host": { - "name": "avc-x1x" - }, - "http": { - "response": { - "body": { - "bytes": 3, - "hash": "27badc983df1780b60c2b3fa9d3a19a00e46aac798451f0febdca52920faaddf" - }, - "status_code": 200 - }, - "rtt": { - "content": { - "us": 57 - }, - "response_header": { - "us": 262 - }, - "total": { - "us": 20331 - }, - "validate": { - "us": 319 - }, - "write_request": { - "us": 82 - } - } - }, - "monitor": { - "check_group": "d76f0762-d445-11e9-88e3-3e80641b9c71", - "duration": { - "us": 24627 - }, - "id": "0002-up", - "ip": "127.0.0.1", - "name": "", - "status": "up", - "type": "http" - }, - "observer": { - "geo": { - "location": "37.926868, -78.024902", - "name": "mpls" - }, - "hostname": "avc-x1x" - }, - "resolve": { - "ip": "127.0.0.1", - "rtt": { - "us": 4218 - } - }, - "summary": { - "down": 0, - "up": 1 - }, - "tcp": { - "rtt": { - "connect": { - "us": 103 - } - } - }, - "timestamp": "2019-09-11T03:40:34.371Z", - "url": { - "domain": "localhost", - "full": "http://localhost:5678/pattern?r=200x1", - "path": "/pattern", - "port": 5678, - "query": "r=200x1", - "scheme": "http" - } - } + "observer": { + "geo": { + "name": "mpls", + "location": "37.926868, -78.024902" + }, + "hostname": "avc-x1x" + }, + "@timestamp": "2019-09-11T03:40:34.371Z", + "monitor": { + "duration": { + "us": 24627 + }, + "ip": "127.0.0.1", + "name": "", + "check_group": "d76f0762-d445-11e9-88e3-3e80641b9c71", + "id": "0002-up", + "type": "http", + "status": "up" + }, + "url": { + "path": "/pattern", + "scheme": "http", + "port": 5678, + "domain": "localhost", + "query": "r=200x1", + "full": "http://localhost:5678/pattern?r=200x1" + }, + "timestamp": "2019-09-11T03:40:34.371Z" +} \ No newline at end of file From 28f8fbb1ae10cf1b3be25cfa3718da665223157e Mon Sep 17 00:00:00 2001 From: shahzad Date: Mon, 30 Mar 2020 17:33:52 +0200 Subject: [PATCH 3/5] fix types --- x-pack/legacy/plugins/uptime/public/pages/monitor.tsx | 3 +-- .../plugins/uptime/public/state/effects/monitor_status.ts | 5 +---- .../uptime/public/state/selectors/__tests__/index.test.ts | 1 - x-pack/plugins/uptime/server/lib/requests/uptime_requests.ts | 2 -- 4 files changed, 2 insertions(+), 9 deletions(-) diff --git a/x-pack/legacy/plugins/uptime/public/pages/monitor.tsx b/x-pack/legacy/plugins/uptime/public/pages/monitor.tsx index 8ff8ea002397..21124b7323d6 100644 --- a/x-pack/legacy/plugins/uptime/public/pages/monitor.tsx +++ b/x-pack/legacy/plugins/uptime/public/pages/monitor.tsx @@ -13,7 +13,6 @@ import { UptimeRefreshContext } from '../contexts'; import { useUptimeTelemetry, useUrlParams, UptimePage } from '../hooks'; import { useTrackPageview } from '../../../../../plugins/observability/public'; import { MonitorStatusDetails } from '../components/connected'; -import { Ping } from '../../common/graphql/types'; import { monitorStatusSelector } from '../state/selectors'; import { PageHeader } from './page_header'; import { useBreadcrumbs } from '../hooks/use_breadcrumbs'; @@ -32,7 +31,7 @@ export const MonitorPage: React.FC = () => { const [selectedLocation, setSelectedLocation] = useState(undefined); const [pingListIndex, setPingListIndex] = useState(0); - const selectedMonitor: Ping = useSelector(monitorStatusSelector); + const selectedMonitor = useSelector(monitorStatusSelector); const sharedVariables = { dateRangeStart, diff --git a/x-pack/legacy/plugins/uptime/public/state/effects/monitor_status.ts b/x-pack/legacy/plugins/uptime/public/state/effects/monitor_status.ts index 1c2c1c7b644b..2669629ed34f 100644 --- a/x-pack/legacy/plugins/uptime/public/state/effects/monitor_status.ts +++ b/x-pack/legacy/plugins/uptime/public/state/effects/monitor_status.ts @@ -6,14 +6,11 @@ import { takeLatest } from 'redux-saga/effects'; import { - getSelectedMonitorAction, - getSelectedMonitorActionSuccess, - getSelectedMonitorActionFail, getMonitorStatusAction, getMonitorStatusActionSuccess, getMonitorStatusActionFail, } from '../actions'; -import { fetchSelectedMonitor, fetchMonitorStatus } from '../api'; +import { fetchMonitorStatus } from '../api'; import { fetchEffectFactory } from './fetch_effect'; export function* fetchMonitorStatusEffect() { diff --git a/x-pack/legacy/plugins/uptime/public/state/selectors/__tests__/index.test.ts b/x-pack/legacy/plugins/uptime/public/state/selectors/__tests__/index.test.ts index 573d5b190608..3b4547514a11 100644 --- a/x-pack/legacy/plugins/uptime/public/state/selectors/__tests__/index.test.ts +++ b/x-pack/legacy/plugins/uptime/public/state/selectors/__tests__/index.test.ts @@ -46,7 +46,6 @@ describe('state selectors', () => { }, monitorStatus: { status: null, - monitor: null, loading: false, }, indexPattern: { diff --git a/x-pack/plugins/uptime/server/lib/requests/uptime_requests.ts b/x-pack/plugins/uptime/server/lib/requests/uptime_requests.ts index 6eeea5ba4c3e..9d3fa5aa08ae 100644 --- a/x-pack/plugins/uptime/server/lib/requests/uptime_requests.ts +++ b/x-pack/plugins/uptime/server/lib/requests/uptime_requests.ts @@ -9,7 +9,6 @@ import { Ping, PingResults } from '../../../../../legacy/plugins/uptime/common/g import { GetFilterBarParams, GetLatestMonitorParams, - GetMonitorParams, GetMonitorChartsParams, GetMonitorDetailsParams, GetMonitorLocationsParams, @@ -39,7 +38,6 @@ export interface UptimeRequests { getFilterBar: ESQ; getIndexPattern: ESQ<{}, {}>; getLatestMonitor: ESQ; - getMonitor: ESQ; getMonitorDurationChart: ESQ; getMonitorDetails: ESQ; getMonitorLocations: ESQ; From 56345e11a1e138e7566ccb90ac3471b3e303df6f Mon Sep 17 00:00:00 2001 From: shahzad Date: Mon, 30 Mar 2020 18:37:42 +0200 Subject: [PATCH 4/5] fix tets --- .../__tests__/get_latest_monitor.test.ts | 50 +++++-------------- 1 file changed, 13 insertions(+), 37 deletions(-) diff --git a/x-pack/plugins/uptime/server/lib/requests/__tests__/get_latest_monitor.test.ts b/x-pack/plugins/uptime/server/lib/requests/__tests__/get_latest_monitor.test.ts index b7e340fddbd2..9480aee75bb9 100644 --- a/x-pack/plugins/uptime/server/lib/requests/__tests__/get_latest_monitor.test.ts +++ b/x-pack/plugins/uptime/server/lib/requests/__tests__/get_latest_monitor.test.ts @@ -31,49 +31,25 @@ describe('getLatestMonitor', () => { ], }, }, - aggs: { - by_id: { - terms: { - field: 'monitor.id', - size: 1000, - }, - aggs: { - latest: { - top_hits: { - size: 1, - sort: { - '@timestamp': { order: 'desc' }, - }, - }, - }, - }, - }, + size: 1, + _source: ['url', 'monitor', 'observer', 'tls', '@timestamp'], + sort: { + '@timestamp': { order: 'desc' }, }, - size: 0, }, }; mockEsSearchResult = { - aggregations: { - by_id: { - buckets: [ - { - latest: { - hits: { - hits: [ - { - _source: { - '@timestamp': 123456, - monitor: { - id: 'testMonitor', - }, - }, - }, - ], - }, + hits: { + hits: [ + { + _source: { + '@timestamp': 123456, + monitor: { + id: 'testMonitor', }, }, - ], - }, + }, + ], }, }; }); From 4a8238fe85f175f6e7d46d778fe5a7e7ad4117ff Mon Sep 17 00:00:00 2001 From: shahzad Date: Mon, 30 Mar 2020 20:17:06 +0200 Subject: [PATCH 5/5] fix tests --- .../server/lib/requests/__tests__/get_latest_monitor.test.ts | 3 ++- .../plugins/uptime/server/lib/requests/get_latest_monitor.ts | 5 +++-- .../apis/uptime/rest/fixtures/monitor_latest_status.json | 5 ++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/x-pack/plugins/uptime/server/lib/requests/__tests__/get_latest_monitor.test.ts b/x-pack/plugins/uptime/server/lib/requests/__tests__/get_latest_monitor.test.ts index 9480aee75bb9..112c8e97d4c0 100644 --- a/x-pack/plugins/uptime/server/lib/requests/__tests__/get_latest_monitor.test.ts +++ b/x-pack/plugins/uptime/server/lib/requests/__tests__/get_latest_monitor.test.ts @@ -43,7 +43,7 @@ describe('getLatestMonitor', () => { hits: [ { _source: { - '@timestamp': 123456, + timestamp: 123456, monitor: { id: 'testMonitor', }, @@ -63,6 +63,7 @@ describe('getLatestMonitor', () => { dateEnd: 'now', monitorId: 'testMonitor', }); + expect(result.timestamp).toBe(123456); expect(result.monitor).not.toBeFalsy(); expect(result?.monitor?.id).toBe('testMonitor'); diff --git a/x-pack/plugins/uptime/server/lib/requests/get_latest_monitor.ts b/x-pack/plugins/uptime/server/lib/requests/get_latest_monitor.ts index f19249a4875b..299e3eb6ca3c 100644 --- a/x-pack/plugins/uptime/server/lib/requests/get_latest_monitor.ts +++ b/x-pack/plugins/uptime/server/lib/requests/get_latest_monitor.ts @@ -54,9 +54,10 @@ export const getLatestMonitor: UMElasticsearchQueryFn