From cdca6ec1f212e479c8a27bc89fb315dc10fc9bc7 Mon Sep 17 00:00:00 2001 From: Shahzad Date: Mon, 25 May 2020 10:23:55 +0200 Subject: [PATCH] WIK --- .../telemetry/kibana_telemetry_adapter.ts | 7 ++--- .../rest_api/telemetry/log_page_view.ts | 6 ++++- .../apis/uptime/rest/telemetry_collectors.ts | 26 +++++++++++++++++-- 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/x-pack/plugins/uptime/server/lib/adapters/telemetry/kibana_telemetry_adapter.ts b/x-pack/plugins/uptime/server/lib/adapters/telemetry/kibana_telemetry_adapter.ts index 8ce2fb66b510a..fceaed51e892b 100644 --- a/x-pack/plugins/uptime/server/lib/adapters/telemetry/kibana_telemetry_adapter.ts +++ b/x-pack/plugins/uptime/server/lib/adapters/telemetry/kibana_telemetry_adapter.ts @@ -53,10 +53,11 @@ export class KibanaTelemetryAdapter { }); } + public static clearLocalTelemetry() { + this.collector = {}; + } + public static countPageView(pageView: PageViewParams) { - if (pageView.refreshTelemetryHistory) { - this.collector = {}; - } const bucketId = this.getBucketToIncrement(); const bucket = this.collector[bucketId]; if (pageView.page === 'Overview') { diff --git a/x-pack/plugins/uptime/server/rest_api/telemetry/log_page_view.ts b/x-pack/plugins/uptime/server/rest_api/telemetry/log_page_view.ts index d8387e79e9089..9881d41f3bf2b 100644 --- a/x-pack/plugins/uptime/server/rest_api/telemetry/log_page_view.ts +++ b/x-pack/plugins/uptime/server/rest_api/telemetry/log_page_view.ts @@ -29,8 +29,12 @@ export const createLogPageViewRoute: UMRestApiRouteFactory = () => ({ request, response ): Promise => { + const pageView = request.body as PageViewParams; + if (pageView.refreshTelemetryHistory) { + KibanaTelemetryAdapter.clearLocalTelemetry(); + } await KibanaTelemetryAdapter.countNoOfUniqueMonitorAndLocations(callES, savedObjectsClient); - const pageViewResult = KibanaTelemetryAdapter.countPageView(request.body as PageViewParams); + const pageViewResult = KibanaTelemetryAdapter.countPageView(pageView as PageViewParams); return response.ok({ body: pageViewResult, diff --git a/x-pack/test/api_integration/apis/uptime/rest/telemetry_collectors.ts b/x-pack/test/api_integration/apis/uptime/rest/telemetry_collectors.ts index 99e09aa5ce886..ba264adc3299f 100644 --- a/x-pack/test/api_integration/apis/uptime/rest/telemetry_collectors.ts +++ b/x-pack/test/api_integration/apis/uptime/rest/telemetry_collectors.ts @@ -78,13 +78,18 @@ export default function({ getService }: FtrProviderContext) { ); await makeChecksWithStatus(es, 'mixMonitorId', 1, 1, 1, { observer: observer2 }, 'down'); + await es.indices.refresh(); }); after('unload heartbeat index', () => getService('esArchiver').unload('uptime/blank')); - it('should receive expected results after calling monitor/overview logging', async () => { + beforeEach(async () => { + await es.indices.refresh(); + }); + + it('should receive expected results after calling monitor logging', async () => { // call monitor page - await supertest + const { body: result } = await supertest .post(API_URLS.LOG_PAGE_VIEW) .set('kbn-xsrf', 'true') .send({ @@ -97,6 +102,23 @@ export default function({ getService }: FtrProviderContext) { }) .expect(200); + expect(result).to.eql({ + overview_page: 0, + monitor_page: 1, + no_of_unique_monitors: 4, + settings_page: 0, + monitor_frequency: [120, 0.001, 60, 60], + monitor_name_stats: { min_length: 7, max_length: 22, avg_length: 12 }, + no_of_unique_observer_locations: 3, + observer_location_name_stats: { min_length: 2, max_length: 7, avg_length: 4.8 }, + dateRangeStart: ['now/d'], + dateRangeEnd: ['now/d'], + autoRefreshEnabled: true, + autorefreshInterval: [100], + }); + }); + + it('should receive expected results after calling overview logging', async () => { // call overview page const { body: result } = await supertest .post(API_URLS.LOG_PAGE_VIEW)