From 222cbaa643709483045eecf1380776673916900b Mon Sep 17 00:00:00 2001 From: Shahzad Date: Tue, 17 Nov 2020 16:45:21 +0100 Subject: [PATCH] [7.x] [Uptime] Fix monitor list down histogram (#83411) (#83543) --- .../server/lib/requests/get_monitor_states.ts | 2 +- .../monitor_states_real_data.snap | 369 ++++++++++++++++++ .../api_integration/apis/uptime/rest/index.ts | 3 + .../uptime/rest/monitor_states_real_data.ts | 11 + 4 files changed, 384 insertions(+), 1 deletion(-) create mode 100644 x-pack/test/api_integration/apis/uptime/rest/__snapshots__/monitor_states_real_data.snap diff --git a/x-pack/plugins/uptime/server/lib/requests/get_monitor_states.ts b/x-pack/plugins/uptime/server/lib/requests/get_monitor_states.ts index 020fcf5331188..2ff1043d79e84 100644 --- a/x-pack/plugins/uptime/server/lib/requests/get_monitor_states.ts +++ b/x-pack/plugins/uptime/server/lib/requests/get_monitor_states.ts @@ -151,7 +151,7 @@ export const getHistogramForMonitors = async ( }, }, }; - const result = await queryContext.search(params); + const { body: result } = await queryContext.search(params); const histoBuckets: any[] = result.aggregations?.histogram.buckets ?? []; const simplified = histoBuckets.map((histoBucket: any): { timestamp: number; byId: any } => { diff --git a/x-pack/test/api_integration/apis/uptime/rest/__snapshots__/monitor_states_real_data.snap b/x-pack/test/api_integration/apis/uptime/rest/__snapshots__/monitor_states_real_data.snap new file mode 100644 index 0000000000000..50625683b605d --- /dev/null +++ b/x-pack/test/api_integration/apis/uptime/rest/__snapshots__/monitor_states_real_data.snap @@ -0,0 +1,369 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`monitor states endpoint will fetch monitor state data for the given down filters 1`] = ` +Object { + "nextPagePagination": "{\\"cursorDirection\\":\\"AFTER\\",\\"sortOrder\\":\\"ASC\\",\\"cursorKey\\":{\\"monitor_id\\":\\"0020-down\\"}}", + "prevPagePagination": null, + "summaries": Array [ + Object { + "histogram": Object { + "points": Array [ + Object { + "down": 1, + "timestamp": 1568172624744, + }, + Object { + "down": 2, + "timestamp": 1568172677247, + }, + Object { + "down": 1, + "timestamp": 1568172729750, + }, + Object { + "down": 2, + "timestamp": 1568172782253, + }, + Object { + "down": 2, + "timestamp": 1568172834756, + }, + Object { + "down": 2, + "timestamp": 1568172887259, + }, + Object { + "down": 1, + "timestamp": 1568172939762, + }, + Object { + "down": 2, + "timestamp": 1568172992265, + }, + Object { + "down": 2, + "timestamp": 1568173044768, + }, + Object { + "down": 2, + "timestamp": 1568173097271, + }, + Object { + "down": 1, + "timestamp": 1568173149774, + }, + Object { + "down": 2, + "timestamp": 1568173202277, + }, + ], + }, + "minInterval": 52503, + "monitor_id": "0010-down", + "state": Object { + "monitor": Object { + "name": "", + }, + "observer": Object { + "geo": Object { + "name": Array [ + "mpls", + ], + }, + }, + "summary": Object { + "down": 1, + "status": "down", + "up": 0, + }, + "summaryPings": Array [ + Object { + "@timestamp": "2019-09-11T03:40:34.371Z", + "agent": Object { + "ephemeral_id": "412a92a8-2142-4b1a-a7a2-1afd32e12f85", + "hostname": "avc-x1x", + "id": "04e1d082-65bc-4929-8d65-d0768a2621c4", + "type": "heartbeat", + "version": "8.0.0", + }, + "docId": "rZtoHm0B0I9WX_CznN_V", + "ecs": Object { + "version": "1.1.0", + }, + "error": Object { + "message": "400 Bad Request", + "type": "validate", + }, + "event": Object { + "dataset": "uptime", + }, + "host": Object { + "name": "avc-x1x", + }, + "http": Object { + "response": Object { + "body": Object { + "bytes": 3, + "content": "400", + "hash": "26d228663f13a88592a12d16cf9587caab0388b262d6d9f126ed62f9333aca94", + }, + "status_code": 400, + }, + "rtt": Object { + "content": Object { + "us": 41, + }, + "response_header": Object { + "us": 36777, + }, + "total": Object { + "us": 37821, + }, + "validate": Object { + "us": 36818, + }, + "write_request": Object { + "us": 53, + }, + }, + }, + "monitor": Object { + "check_group": "d76f07d1-d445-11e9-88e3-3e80641b9c71", + "duration": Object { + "us": 37926, + }, + "id": "0010-down", + "ip": "127.0.0.1", + "name": "", + "status": "down", + "type": "http", + }, + "observer": Object { + "geo": Object { + "location": "37.926868, -78.024902", + "name": "mpls", + }, + "hostname": "avc-x1x", + }, + "resolve": Object { + "ip": "127.0.0.1", + "rtt": Object { + "us": 56, + }, + }, + "summary": Object { + "down": 1, + "up": 0, + }, + "tcp": Object { + "rtt": Object { + "connect": Object { + "us": 890, + }, + }, + }, + "timestamp": "2019-09-11T03:40:34.371Z", + "url": Object { + "domain": "localhost", + "full": "http://localhost:5678/pattern?r=400x1", + "path": "/pattern", + "port": 5678, + "query": "r=400x1", + "scheme": "http", + }, + }, + ], + "timestamp": "2019-09-11T03:40:34.371Z", + "url": Object { + "domain": "localhost", + "full": "http://localhost:5678/pattern?r=400x1", + "path": "/pattern", + "port": 5678, + "query": "r=400x1", + "scheme": "http", + }, + }, + }, + Object { + "histogram": Object { + "points": Array [ + Object { + "down": 1, + "timestamp": 1568172624744, + }, + Object { + "down": 2, + "timestamp": 1568172677247, + }, + Object { + "down": 1, + "timestamp": 1568172729750, + }, + Object { + "down": 2, + "timestamp": 1568172782253, + }, + Object { + "down": 2, + "timestamp": 1568172834756, + }, + Object { + "down": 2, + "timestamp": 1568172887259, + }, + Object { + "down": 1, + "timestamp": 1568172939762, + }, + Object { + "down": 2, + "timestamp": 1568172992265, + }, + Object { + "down": 2, + "timestamp": 1568173044768, + }, + Object { + "down": 2, + "timestamp": 1568173097271, + }, + Object { + "down": 1, + "timestamp": 1568173149774, + }, + Object { + "down": 2, + "timestamp": 1568173202277, + }, + ], + }, + "minInterval": 52503, + "monitor_id": "0020-down", + "state": Object { + "monitor": Object { + "name": "", + }, + "observer": Object { + "geo": Object { + "name": Array [ + "mpls", + ], + }, + }, + "summary": Object { + "down": 1, + "status": "down", + "up": 0, + }, + "summaryPings": Array [ + Object { + "@timestamp": "2019-09-11T03:40:34.372Z", + "agent": Object { + "ephemeral_id": "412a92a8-2142-4b1a-a7a2-1afd32e12f85", + "hostname": "avc-x1x", + "id": "04e1d082-65bc-4929-8d65-d0768a2621c4", + "type": "heartbeat", + "version": "8.0.0", + }, + "docId": "X5toHm0B0I9WX_CznN-6", + "ecs": Object { + "version": "1.1.0", + }, + "error": Object { + "message": "400 Bad Request", + "type": "validate", + }, + "event": Object { + "dataset": "uptime", + }, + "host": Object { + "name": "avc-x1x", + }, + "http": Object { + "response": Object { + "body": Object { + "bytes": 3, + "content": "400", + "hash": "26d228663f13a88592a12d16cf9587caab0388b262d6d9f126ed62f9333aca94", + }, + "status_code": 400, + }, + "rtt": Object { + "content": Object { + "us": 54, + }, + "response_header": Object { + "us": 180, + }, + "total": Object { + "us": 555, + }, + "validate": Object { + "us": 234, + }, + "write_request": Object { + "us": 63, + }, + }, + }, + "monitor": Object { + "check_group": "d7712ecb-d445-11e9-88e3-3e80641b9c71", + "duration": Object { + "us": 14900, + }, + "id": "0020-down", + "ip": "127.0.0.1", + "name": "", + "status": "down", + "type": "http", + }, + "observer": Object { + "geo": Object { + "location": "37.926868, -78.024902", + "name": "mpls", + }, + "hostname": "avc-x1x", + }, + "resolve": Object { + "ip": "127.0.0.1", + "rtt": Object { + "us": 14294, + }, + }, + "summary": Object { + "down": 1, + "up": 0, + }, + "tcp": Object { + "rtt": Object { + "connect": Object { + "us": 105, + }, + }, + }, + "timestamp": "2019-09-11T03:40:34.372Z", + "url": Object { + "domain": "localhost", + "full": "http://localhost:5678/pattern?r=400x1", + "path": "/pattern", + "port": 5678, + "query": "r=400x1", + "scheme": "http", + }, + }, + ], + "timestamp": "2019-09-11T03:40:34.372Z", + "url": Object { + "domain": "localhost", + "full": "http://localhost:5678/pattern?r=400x1", + "path": "/pattern", + "port": 5678, + "query": "r=400x1", + "scheme": "http", + }, + }, + }, + ], + "totalSummaryCount": 2000, +} +`; 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 f59b79a6b7bfc..6f410add0fa4d 100644 --- a/x-pack/test/api_integration/apis/uptime/rest/index.ts +++ b/x-pack/test/api_integration/apis/uptime/rest/index.ts @@ -9,12 +9,15 @@ import { settingsObjectId, settingsObjectType, } from '../../../../../plugins/uptime/server/lib/saved_objects'; +import { registerMochaHooksForSnapshots } from '../../../../apm_api_integration/common/match_snapshot'; export default function ({ getService, loadTestFile }: FtrProviderContext) { const esArchiver = getService('esArchiver'); const server = getService('kibanaServer'); describe('uptime REST endpoints', () => { + registerMochaHooksForSnapshots(); + beforeEach('clear settings', async () => { try { await server.savedObjects.delete({ diff --git a/x-pack/test/api_integration/apis/uptime/rest/monitor_states_real_data.ts b/x-pack/test/api_integration/apis/uptime/rest/monitor_states_real_data.ts index d3c49bb49ff52..08a339ed59326 100644 --- a/x-pack/test/api_integration/apis/uptime/rest/monitor_states_real_data.ts +++ b/x-pack/test/api_integration/apis/uptime/rest/monitor_states_real_data.ts @@ -9,6 +9,7 @@ import { isRight } from 'fp-ts/lib/Either'; import { FtrProviderContext } from '../../../ftr_provider_context'; import { MonitorSummariesResultType } from '../../../../../plugins/uptime/common/runtime_types'; import { API_URLS } from '../../../../../plugins/uptime/common/constants'; +import { expectSnapshot } from '../../../../apm_api_integration/common/match_snapshot'; interface ExpectedMonitorStatesPage { response: any; @@ -90,6 +91,16 @@ export default function ({ getService }: FtrProviderContext) { }); }); + it('will fetch monitor state data for the given down filters', async () => { + const statusFilter = 'down'; + const size = 2; + const { body } = await supertest.get( + `${API_URLS.MONITOR_LIST}?dateRangeStart=${from}&dateRangeEnd=${to}&statusFilter=${statusFilter}&pageSize=${size}` + ); + + expectSnapshot(body).toMatch(); + }); + it('can navigate forward and backward using pagination', async () => { const expectedResultsCount = 100; const size = 10;