Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Metrics + Logs UI] Add test for logs and metrics telemetry #70858

Merged
merged 10 commits into from
Jul 13, 2020
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<EuiFlexGroup
alignItems="center"
Expand All @@ -39,6 +41,7 @@ export const DropdownButton = withTheme(({ onClick, label, theme, children }: Pr
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiButtonEmpty
data-test-subj={props['data-test-subj']}
color="text"
iconType="arrowDown"
onClick={onClick}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,17 @@ export const WaffleInventorySwitcher: React.FC = () => {
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,
},
Expand Down Expand Up @@ -117,6 +120,7 @@ export const WaffleInventorySwitcher: React.FC = () => {

const button = (
<DropdownButton
data-test-subj={'openInventorySwitcher'}
onClick={openPopover}
label={i18n.translate('xpack.infra.waffle.showLabel', { defaultMessage: 'Show' })}
>
Expand Down
54 changes: 54 additions & 0 deletions x-pack/test/functional/apps/infra/home_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -46,6 +53,53 @@ 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);
});
});
});
};
35 changes: 35 additions & 0 deletions x-pack/test/functional/apps/infra/logs_source_configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,22 @@
*/

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',
};

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 () => {
Expand Down Expand Up @@ -97,6 +103,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');

Expand Down
23 changes: 23 additions & 0 deletions x-pack/test/functional/page_objects/infra_home_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
},
Expand Down