From 653f3ea0ca07ed20ccd6c8227360b0e55270f7b4 Mon Sep 17 00:00:00 2001 From: Phillip Burch Date: Mon, 6 Jul 2020 13:42:22 -0500 Subject: [PATCH 1/6] Add test for logs and metrics telemetry --- .../components/dropdown_button.tsx | 5 +- .../waffle/waffle_inventory_switcher.tsx | 4 + .../test/functional/apps/infra/home_page.ts | 77 +++++++++++++++++++ .../apps/infra/logs_source_configuration.ts | 39 ++++++++++ .../page_objects/infra_home_page.ts | 23 ++++++ 5 files changed, 147 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/dropdown_button.tsx b/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/dropdown_button.tsx index 6e3ebee2dcb4b..62b25d5a36870 100644 --- a/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/dropdown_button.tsx +++ b/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/dropdown_button.tsx @@ -9,13 +9,15 @@ import React, { ReactNode } from 'react'; import { withTheme, EuiTheme } from '../../../../../../observability/public'; interface Props { + 'data-test-subj'?: string; label: string; onClick: () => void; theme: EuiTheme | undefined; children: ReactNode; } -export const DropdownButton = withTheme(({ onClick, label, theme, children }: Props) => { +export const DropdownButton = withTheme((props: Props) => { + const { onClick, label, theme, children } = props; return ( { id: 'firstPanel', items: [ { + 'data-test-subj': 'goToHost', name: getDisplayNameForType('host'), onClick: goToHost, }, { + 'data-test-subj': 'goToPods', name: getDisplayNameForType('pod'), onClick: goToK8, }, { + 'data-test-subj': 'goToDocker', name: getDisplayNameForType('container'), onClick: goToDocker, }, @@ -117,6 +120,7 @@ export const WaffleInventorySwitcher: React.FC = () => { const button = ( diff --git a/x-pack/test/functional/apps/infra/home_page.ts b/x-pack/test/functional/apps/infra/home_page.ts index 28279d5e5b812..d44c716942892 100644 --- a/x-pack/test/functional/apps/infra/home_page.ts +++ b/x-pack/test/functional/apps/infra/home_page.ts @@ -4,15 +4,22 @@ * you may not use this file except in compliance with the Elastic License. */ +import moment from 'moment'; +import expect from '@kbn/expect/expect.js'; import { FtrProviderContext } from '../../ftr_provider_context'; import { DATES } from './constants'; const DATE_WITH_DATA = DATES.metricsAndLogs.hosts.withData; const DATE_WITHOUT_DATA = DATES.metricsAndLogs.hosts.withoutData; +const COMMON_REQUEST_HEADERS = { + 'kbn-xsrf': 'some-xsrf-token', +}; + export default ({ getPageObjects, getService }: FtrProviderContext) => { const esArchiver = getService('esArchiver'); const pageObjects = getPageObjects(['common', 'infraHome']); + const supertest = getService('supertest'); describe('Home page', function () { this.tags('includeFirefox'); @@ -46,6 +53,76 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { await pageObjects.infraHome.goToTime(DATE_WITHOUT_DATA); await pageObjects.infraHome.getNoMetricsDataPrompt(); }); + + it('records telemetry for hosts', async () => { + await pageObjects.infraHome.goToTime(DATE_WITH_DATA); + await pageObjects.infraHome.getWaffleMap(); + + const resp = await supertest + .post(`/api/telemetry/v2/clusters/_stats`) + .set(COMMON_REQUEST_HEADERS) + .set('Accept', 'application/json') + .send({ + timeRange: { + min: moment().subtract(1, 'hour').toISOString(), + max: moment().toISOString(), + }, + unencrypted: true, + }) + .expect(200) + .then((res: any) => res.body); + + expect( + resp[0].stack_stats.kibana.plugins.infraops.last_24_hours.hits.infraops_hosts + ).to.be.greaterThan(0); + }); + + it('records telemetry for docker', async () => { + await pageObjects.infraHome.goToTime(DATE_WITH_DATA); + await pageObjects.infraHome.getWaffleMap(); + await pageObjects.infraHome.goToDocker(); + + const resp = await supertest + .post(`/api/telemetry/v2/clusters/_stats`) + .set(COMMON_REQUEST_HEADERS) + .set('Accept', 'application/json') + .send({ + timeRange: { + min: moment().subtract(1, 'hour').toISOString(), + max: moment().toISOString(), + }, + unencrypted: true, + }) + .expect(200) + .then((res: any) => res.body); + + expect( + resp[0].stack_stats.kibana.plugins.infraops.last_24_hours.hits.infraops_docker + ).to.be.greaterThan(0); + }); + }); + + it('records telemetry for kubernetes', async () => { + await pageObjects.infraHome.goToTime(DATE_WITH_DATA); + await pageObjects.infraHome.goToPods(); + + const resp = await supertest + .post(`/api/telemetry/v2/clusters/_stats`) + .set(COMMON_REQUEST_HEADERS) + .set('Accept', 'application/json') + .send({ + timeRange: { + min: moment().subtract(1, 'hour').toISOString(), + max: moment().toISOString(), + }, + unencrypted: true, + }) + .expect(200) + .then((res: any) => res.body); + + expect( + resp[0].stack_stats.kibana.plugins.infraops.last_24_hours.hits.infraops_kubernetes + ).to.be.greaterThan(0); }); }); }; diff --git a/x-pack/test/functional/apps/infra/logs_source_configuration.ts b/x-pack/test/functional/apps/infra/logs_source_configuration.ts index 7ec06e74289c9..8775e7a939eb7 100644 --- a/x-pack/test/functional/apps/infra/logs_source_configuration.ts +++ b/x-pack/test/functional/apps/infra/logs_source_configuration.ts @@ -5,16 +5,26 @@ */ import expect from '@kbn/expect'; +import moment from 'moment'; import { DATES } from './constants'; import { FtrProviderContext } from '../../ftr_provider_context'; +const COMMON_REQUEST_HEADERS = { + 'kbn-xsrf': 'some-xsrf-token', +}; + +function timeout(ms) { + return new Promise((resolve) => setTimeout(resolve, ms)); +} + export default ({ getPageObjects, getService }: FtrProviderContext) => { const esArchiver = getService('esArchiver'); const logsUi = getService('logsUi'); const infraSourceConfigurationForm = getService('infraSourceConfigurationForm'); const pageObjects = getPageObjects(['common', 'infraLogs']); const retry = getService('retry'); + const supertest = getService('supertest'); describe('Logs Source Configuration', function () { before(async () => { @@ -97,6 +107,35 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { expect(logStreamEntryColumns).to.have.length(3); }); + it('records telemetry for logs', async () => { + await logsUi.logStreamPage.navigateTo({ + logPosition: { + start: DATES.metricsAndLogs.stream.startWithData, + end: DATES.metricsAndLogs.stream.endWithData, + }, + }); + + await logsUi.logStreamPage.getStreamEntries(); + + const resp = await supertest + .post(`/api/telemetry/v2/clusters/_stats`) + .set(COMMON_REQUEST_HEADERS) + .set('Accept', 'application/json') + .send({ + timeRange: { + min: moment().subtract(1, 'hour').toISOString(), + max: moment().toISOString(), + }, + unencrypted: true, + }) + .expect(200) + .then((res: any) => res.body); + + expect( + resp[0].stack_stats.kibana.plugins.infraops.last_24_hours.hits.logs + ).to.be.greaterThan(0); + }); + it('can change the log columns', async () => { await pageObjects.infraLogs.navigateToTab('settings'); diff --git a/x-pack/test/functional/page_objects/infra_home_page.ts b/x-pack/test/functional/page_objects/infra_home_page.ts index 51dad594f21f5..ef6d2dc02eb80 100644 --- a/x-pack/test/functional/page_objects/infra_home_page.ts +++ b/x-pack/test/functional/page_objects/infra_home_page.ts @@ -33,6 +33,29 @@ export function InfraHomePageProvider({ getService }: FtrProviderContext) { return await testSubjects.find('waffleMap'); }, + async openInvenotrySwitcher() { + await testSubjects.click('openInventorySwitcher'); + return await testSubjects.find('goToHost'); + }, + + async goToHost() { + await testSubjects.click('openInventorySwitcher'); + await testSubjects.find('goToHost'); + return await testSubjects.click('goToHost'); + }, + + async goToPods() { + await testSubjects.click('openInventorySwitcher'); + await testSubjects.find('goToHost'); + return await testSubjects.click('goToPods'); + }, + + async goToDocker() { + await testSubjects.click('openInventorySwitcher'); + await testSubjects.find('goToHost'); + return await testSubjects.click('goToDocker'); + }, + async goToMetricExplorer() { return await testSubjects.click('infrastructureNavLink_/infrastructure/metrics-explorer'); }, From f00af0b84de910a04716849396a05a0dbae25c85 Mon Sep 17 00:00:00 2001 From: Phillip Burch Date: Mon, 6 Jul 2020 14:45:28 -0500 Subject: [PATCH 2/6] wait before you go --- x-pack/test/functional/apps/infra/home_page.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/x-pack/test/functional/apps/infra/home_page.ts b/x-pack/test/functional/apps/infra/home_page.ts index d44c716942892..5f010f99da4b9 100644 --- a/x-pack/test/functional/apps/infra/home_page.ts +++ b/x-pack/test/functional/apps/infra/home_page.ts @@ -104,6 +104,7 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { it('records telemetry for kubernetes', async () => { await pageObjects.infraHome.goToTime(DATE_WITH_DATA); + await pageObjects.infraHome.getWaffleMap(); await pageObjects.infraHome.goToPods(); const resp = await supertest From d982662659520271355aeedf0f1e12206dbac4c0 Mon Sep 17 00:00:00 2001 From: Phillip Burch Date: Mon, 6 Jul 2020 17:20:18 -0500 Subject: [PATCH 3/6] Remove kubenetes --- .../test/functional/apps/infra/home_page.ts | 24 ------------------- 1 file changed, 24 deletions(-) diff --git a/x-pack/test/functional/apps/infra/home_page.ts b/x-pack/test/functional/apps/infra/home_page.ts index 5f010f99da4b9..04f289b69bb71 100644 --- a/x-pack/test/functional/apps/infra/home_page.ts +++ b/x-pack/test/functional/apps/infra/home_page.ts @@ -101,29 +101,5 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { ).to.be.greaterThan(0); }); }); - - it('records telemetry for kubernetes', async () => { - await pageObjects.infraHome.goToTime(DATE_WITH_DATA); - await pageObjects.infraHome.getWaffleMap(); - await pageObjects.infraHome.goToPods(); - - const resp = await supertest - .post(`/api/telemetry/v2/clusters/_stats`) - .set(COMMON_REQUEST_HEADERS) - .set('Accept', 'application/json') - .send({ - timeRange: { - min: moment().subtract(1, 'hour').toISOString(), - max: moment().toISOString(), - }, - unencrypted: true, - }) - .expect(200) - .then((res: any) => res.body); - - expect( - resp[0].stack_stats.kibana.plugins.infraops.last_24_hours.hits.infraops_kubernetes - ).to.be.greaterThan(0); - }); }); }; From 0982567bbf60f9487b5e60a3a11e70c0e14f7f14 Mon Sep 17 00:00:00 2001 From: Phillip Burch Date: Mon, 6 Jul 2020 17:24:24 -0500 Subject: [PATCH 4/6] Fix type check --- .../test/functional/apps/infra/logs_source_configuration.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/x-pack/test/functional/apps/infra/logs_source_configuration.ts b/x-pack/test/functional/apps/infra/logs_source_configuration.ts index 8775e7a939eb7..04ffcc4847d54 100644 --- a/x-pack/test/functional/apps/infra/logs_source_configuration.ts +++ b/x-pack/test/functional/apps/infra/logs_source_configuration.ts @@ -14,10 +14,6 @@ const COMMON_REQUEST_HEADERS = { 'kbn-xsrf': 'some-xsrf-token', }; -function timeout(ms) { - return new Promise((resolve) => setTimeout(resolve, ms)); -} - export default ({ getPageObjects, getService }: FtrProviderContext) => { const esArchiver = getService('esArchiver'); const logsUi = getService('logsUi'); From 5b1f83c96d7e7c2208094db5a8090c6e590e88e5 Mon Sep 17 00:00:00 2001 From: Phillip Burch Date: Mon, 6 Jul 2020 17:27:32 -0500 Subject: [PATCH 5/6] Add back kubernetes test --- .../test/functional/apps/infra/home_page.ts | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/x-pack/test/functional/apps/infra/home_page.ts b/x-pack/test/functional/apps/infra/home_page.ts index 04f289b69bb71..2666f5dfeaccc 100644 --- a/x-pack/test/functional/apps/infra/home_page.ts +++ b/x-pack/test/functional/apps/infra/home_page.ts @@ -100,6 +100,30 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { resp[0].stack_stats.kibana.plugins.infraops.last_24_hours.hits.infraops_docker ).to.be.greaterThan(0); }); + + it('records telemetry for kubernetes', async () => { + await pageObjects.infraHome.goToTime(DATE_WITH_DATA); + await pageObjects.infraHome.getWaffleMap(); + await pageObjects.infraHome.goToPods(); + + const resp = await supertest + .post(`/api/telemetry/v2/clusters/_stats`) + .set(COMMON_REQUEST_HEADERS) + .set('Accept', 'application/json') + .send({ + timeRange: { + min: moment().subtract(1, 'hour').toISOString(), + max: moment().toISOString(), + }, + unencrypted: true, + }) + .expect(200) + .then((res: any) => res.body); + + expect( + resp[0].stack_stats.kibana.plugins.infraops.last_24_hours.hits.infraops_kubernetes + ).to.be.greaterThan(0); + }); }); }); }; From e5632e762ec347e3147c531774088bec48e11fcc Mon Sep 17 00:00:00 2001 From: Phillip Burch Date: Mon, 6 Jul 2020 20:28:16 -0500 Subject: [PATCH 6/6] Remove kubernetes --- .../test/functional/apps/infra/home_page.ts | 24 ------------------- 1 file changed, 24 deletions(-) diff --git a/x-pack/test/functional/apps/infra/home_page.ts b/x-pack/test/functional/apps/infra/home_page.ts index 2666f5dfeaccc..04f289b69bb71 100644 --- a/x-pack/test/functional/apps/infra/home_page.ts +++ b/x-pack/test/functional/apps/infra/home_page.ts @@ -100,30 +100,6 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { resp[0].stack_stats.kibana.plugins.infraops.last_24_hours.hits.infraops_docker ).to.be.greaterThan(0); }); - - it('records telemetry for kubernetes', async () => { - await pageObjects.infraHome.goToTime(DATE_WITH_DATA); - await pageObjects.infraHome.getWaffleMap(); - await pageObjects.infraHome.goToPods(); - - const resp = await supertest - .post(`/api/telemetry/v2/clusters/_stats`) - .set(COMMON_REQUEST_HEADERS) - .set('Accept', 'application/json') - .send({ - timeRange: { - min: moment().subtract(1, 'hour').toISOString(), - max: moment().toISOString(), - }, - unencrypted: true, - }) - .expect(200) - .then((res: any) => res.body); - - expect( - resp[0].stack_stats.kibana.plugins.infraops.last_24_hours.hits.infraops_kubernetes - ).to.be.greaterThan(0); - }); }); }); };