Skip to content

Commit

Permalink
added some e2e test for container details view
Browse files Browse the repository at this point in the history
  • Loading branch information
MiriamAparicio committed May 13, 2024
1 parent 7753742 commit a69a97b
Show file tree
Hide file tree
Showing 10 changed files with 217 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export const DockerCharts = React.forwardRef<HTMLDivElement, Props>(
}
/>
}
data-test-subj="infraAssetDetailsDockerContainerChartsSection${metric}"
data-test-subj={`infraAssetDetailsDockerChartsSection${metric}`}
id="dockerContainerCharts"
ref={ref}
>
Expand Down
2 changes: 2 additions & 0 deletions x-pack/test/common/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { InfraLogViewsServiceProvider } from './infra_log_views';
import { SpacesServiceProvider } from './spaces';
import { BsearchSecureService } from './bsearch_secure';
import { ApmSynthtraceKibanaClientProvider } from './apm_synthtrace_kibana_client';
import { InfraSynthtraceKibanaClientProvider } from './infra_synthtrace_kibana_client';

export const services = {
...kibanaCommonServices,
Expand All @@ -19,4 +20,5 @@ export const services = {
spaces: SpacesServiceProvider,
secureBsearch: BsearchSecureService,
apmSynthtraceKibanaClient: ApmSynthtraceKibanaClientProvider,
infraSynthtraceKibanaClient: InfraSynthtraceKibanaClientProvider,
};
37 changes: 37 additions & 0 deletions x-pack/test/common/services/infra_synthtrace_kibana_client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import url from 'url';
import { kbnTestConfig } from '@kbn/test';
import { InfraSynthtraceKibanaClient, createLogger, LogLevel } from '@kbn/apm-synthtrace';

const getKibanaServerUrlWithAuth = () => {
const kibanaServerUrl = url.format(kbnTestConfig.getUrlParts() as url.UrlObject);
const kibanaServerUrlWithAuth = url
.format({
...url.parse(kibanaServerUrl),
auth: `elastic:${kbnTestConfig.getUrlParts().password}`,
})
.slice(0, -1);
return kibanaServerUrlWithAuth;
};

export function InfraSynthtraceKibanaClientProvider() {
const kibanaServerUrlWithAuth = getKibanaServerUrlWithAuth();
const target = kibanaServerUrlWithAuth;
const logger = createLogger(LogLevel.debug);
const username = 'elastic';
const password = kbnTestConfig.getUrlParts().password || 'changeme';
const kibanaClient = new InfraSynthtraceKibanaClient({
target,
logger,
username,
password,
});

return kibanaClient;
}
17 changes: 17 additions & 0 deletions x-pack/test/common/utils/synthtrace/infra_es_client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { Client } from '@elastic/elasticsearch';
import { InfraSynthtraceEsClient, createLogger, LogLevel } from '@kbn/apm-synthtrace';

export async function getInfraSynthtraceEsClient(client: Client) {
return new InfraSynthtraceEsClient({
client,
logger: createLogger(LogLevel.info),
refreshAfterIndex: true,
});
}
6 changes: 5 additions & 1 deletion x-pack/test/functional/apps/infra/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ export const ML_JOB_IDS = [
export const HOSTS_LINK_LOCAL_STORAGE_KEY = 'inventoryUI:hostsLinkClicked';

export const INVENTORY_PATH = 'metrics/inventory';
export const NODE_DETAILS_PATH = 'detail/host';
export const NODE_DETAILS_PATH = 'detail';
export const HOSTS_VIEW_PATH = 'metrics/hosts';

export const DATE_PICKER_FORMAT = 'MMM D, YYYY @ HH:mm:ss.SSS';

export const DATE_WITH_DOCKER_DATA_FROM = '2023-03-28T18:20:00.000Z';
export const DATE_WITH_DOCKER_DATA_TO = '2023-03-28T18:21:00.000Z';
export const DATE_WITH_DOCKER_DATA = '03/28/2023 6:20:59 PM';
25 changes: 24 additions & 1 deletion x-pack/test/functional/apps/infra/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { apm, timerange } from '@kbn/apm-synthtrace-client';
import { apm, timerange, infra } from '@kbn/apm-synthtrace-client';

const SERVICE_PREFIX = 'service';
// generates traces, metrics for services
Expand Down Expand Up @@ -46,3 +46,26 @@ export function generateAddServicesToExistingHost({
)
);
}

export function generateDockerContainersData({
from,
to,
count = 1,
}: {
from: string;
to: string;
count?: number;
}) {
const range = timerange(from, to);

const containers = Array(count)
.fill(0)
.map((_, idx) => infra.dockerContainer(`container-id-${idx}`));

return range
.interval('30s')
.rate(1)
.generator((timestamp) =>
containers.flatMap((container) => container.metrics().timestamp(timestamp))
);
}
46 changes: 45 additions & 1 deletion x-pack/test/functional/apps/infra/home_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,25 @@
import expect from '@kbn/expect';
import { parse } from 'url';
import { KUBERNETES_TOUR_STORAGE_KEY } from '@kbn/infra-plugin/public/pages/metrics/inventory_view/components/kubernetes_tour';
import { InfraSynthtraceEsClient } from '@kbn/apm-synthtrace';
import { FtrProviderContext } from '../../ftr_provider_context';
import { DATES, INVENTORY_PATH } from './constants';
import { generateDockerContainersData } from './helpers';
import { getInfraSynthtraceEsClient } from '../../../common/utils/synthtrace/infra_es_client';

const DATE_WITH_DATA = DATES.metricsAndLogs.hosts.withData;
const DATE_WITHOUT_DATA = DATES.metricsAndLogs.hosts.withoutData;
const DATE_WITH_POD_WITH_DATA = DATES.metricsAndLogs.pods.withData;
const DATE_WITH_DOCKER_DATA_FROM = '2023-03-28T18:20:00.000Z';
const DATE_WITH_DOCKER_DATA_TO = '2023-03-28T18:21:00.000Z';
const DATE_WITH_DOCKER_DATA = '03/28/2023 6:20:00 PM';

export default ({ getPageObjects, getService }: FtrProviderContext) => {
const esArchiver = getService('esArchiver');
const browser = getService('browser');
const retry = getService('retry');
const esClient = getService('es');
const infraSynthtraceKibanaClient = getService('infraSynthtraceKibanaClient');
const pageObjects = getPageObjects([
'common',
'header',
Expand Down Expand Up @@ -74,6 +82,7 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
before(async () => {
await esArchiver.load('x-pack/test/functional/es_archives/infra/metrics_and_logs');
await esArchiver.load('x-pack/test/functional/es_archives/infra/8.0.0/pods_only');
await esArchiver.load('x-pack/test/functional/es_archives/infra/6.6.0/docker');
await pageObjects.common.navigateToApp('infraOps');
await pageObjects.infraHome.waitForLoading();
});
Expand Down Expand Up @@ -355,7 +364,7 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
await returnTo(INVENTORY_PATH);
});

it('Should redirect to Node Details page', async () => {
it('Should redirect to Pod Details page', async () => {
await pageObjects.infraHome.goToPods();
await pageObjects.infraHome.goToTime(DATE_WITH_POD_WITH_DATA);
await pageObjects.infraHome.clickOnFirstNode();
Expand All @@ -370,6 +379,41 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {

await returnTo(INVENTORY_PATH);
});

describe('Redirect to Container Details page', () => {
let synthEsClient: InfraSynthtraceEsClient;
before(async () => {
const version = await infraSynthtraceKibanaClient.fetchLatestSystemPackageVersion();
await infraSynthtraceKibanaClient.installSystemPackage(version);
synthEsClient = await getInfraSynthtraceEsClient(esClient);
await synthEsClient.index(
generateDockerContainersData({
from: DATE_WITH_DOCKER_DATA_FROM,
to: DATE_WITH_DOCKER_DATA_TO,
count: 5,
})
);
});

after(async () => {
return await synthEsClient.clean();
});
it('Should redirect to Container Details page', async () => {
await pageObjects.infraHome.goToContainer();
await pageObjects.infraHome.goToTime(DATE_WITH_DOCKER_DATA);
await pageObjects.infraHome.clickOnFirstNode();
await pageObjects.infraHome.clickOnGoToNodeDetails();

await retry.try(async () => {
const documentTitle = await browser.getTitle();
expect(documentTitle).to.contain(
'container-id-4 - Inventory - Infrastructure - Observability - Elastic'
);
});

await returnTo(INVENTORY_PATH);
});
});
});
});

Expand Down
84 changes: 75 additions & 9 deletions x-pack/test/functional/apps/infra/node_details.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,23 @@

import moment from 'moment';
import expect from '@kbn/expect';
import { InfraSynthtraceEsClient } from '@kbn/apm-synthtrace';
import { enableInfrastructureProfilingIntegration } from '@kbn/observability-plugin/common';
import {
ALERT_STATUS_ACTIVE,
ALERT_STATUS_RECOVERED,
ALERT_STATUS_UNTRACKED,
} from '@kbn/rule-data-utils';
import { FtrProviderContext } from '../../ftr_provider_context';
import { DATES, NODE_DETAILS_PATH, DATE_PICKER_FORMAT } from './constants';
import {
DATES,
NODE_DETAILS_PATH,
DATE_PICKER_FORMAT,
DATE_WITH_DOCKER_DATA_FROM,
DATE_WITH_DOCKER_DATA_TO,
} from './constants';
import { getInfraSynthtraceEsClient } from '../../../common/utils/synthtrace/infra_es_client';
import { generateDockerContainersData } from './helpers';

const START_HOST_ALERTS_DATE = moment.utc(DATES.metricsAndLogs.hosts.min);
const END_HOST_ALERTS_DATE = moment.utc(DATES.metricsAndLogs.hosts.max);
Expand All @@ -32,6 +41,8 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
const browser = getService('browser');
const kibanaServer = getService('kibanaServer');
const esArchiver = getService('esArchiver');
const infraSynthtraceKibanaClient = getService('infraSynthtraceKibanaClient');
const esClient = getService('es');
const retry = getService('retry');
const testSubjects = getService('testSubjects');
const pageObjects = getPageObjects([
Expand All @@ -50,10 +61,10 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
return queryParams.toString();
};

const navigateToNodeDetails = async (assetId: string, assetName: string) => {
const navigateToNodeDetails = async (assetId: string, assetName: string, assetType: string) => {
await pageObjects.common.navigateToUrlWithBrowserHistory(
'infraOps',
`/${NODE_DETAILS_PATH}/${assetId}`,
`/${NODE_DETAILS_PATH}/${assetType}/${assetId}`,
getNodeDetailsUrl(assetName),
{
insertTimestamp: false,
Expand Down Expand Up @@ -90,7 +101,7 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
]);
await browser.setWindowSize(1600, 1200);

await navigateToNodeDetails('Jennys-MBP.fritz.box', 'Jennys-MBP.fritz.box');
await navigateToNodeDetails('Jennys-MBP.fritz.box', 'Jennys-MBP.fritz.box', 'host');
await pageObjects.header.waitUntilLoadingHasFinished();
});

Expand All @@ -102,7 +113,7 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
]);
});

describe('#Date picker', () => {
describe('#Date picker: host', () => {
before(async () => {
await pageObjects.assetDetails.clickOverviewTab();

Expand Down Expand Up @@ -247,7 +258,7 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
const ALL_ALERTS = ACTIVE_ALERTS + RECOVERED_ALERTS;
const COLUMNS = 11;
before(async () => {
await navigateToNodeDetails('demo-stack-apache-01', 'demo-stack-apache-01');
await navigateToNodeDetails('demo-stack-apache-01', 'demo-stack-apache-01', 'host');
await pageObjects.header.waitUntilLoadingHasFinished();

await pageObjects.timePicker.setAbsoluteRange(
Expand All @@ -259,7 +270,7 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
});

after(async () => {
await navigateToNodeDetails('Jennys-MBP.fritz.box', 'Jennys-MBP.fritz.box');
await navigateToNodeDetails('Jennys-MBP.fritz.box', 'Jennys-MBP.fritz.box', 'host');
await pageObjects.header.waitUntilLoadingHasFinished();

await pageObjects.timePicker.setAbsoluteRange(
Expand Down Expand Up @@ -482,7 +493,7 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {

describe('Host with alerts and no processes', () => {
before(async () => {
await navigateToNodeDetails('demo-stack-mysql-01', 'demo-stack-mysql-01');
await navigateToNodeDetails('demo-stack-mysql-01', 'demo-stack-mysql-01', 'host');
await pageObjects.timePicker.setAbsoluteRange(
START_HOST_ALERTS_DATE.format(DATE_PICKER_FORMAT),
END_HOST_ALERTS_DATE.format(DATE_PICKER_FORMAT)
Expand Down Expand Up @@ -516,7 +527,11 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {

describe('#With Kubernetes section', () => {
before(async () => {
await navigateToNodeDetails('demo-stack-kubernetes-01', 'demo-stack-kubernetes-01');
await navigateToNodeDetails(
'demo-stack-kubernetes-01',
'demo-stack-kubernetes-01',
'host'
);
await pageObjects.header.waitUntilLoadingHasFinished();
});

Expand Down Expand Up @@ -597,6 +612,57 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
});
});
});

describe('#Asset Type: container', () => {
let synthEsClient: InfraSynthtraceEsClient;
before(async () => {
const version = await infraSynthtraceKibanaClient.fetchLatestSystemPackageVersion();
await infraSynthtraceKibanaClient.installSystemPackage(version);
synthEsClient = await getInfraSynthtraceEsClient(esClient);
await synthEsClient.index(
generateDockerContainersData({
from: DATE_WITH_DOCKER_DATA_FROM,
to: DATE_WITH_DOCKER_DATA_TO,
count: 1,
})
);
});

after(async () => {
await synthEsClient.clean();
});

it('should render container overview tab', async () => {
await navigateToNodeDetails('container-id-1', 'container-id-1', 'container');
await pageObjects.header.waitUntilLoadingHasFinished();

await pageObjects.assetDetails.clickOverviewTab();
});
// Add this test after implementing the creation of metadata for containers in sythtrace
// [
// { metric: 'cpuUsage', value: '13.9%' },
// { metric: 'memoryUsage', value: '94.9%' },
// ].forEach(({ metric, value }) => {
// it(`${metric} tile should show ${value}`, async () => {
// await retry.tryForTime(3 * 1000, async () => {
// const tileValue = await pageObjects.assetDetails.getAssetDetailsKPITileValue(metric);
// expect(tileValue).to.eql(value);
// });
// });
// });

[
{ metric: 'cpu', chartsCount: 1 },
{ metric: 'memory', chartsCount: 1 },
].forEach(({ metric, chartsCount }) => {
it(`should render ${chartsCount} ${metric} chart(s) in the Metrics section`, async () => {
const containers = await pageObjects.assetDetails.getOverviewTabDockerMetricCharts(
metric
);
expect(containers.length).to.equal(chartsCount);
});
});
});
});
});
};
9 changes: 9 additions & 0 deletions x-pack/test/functional/page_objects/asset_details.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,15 @@ export function AssetDetailsProvider({ getService }: FtrProviderContext) {
return section.findAllByCssSelector('[data-test-subj*="infraAssetDetailsMetricChart"]');
},

async getOverviewTabDockerMetricCharts(metric: string) {
const container = await testSubjects.find('infraAssetDetailsOverviewTabContent');
const section = await container.findByTestSubject(
`infraAssetDetailsDockerChartsSection${metric}`
);

return section.findAllByCssSelector('[data-test-subj*="infraAssetDetailsMetricChart"]');
},

async getOverviewTabKubernetesMetricCharts() {
const container = await testSubjects.find('infraAssetDetailsOverviewTabContent');
const section = await container.findByTestSubject(`infraAssetDetailsKubernetesChartsSection`);
Expand Down
Loading

0 comments on commit a69a97b

Please sign in to comment.