diff --git a/x-pack/scripts/functional_tests.js b/x-pack/scripts/functional_tests.js index 0a022694655d0..ccd756283a4ff 100644 --- a/x-pack/scripts/functional_tests.js +++ b/x-pack/scripts/functional_tests.js @@ -7,8 +7,6 @@ require('@kbn/plugin-helpers').babelRegister(); require('@kbn/test').runTestsCli([ - require.resolve('../test/reporting/configs/chromium_api.js'), - require.resolve('../test/reporting/configs/generate_api'), require.resolve('../test/functional/config.js'), require.resolve('../test/functional_with_es_ssl/config.ts'), require.resolve('../test/functional/config_security_basic.ts'), @@ -50,4 +48,5 @@ require('@kbn/test').runTestsCli([ require.resolve('../test/licensing_plugin/config.public'), require.resolve('../test/licensing_plugin/config.legacy'), require.resolve('../test/endpoint_api_integration_no_ingest/config.ts'), + require.resolve('../test/reporting_api_integration/config.js'), ]); diff --git a/x-pack/test/reporting/.gitignore b/x-pack/test/reporting/.gitignore deleted file mode 100644 index 99ee4c44686a0..0000000000000 --- a/x-pack/test/reporting/.gitignore +++ /dev/null @@ -1 +0,0 @@ -functional/reports/session/ diff --git a/x-pack/test/reporting/api/chromium_tests.ts b/x-pack/test/reporting/api/chromium_tests.ts deleted file mode 100644 index 107e04115092a..0000000000000 --- a/x-pack/test/reporting/api/chromium_tests.ts +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import { OSS_DATA_ARCHIVE_PATH, OSS_KIBANA_ARCHIVE_PATH } from './constants'; -import { FtrProviderContext } from '../ftr_provider_context'; - -// eslint-disable-next-line import/no-default-export -export default function({ loadTestFile, getService }: FtrProviderContext) { - const esArchiver = getService('esArchiver'); - const kibanaServer = getService('kibanaServer'); - - describe('chromium', function() { - this.tags('ciGroup2'); - - before(async () => { - await esArchiver.load(OSS_KIBANA_ARCHIVE_PATH); - await esArchiver.load(OSS_DATA_ARCHIVE_PATH); - - await kibanaServer.uiSettings.update({ - defaultIndex: '0bf35f60-3dc9-11e8-8660-4d65aa086b3c', - }); - }); - - after(async () => { - await esArchiver.unload(OSS_KIBANA_ARCHIVE_PATH); - await esArchiver.unload(OSS_DATA_ARCHIVE_PATH); - }); - - loadTestFile(require.resolve('./bwc_existing_indexes')); - loadTestFile(require.resolve('./bwc_generation_urls')); - loadTestFile(require.resolve('./usage')); - }); -} diff --git a/x-pack/test/reporting/configs/chromium_api.js b/x-pack/test/reporting/configs/chromium_api.js deleted file mode 100644 index 98235f433681e..0000000000000 --- a/x-pack/test/reporting/configs/chromium_api.js +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import { ReportingAPIProvider } from '../services'; - -export default async function({ readConfigFile }) { - const apiConfig = await readConfigFile(require.resolve('../../api_integration/config.js')); - const functionalConfig = await readConfigFile(require.resolve('../../functional/config.js')); - - return { - servers: apiConfig.get('servers'), - junit: { reportName: 'X-Pack Chromium API Reporting Tests' }, - testFiles: [require.resolve('../api/chromium_tests')], - services: { - ...apiConfig.get('services'), - reportingAPI: ReportingAPIProvider, - }, - kbnTestServer: { - ...apiConfig.get('kbnTestServer'), - serverArgs: [ - // Reporting API tests use functionalConfig instead of apiConfig because they needs a fully working UI. By default, the API config - // does not have optimize setting enabled, and Kibana would not have a working UI. - ...functionalConfig.get('kbnTestServer.serverArgs'), - '--logging.events.log', - '["info","warning","error","fatal","optimize","reporting"]', - '--xpack.reporting.csv.enablePanelActionDownload=true', - '--xpack.reporting.capture.maxAttempts=1', - '--xpack.security.session.idleTimeout=3600000', - '--xpack.spaces.enabled=false', - ], - }, - esArchiver: apiConfig.get('esArchiver'), - esTestCluster: apiConfig.get('esTestCluster'), - }; -} diff --git a/x-pack/test/reporting/services/index.ts b/x-pack/test/reporting/services/index.ts deleted file mode 100644 index 9684f2a8abc6c..0000000000000 --- a/x-pack/test/reporting/services/index.ts +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import { ReportingAPIProvider } from './reporting_api'; -import { services as xpackServices } from '../../functional/services'; - -export const services = { - ...xpackServices, - reportingAPI: ReportingAPIProvider, -}; - -export { ReportingAPIProvider }; diff --git a/x-pack/test/reporting/configs/generate_api.js b/x-pack/test/reporting_api_integration/config.js similarity index 69% rename from x-pack/test/reporting/configs/generate_api.js rename to x-pack/test/reporting_api_integration/config.js index c2b5e6c84f05f..2b1cd637a831d 100644 --- a/x-pack/test/reporting/configs/generate_api.js +++ b/x-pack/test/reporting_api_integration/config.js @@ -6,15 +6,16 @@ import { esTestConfig, kbnTestConfig, kibanaServerTestUser } from '@kbn/test'; import { format as formatUrl } from 'url'; -import { ReportingAPIProvider } from '../services'; +import { ReportingAPIProvider } from './services'; export default async function({ readConfigFile }) { - const apiConfig = await readConfigFile(require.resolve('../../api_integration/config.js')); + const apiConfig = await readConfigFile(require.resolve('../api_integration/config')); + const functionalConfig = await readConfigFile(require.resolve('../functional/config')); // Reporting API tests need a fully working UI return { servers: apiConfig.get('servers'), - junit: { reportName: 'X-Pack Reporting Generate API Integration Tests' }, - testFiles: [require.resolve('../api/generate')], + junit: { reportName: 'X-Pack Reporting API Integration Tests' }, + testFiles: [require.resolve('./reporting')], services: { ...apiConfig.get('services'), reportingAPI: ReportingAPIProvider, @@ -22,18 +23,18 @@ export default async function({ readConfigFile }) { kbnTestServer: { ...apiConfig.get('kbnTestServer'), serverArgs: [ - '--logging.events.log', - '["info","warning","error","fatal","optimize","reporting"]', + ...functionalConfig.get('kbnTestServer.serverArgs'), + `--elasticsearch.hosts=${formatUrl(esTestConfig.getUrlParts())}`, `--elasticsearch.password=${kibanaServerTestUser.password}`, `--elasticsearch.username=${kibanaServerTestUser.username}`, `--logging.json=false`, - `--optimize.enabled=false`, `--server.maxPayloadBytes=1679958`, `--server.port=${kbnTestConfig.getPort()}`, - `--xpack.reporting.csv.enablePanelActionDownload=true`, + `--xpack.reporting.capture.maxAttempts=1`, `--xpack.reporting.csv.maxSizeBytes=2850`, `--xpack.reporting.queue.pollInterval=3000`, + `--xpack.security.session.idleTimeout=3600000`, `--xpack.spaces.enabled=false`, ], }, diff --git a/x-pack/test/reporting/api/generate/fixtures.ts b/x-pack/test/reporting_api_integration/fixtures.ts similarity index 100% rename from x-pack/test/reporting/api/generate/fixtures.ts rename to x-pack/test/reporting_api_integration/fixtures.ts diff --git a/x-pack/test/reporting/ftr_provider_context.d.ts b/x-pack/test/reporting_api_integration/ftr_provider_context.d.ts similarity index 100% rename from x-pack/test/reporting/ftr_provider_context.d.ts rename to x-pack/test/reporting_api_integration/ftr_provider_context.d.ts diff --git a/x-pack/test/reporting/api/generation_urls.ts b/x-pack/test/reporting_api_integration/generation_urls.ts similarity index 100% rename from x-pack/test/reporting/api/generation_urls.ts rename to x-pack/test/reporting_api_integration/generation_urls.ts diff --git a/x-pack/test/reporting/api/bwc_existing_indexes.js b/x-pack/test/reporting_api_integration/reporting/bwc_existing_indexes.ts similarity index 63% rename from x-pack/test/reporting/api/bwc_existing_indexes.js rename to x-pack/test/reporting_api_integration/reporting/bwc_existing_indexes.ts index ffcf123848bb2..44a0466ae4dc5 100644 --- a/x-pack/test/reporting/api/bwc_existing_indexes.js +++ b/x-pack/test/reporting_api_integration/reporting/bwc_existing_indexes.ts @@ -4,7 +4,8 @@ * you may not use this file except in compliance with the Elastic License. */ -import * as GenerationUrls from './generation_urls'; +import { FtrProviderContext } from '../ftr_provider_context'; +import * as GenerationUrls from '../generation_urls'; /** * This file tests the situation when a reporting index spans releases. By default reporting indexes are created @@ -14,19 +15,18 @@ import * as GenerationUrls from './generation_urls'; * a major change in a major release, we handle it properly. */ -export default function({ getService }) { +// eslint-disable-next-line import/no-default-export +export default function({ getService }: FtrProviderContext) { const esArchiver = getService('esArchiver'); const reportingAPI = getService('reportingAPI'); - const usageAPI = getService('usageAPI'); // FLAKY: https://github.com/elastic/kibana/issues/42725 describe.skip('BWC report generation into existing indexes', () => { - let expectedCompletedReportCount; - let cleanupIndexAlias; + let cleanupIndexAlias: () => Promise; describe('existing 6_2 index', () => { before('load data and add index alias', async () => { - await reportingAPI.deleteAllReportingIndexes(); + await reportingAPI.deleteAllReports(); await esArchiver.load('reporting/bwc/6_2'); // The index name in the 6_2 archive. @@ -35,9 +35,6 @@ export default function({ getService }) { ARCHIVED_REPORTING_INDEX ); - const stats = await usageAPI.getUsageStats(); - expectedCompletedReportCount = await reportingAPI.getCompletedReportCount(stats); - await esArchiver.unload('reporting/bwc/6_2'); }); @@ -45,34 +42,18 @@ export default function({ getService }) { await cleanupIndexAlias(); }); - // Might not be great test practice to lump all these jobs together but reporting takes awhile and it'll be - // more efficient to post them all up front, then sequentially. it('multiple jobs posted', async () => { const reportPaths = []; reportPaths.push( await reportingAPI.postJob(GenerationUrls.CSV_DISCOVER_KUERY_AND_FILTER_6_3) ); - reportPaths.push( - await reportingAPI.postJob(GenerationUrls.PDF_PRESERVE_DASHBOARD_FILTER_6_3) - ); - reportPaths.push( - await reportingAPI.postJob(GenerationUrls.PDF_PRESERVE_PIE_VISUALIZATION_6_3) - ); - reportPaths.push(await reportingAPI.postJob(GenerationUrls.PDF_PRINT_DASHBOARD_6_3)); reportPaths.push( await reportingAPI.postJob( GenerationUrls.PDF_PRINT_PIE_VISUALIZATION_FILTER_AND_SAVED_SEARCH_6_3 ) ); - await reportingAPI.expectAllJobsToFinishSuccessfully(reportPaths); }).timeout(1540000); - - it('jobs completed successfully', async () => { - const stats = await usageAPI.getUsageStats(); - expectedCompletedReportCount += 5; - reportingAPI.expectCompletedReportCount(stats, expectedCompletedReportCount); - }); }); }); } diff --git a/x-pack/test/reporting/api/bwc_generation_urls.js b/x-pack/test/reporting_api_integration/reporting/bwc_generation_urls.ts similarity index 71% rename from x-pack/test/reporting/api/bwc_generation_urls.js rename to x-pack/test/reporting_api_integration/reporting/bwc_generation_urls.ts index 25b40ff3f74a8..7557512de2adc 100644 --- a/x-pack/test/reporting/api/bwc_generation_urls.js +++ b/x-pack/test/reporting_api_integration/reporting/bwc_generation_urls.ts @@ -4,33 +4,37 @@ * you may not use this file except in compliance with the Elastic License. */ -import * as GenerationUrls from './generation_urls'; - -export default function({ getService }) { +import { FtrProviderContext } from '../ftr_provider_context'; +import * as GenerationUrls from '../generation_urls'; +import { OSS_DATA_ARCHIVE_PATH, OSS_KIBANA_ARCHIVE_PATH } from './constants'; + +// eslint-disable-next-line import/no-default-export +export default function({ getService }: FtrProviderContext) { + const esArchiver = getService('esArchiver'); + const kibanaServer = getService('kibanaServer'); const reportingAPI = getService('reportingAPI'); - const usageAPI = getService('usageAPI'); describe('BWC report generation urls', () => { - describe('Pre 6_2', () => { - before(async () => { - await reportingAPI.deleteAllReportingIndexes(); + before(async () => { + await esArchiver.load(OSS_KIBANA_ARCHIVE_PATH); + await esArchiver.load(OSS_DATA_ARCHIVE_PATH); + + await kibanaServer.uiSettings.update({ + defaultIndex: '0bf35f60-3dc9-11e8-8660-4d65aa086b3c', }); + await reportingAPI.deleteAllReports(); + }); + describe('Pre 6_2', () => { // The URL being tested was captured from release 6.4 and then the layout section was removed to test structure before // preserve_layout was introduced. See https://github.com/elastic/kibana/issues/23414 it('job posted successfully', async () => { const path = await reportingAPI.postJob(GenerationUrls.PDF_PRINT_DASHBOARD_PRE_6_2); await reportingAPI.waitForJobToFinish(path); - const stats = await usageAPI.getUsageStats(); - reportingAPI.expectCompletedReportCount(stats, 1); }).timeout(500000); }); describe('6_2', () => { - before(async () => { - await reportingAPI.deleteAllReportingIndexes(); - }); - // Might not be great test practice to lump all these jobs together but reporting takes awhile and it'll be // more efficient to post them all up front, then sequentially. it('multiple jobs posted', async () => { @@ -41,11 +45,6 @@ export default function({ getService }) { await reportingAPI.expectAllJobsToFinishSuccessfully(reportPaths); }).timeout(1540000); - - it('jobs completed successfully', async () => { - const stats = await usageAPI.getUsageStats(); - reportingAPI.expectCompletedReportCount(stats, 3); - }); }); // 6.3 urls currently being tested as part of the "bwc_existing_indexes" test suite. Reports are time consuming, diff --git a/x-pack/test/reporting/api/constants.ts b/x-pack/test/reporting_api_integration/reporting/constants.ts similarity index 65% rename from x-pack/test/reporting/api/constants.ts rename to x-pack/test/reporting_api_integration/reporting/constants.ts index 0b4cb4f44a4bc..590ef6325dd51 100644 --- a/x-pack/test/reporting/api/constants.ts +++ b/x-pack/test/reporting_api_integration/reporting/constants.ts @@ -3,13 +3,15 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ + +import { REPO_ROOT } from '@kbn/dev-utils'; import path from 'path'; export const OSS_KIBANA_ARCHIVE_PATH = path.resolve( - __dirname, - '../../../../test/functional/fixtures/es_archiver/dashboard/current/kibana' + REPO_ROOT, + 'test/functional/fixtures/es_archiver/dashboard/current/kibana' ); export const OSS_DATA_ARCHIVE_PATH = path.resolve( - __dirname, - '../../../../test/functional/fixtures/es_archiver/dashboard/current/data' + REPO_ROOT, + 'test/functional/fixtures/es_archiver/dashboard/current/data' ); diff --git a/x-pack/test/reporting/api/generate/csv_job_params.ts b/x-pack/test/reporting_api_integration/reporting/csv_job_params.ts similarity index 89% rename from x-pack/test/reporting/api/generate/csv_job_params.ts rename to x-pack/test/reporting_api_integration/reporting/csv_job_params.ts index c8d6f11b74f9d..0cee0308e7489 100644 --- a/x-pack/test/reporting/api/generate/csv_job_params.ts +++ b/x-pack/test/reporting_api_integration/reporting/csv_job_params.ts @@ -6,12 +6,15 @@ import expect from '@kbn/expect'; import supertest from 'supertest'; -import { JOB_PARAMS_RISON } from './fixtures'; +import { JOB_PARAMS_RISON } from '../fixtures'; +import { FtrProviderContext } from '../ftr_provider_context'; // eslint-disable-next-line import/no-default-export -export default function({ getService }: { getService: any }) { +export default function({ getService }: FtrProviderContext) { const esArchiver = getService('esArchiver'); const supertestSvc = getService('supertest'); + const reportingAPI = getService('reportingAPI'); + const generateAPI = { getCsvFromParamsInPayload: async (jobParams: object = {}) => { return await supertestSvc @@ -30,11 +33,13 @@ export default function({ getService }: { getService: any }) { before(async () => { await esArchiver.load('reporting/logs'); await esArchiver.load('logstash_functional'); - }); // prettier-ignore + }); + after(async () => { await esArchiver.unload('reporting/logs'); await esArchiver.unload('logstash_functional'); - }); // prettier-ignore + await reportingAPI.deleteAllReports(); + }); it('Rejects bogus jobParams', async () => { const { status: resStatus, text: resText } = (await generateAPI.getCsvFromParamsInPayload({ diff --git a/x-pack/test/reporting/api/generate/csv_saved_search.ts b/x-pack/test/reporting_api_integration/reporting/csv_saved_search.ts similarity index 98% rename from x-pack/test/reporting/api/generate/csv_saved_search.ts rename to x-pack/test/reporting_api_integration/reporting/csv_saved_search.ts index ed44ba8ea4a76..96d3f0f28c22b 100644 --- a/x-pack/test/reporting/api/generate/csv_saved_search.ts +++ b/x-pack/test/reporting_api_integration/reporting/csv_saved_search.ts @@ -7,15 +7,16 @@ import expect from '@kbn/expect'; import supertest from 'supertest'; import { + CSV_RESULT_DOCVALUE, CSV_RESULT_HUGE, + CSV_RESULT_NANOS, CSV_RESULT_SCRIPTED, CSV_RESULT_SCRIPTED_REQUERY, CSV_RESULT_SCRIPTED_RESORTED, CSV_RESULT_TIMEBASED, CSV_RESULT_TIMELESS, - CSV_RESULT_NANOS, - CSV_RESULT_DOCVALUE, -} from './fixtures'; +} from '../fixtures'; +import { FtrProviderContext } from '../ftr_provider_context'; interface GenerateOpts { timerange?: { @@ -27,9 +28,11 @@ interface GenerateOpts { } // eslint-disable-next-line import/no-default-export -export default function({ getService }: { getService: any }) { +export default function({ getService }: FtrProviderContext) { const esArchiver = getService('esArchiver'); const supertestSvc = getService('supertest'); + const reportingAPI = getService('reportingAPI'); + const generateAPI = { getCsvFromSavedSearch: async ( id: string, @@ -45,6 +48,10 @@ export default function({ getService }: { getService: any }) { describe('Generation from Saved Search ID', () => { describe('Saved Search Features', () => { + after(async () => { + await reportingAPI.deleteAllReports(); + }); + it('With filters and timebased data', async () => { // load test data that contains a saved search and documents await esArchiver.load('reporting/logs'); diff --git a/x-pack/test/reporting/api/generate/index.ts b/x-pack/test/reporting_api_integration/reporting/index.ts similarity index 65% rename from x-pack/test/reporting/api/generate/index.ts rename to x-pack/test/reporting_api_integration/reporting/index.ts index b9db0d465d005..2baea547d0e90 100644 --- a/x-pack/test/reporting/api/generate/index.ts +++ b/x-pack/test/reporting_api_integration/reporting/index.ts @@ -4,13 +4,16 @@ * you may not use this file except in compliance with the Elastic License. */ -import { FtrProviderContext } from '../../ftr_provider_context'; +import { FtrProviderContext } from '../ftr_provider_context'; // eslint-disable-next-line import/no-default-export export default function({ loadTestFile }: FtrProviderContext) { - describe('CSV', function() { + describe('Reporting APIs', function() { this.tags('ciGroup2'); - loadTestFile(require.resolve('./csv_saved_search')); + loadTestFile(require.resolve('./bwc_existing_indexes')); + loadTestFile(require.resolve('./bwc_generation_urls')); loadTestFile(require.resolve('./csv_job_params')); + loadTestFile(require.resolve('./csv_saved_search')); + loadTestFile(require.resolve('./usage')); }); } diff --git a/x-pack/test/reporting/api/usage.ts b/x-pack/test/reporting_api_integration/reporting/usage.ts similarity index 88% rename from x-pack/test/reporting/api/usage.ts rename to x-pack/test/reporting_api_integration/reporting/usage.ts index e3ebcf9d3bab0..dc0144f74912c 100644 --- a/x-pack/test/reporting/api/usage.ts +++ b/x-pack/test/reporting_api_integration/reporting/usage.ts @@ -6,8 +6,9 @@ import expect from '@kbn/expect'; import { FtrProviderContext } from '../ftr_provider_context'; -import { ReportingUsageStats } from '../services/reporting_api'; -import * as GenerationUrls from './generation_urls'; +import * as GenerationUrls from '../generation_urls'; +import { ReportingUsageStats } from '../services'; +import { OSS_DATA_ARCHIVE_PATH, OSS_KIBANA_ARCHIVE_PATH } from './constants'; interface UsageStats { reporting: ReportingUsageStats; @@ -16,12 +17,29 @@ interface UsageStats { // eslint-disable-next-line import/no-default-export export default function({ getService }: FtrProviderContext) { const esArchiver = getService('esArchiver'); + const kibanaServer = getService('kibanaServer'); const reportingAPI = getService('reportingAPI'); const usageAPI = getService('usageAPI' as any); // NOTE Usage API service is not Typescript describe('reporting usage', () => { - before(() => reportingAPI.deleteAllReportingIndexes()); - afterEach(() => reportingAPI.deleteAllReportingIndexes()); + before(async () => { + await esArchiver.load(OSS_KIBANA_ARCHIVE_PATH); + await esArchiver.load(OSS_DATA_ARCHIVE_PATH); + + await kibanaServer.uiSettings.update({ + defaultIndex: '0bf35f60-3dc9-11e8-8660-4d65aa086b3c', + }); + await reportingAPI.deleteAllReports(); + }); + + after(async () => { + await esArchiver.unload(OSS_KIBANA_ARCHIVE_PATH); + await esArchiver.unload(OSS_DATA_ARCHIVE_PATH); + }); + + afterEach(async () => { + await reportingAPI.deleteAllReports(); + }); describe('initial state', () => { let usage: UsageStats; @@ -98,7 +116,7 @@ export default function({ getService }: FtrProviderContext) { }); describe('from new jobs posted', () => { - it('csv', async () => { + it('should handle csv', async () => { await reportingAPI.expectAllJobsToFinishSuccessfully( await Promise.all([ reportingAPI.postJob(GenerationUrls.CSV_DISCOVER_KUERY_AND_FILTER_6_3), @@ -114,7 +132,7 @@ export default function({ getService }: FtrProviderContext) { reportingAPI.expectRecentJobTypeTotalStats(usage, 'printable_pdf', 0); }); - it('preserve_layout pdf', async () => { + it('should handle preserve_layout pdf', async () => { await reportingAPI.expectAllJobsToFinishSuccessfully( await Promise.all([ reportingAPI.postJob(GenerationUrls.PDF_PRESERVE_DASHBOARD_FILTER_6_3), @@ -131,7 +149,7 @@ export default function({ getService }: FtrProviderContext) { reportingAPI.expectRecentJobTypeTotalStats(usage, 'printable_pdf', 2); }); - it('print_layout pdf', async () => { + it('should handle print_layout pdf', async () => { await reportingAPI.expectAllJobsToFinishSuccessfully( await Promise.all([ reportingAPI.postJob(GenerationUrls.PDF_PRINT_DASHBOARD_6_3), diff --git a/x-pack/test/reporting/services/reporting_api.ts b/x-pack/test/reporting_api_integration/services.ts similarity index 76% rename from x-pack/test/reporting/services/reporting_api.ts rename to x-pack/test/reporting_api_integration/services.ts index 1fa5fd7135708..ae7b83e2ac81b 100644 --- a/x-pack/test/reporting/services/reporting_api.ts +++ b/x-pack/test/reporting_api_integration/services.ts @@ -5,9 +5,12 @@ */ import expect from '@kbn/expect'; +import * as Rx from 'rxjs'; +import { filter, first, mapTo, switchMap, timeout } from 'rxjs/operators'; // @ts-ignore no module definition -import { indexTimestamp } from '../../../legacy/plugins/reporting/server/lib/esqueue/helpers/index_timestamp'; -import { FtrProviderContext } from '../ftr_provider_context'; +import { indexTimestamp } from '../../legacy/plugins/reporting/server/lib/esqueue/helpers/index_timestamp'; +import { services as xpackServices } from '../functional/services'; +import { FtrProviderContext } from './ftr_provider_context'; interface PDFAppCounts { app: { @@ -56,7 +59,13 @@ export function ReportingAPIProvider({ getService }: FtrProviderContext) { .get(downloadReportPath) .responseType('blob') .set('kbn-xsrf', 'xxx')) as any; - log.debug(`Report at path ${downloadReportPath} returned code ${response.statusCode}`); + if (response.statusCode === 503) { + log.debug(`Report at path ${downloadReportPath} is pending`); + } else if (response.statusCode === 200) { + log.debug(`Report at path ${downloadReportPath} is complete`); + } else { + log.debug(`Report at path ${downloadReportPath} returned code ${response.statusCode}`); + } if (response.statusCode !== JOB_IS_PENDING_CODE) { clearInterval(intervalId); resolve(response.statusCode); @@ -120,9 +129,25 @@ export function ReportingAPIProvider({ getService }: FtrProviderContext) { }; }, - async deleteAllReportingIndexes() { - log.debug('ReportingAPI.deleteAllReportingIndexes'); - await esSupertest.delete('/.reporting*').expect(200); + async deleteAllReports() { + log.debug('ReportingAPI.deleteAllReports'); + + // ignores 409 errs and keeps retrying + const deleted$ = Rx.interval(100).pipe( + switchMap(() => + esSupertest + .post('/.reporting*/_delete_by_query') + .send({ query: { match_all: {} } }) + .then(({ status }) => status) + ), + filter(status => status === 200), + mapTo(true), + first(), + timeout(5000) + ); + + const reportsDeleted = await deleted$.toPromise(); + expect(reportsDeleted).to.be(true); }, expectRecentPdfAppStats(stats: UsageStats, app: string, count: number) { @@ -158,3 +183,8 @@ export function ReportingAPIProvider({ getService }: FtrProviderContext) { }, }; } + +export const services = { + ...xpackServices, + reportingAPI: ReportingAPIProvider, +};