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

[Stack Monitoring] install packages before test suite runs #165881

Merged
merged 3 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion x-pack/test/monitoring_api_integration/apis/apm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
*/

import { FtrProviderContext } from '../../../api_integration/ftr_provider_context';
import { installPackage } from '../../packages';

export default function ({ loadTestFile }: FtrProviderContext) {
export default function ({ loadTestFile, getService }: FtrProviderContext) {
describe('APM', () => {
before(() => installPackage(getService('supertest'), 'beat'));

loadTestFile(require.resolve('./overview'));
loadTestFile(require.resolve('./instances'));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
*/

import { FtrProviderContext } from '../../../api_integration/ftr_provider_context';
import { installPackage } from '../../packages';

export default function ({ loadTestFile }: FtrProviderContext) {
export default function ({ loadTestFile, getService }: FtrProviderContext) {
describe('Beats', () => {
before(() => installPackage(getService('supertest'), 'beat'));

loadTestFile(require.resolve('./overview'));
loadTestFile(require.resolve('./beats'));
loadTestFile(require.resolve('./beat'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
*/

import { FtrProviderContext } from '../../../api_integration/ftr_provider_context';
import { installPackage } from '../../packages';

export default function ({ loadTestFile }: FtrProviderContext) {
export default function ({ loadTestFile, getService }: FtrProviderContext) {
describe('Elasticsearch', () => {
before(() => installPackage(getService('supertest'), 'elasticsearch'));

loadTestFile(require.resolve('./ccr'));
loadTestFile(require.resolve('./indices'));
loadTestFile(require.resolve('./ml_jobs'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
*/

import { FtrProviderContext } from '../../../api_integration/ftr_provider_context';
import { installPackage } from '../../packages';

export default function ({ loadTestFile }: FtrProviderContext) {
export default function ({ loadTestFile, getService }: FtrProviderContext) {
describe('Enterprisesearch', () => {
before(() => installPackage(getService('supertest'), 'enterprisesearch'));

loadTestFile(require.resolve('./overview'));
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
*/

import { FtrProviderContext } from '../../../api_integration/ftr_provider_context';
import { installPackage } from '../../packages';

export default function ({ loadTestFile }: FtrProviderContext) {
export default function ({ loadTestFile, getService }: FtrProviderContext) {
describe('Kibana', () => {
before(() => installPackage(getService('supertest'), 'kibana'));

loadTestFile(require.resolve('./overview'));
loadTestFile(require.resolve('./instances'));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
*/

import { FtrProviderContext } from '../../../api_integration/ftr_provider_context';
import { installPackage } from '../../packages';

export default function ({ loadTestFile }: FtrProviderContext) {
export default function ({ loadTestFile, getService }: FtrProviderContext) {
describe('Logstash', () => {
before(() => installPackage(getService('supertest'), 'logstash'));

loadTestFile(require.resolve('./overview'));
loadTestFile(require.resolve('./nodes'));
loadTestFile(require.resolve('./pipelines'));
Expand Down
8 changes: 1 addition & 7 deletions x-pack/test/monitoring_api_integration/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

import { FtrConfigProviderContext } from '@kbn/test';

import { bundledPackagesLocation, getPackagesArgs } from './packages';

export default async function ({ readConfigFile }: FtrConfigProviderContext) {
const xPackAPITestsConfig = await readConfigFile(require.resolve('../api_integration/config.ts'));

Expand All @@ -22,11 +20,7 @@ export default async function ({ readConfigFile }: FtrConfigProviderContext) {
esTestCluster: xPackAPITestsConfig.get('esTestCluster'),
kbnTestServer: {
...xPackAPITestsConfig.get('kbnTestServer'),
serverArgs: [
...xPackAPITestsConfig.get('kbnTestServer.serverArgs'),
`--xpack.fleet.developer.bundledPackageLocation=${bundledPackagesLocation}`,
...getPackagesArgs(),
],
serverArgs: [...xPackAPITestsConfig.get('kbnTestServer.serverArgs')],
},
};
}
27 changes: 27 additions & 0 deletions x-pack/test/monitoring_api_integration/packages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
*/

import path from 'path';
import { createReadStream } from 'fs';
import type SuperTest from 'supertest';

type SupportedPackage = 'beat' | 'elasticsearch' | 'enterprisesearch' | 'logstash' | 'kibana';

const PACKAGES = [
{ name: 'beat', version: '0.1.3' },
Expand All @@ -25,3 +29,26 @@ export const getPackagesArgs = (): string[] => {
};

export const bundledPackagesLocation = path.join(path.dirname(__filename), '/fixtures/packages');

export function installPackage(
supertest: SuperTest.SuperTest<SuperTest.Test>,
packageName: SupportedPackage
) {
const pkg = PACKAGES.find(({ name }) => name === packageName);
const request = supertest
.post('/api/fleet/epm/packages')
.set('kbn-xsrf', 'xxx')
.set('content-type', 'application/zip');

return new Promise<void>((resolve, reject) => {
createReadStream(path.join(bundledPackagesLocation, `${pkg!.name}-${pkg!.version}.zip`))
.on('data', (chunk) => request.write(chunk))
.on('end', () => {
request
.send()
.expect(200)
.then(() => resolve())
.catch(reject);
});
});
}