From c64896d72621357955a78c2582cb6c6fda5cac6c Mon Sep 17 00:00:00 2001 From: Timothy Sullivan Date: Thu, 14 May 2020 13:26:10 -0700 Subject: [PATCH 01/21] [Reporting] Consolidate API Integration Test configs --- x-pack/scripts/functional_tests.js | 3 +- x-pack/test/reporting/.gitignore | 1 - x-pack/test/reporting/api/generate/index.ts | 16 -------- x-pack/test/reporting/configs/chromium_api.js | 39 ------------------- x-pack/test/reporting/services/index.ts | 15 ------- .../config.js} | 17 ++++---- .../fixtures.ts | 0 .../ftr_provider_context.d.ts | 0 .../generation_urls.ts | 0 .../reporting}/constants.ts | 10 +++-- .../reporting}/csv_job_params.ts | 2 +- .../reporting}/csv_saved_search.ts | 2 +- .../reporting/index.ts} | 5 ++- .../reporting}/usage.ts | 4 +- .../services.ts} | 12 +++++- 15 files changed, 34 insertions(+), 92 deletions(-) delete mode 100644 x-pack/test/reporting/.gitignore delete mode 100644 x-pack/test/reporting/api/generate/index.ts delete mode 100644 x-pack/test/reporting/configs/chromium_api.js delete mode 100644 x-pack/test/reporting/services/index.ts rename x-pack/test/{reporting/configs/generate_api.js => reporting_api_integration/config.js} (69%) rename x-pack/test/{reporting/api/generate => reporting_api_integration}/fixtures.ts (100%) rename x-pack/test/{reporting => reporting_api_integration}/ftr_provider_context.d.ts (100%) rename x-pack/test/{reporting/api => reporting_api_integration}/generation_urls.ts (100%) rename x-pack/test/{reporting/api => reporting_api_integration/reporting}/constants.ts (65%) rename x-pack/test/{reporting/api/generate => reporting_api_integration/reporting}/csv_job_params.ts (98%) rename x-pack/test/{reporting/api/generate => reporting_api_integration/reporting}/csv_saved_search.ts (99%) rename x-pack/test/{reporting/api/chromium_tests.ts => reporting_api_integration/reporting/index.ts} (84%) rename x-pack/test/{reporting/api => reporting_api_integration/reporting}/usage.ts (98%) rename x-pack/test/{reporting/services/reporting_api.ts => reporting_api_integration/services.ts} (93%) diff --git a/x-pack/scripts/functional_tests.js b/x-pack/scripts/functional_tests.js index 8ea554c42d6e0..ac4b6b4c9171e 100644 --- a/x-pack/scripts/functional_tests.js +++ b/x-pack/scripts/functional_tests.js @@ -13,8 +13,6 @@ const alwaysImportedTests = [ require.resolve('../test/plugin_functional/config.ts'), ]; const onlyNotInCoverageTests = [ - require.resolve('../test/reporting/configs/chromium_api.js'), - require.resolve('../test/reporting/configs/generate_api.js'), require.resolve('../test/api_integration/config_security_basic.js'), require.resolve('../test/api_integration/config.js'), require.resolve('../test/alerting_api_integration/basic/config.ts'), @@ -52,6 +50,7 @@ const onlyNotInCoverageTests = [ require.resolve('../test/licensing_plugin/config.public.ts'), require.resolve('../test/licensing_plugin/config.legacy.ts'), require.resolve('../test/endpoint_api_integration_no_ingest/config.ts'), + require.resolve('../test/reporting_api_integration/config.ts'), ]; require('@kbn/plugin-helpers').babelRegister(); 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/generate/index.ts b/x-pack/test/reporting/api/generate/index.ts deleted file mode 100644 index b9db0d465d005..0000000000000 --- a/x-pack/test/reporting/api/generate/index.ts +++ /dev/null @@ -1,16 +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 { FtrProviderContext } from '../../ftr_provider_context'; - -// eslint-disable-next-line import/no-default-export -export default function({ loadTestFile }: FtrProviderContext) { - describe('CSV', function() { - this.tags('ciGroup2'); - loadTestFile(require.resolve('./csv_saved_search')); - loadTestFile(require.resolve('./csv_job_params')); - }); -} 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 95649dfb5d7a3..0000000000000 --- a/x-pack/test/reporting/configs/chromium_api.js +++ /dev/null @@ -1,39 +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.endpoint.enabled=true', - '--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/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 98% 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..c9ff7d649268e 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,7 +6,7 @@ import expect from '@kbn/expect'; import supertest from 'supertest'; -import { JOB_PARAMS_RISON } from './fixtures'; +import { JOB_PARAMS_RISON } from '../fixtures'; // eslint-disable-next-line import/no-default-export export default function({ getService }: { getService: any }) { 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 99% 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..de1c431803ee6 100644 --- a/x-pack/test/reporting/api/generate/csv_saved_search.ts +++ b/x-pack/test/reporting_api_integration/reporting/csv_saved_search.ts @@ -15,7 +15,7 @@ import { CSV_RESULT_TIMELESS, CSV_RESULT_NANOS, CSV_RESULT_DOCVALUE, -} from './fixtures'; +} from '../fixtures'; interface GenerateOpts { timerange?: { diff --git a/x-pack/test/reporting/api/chromium_tests.ts b/x-pack/test/reporting_api_integration/reporting/index.ts similarity index 84% rename from x-pack/test/reporting/api/chromium_tests.ts rename to x-pack/test/reporting_api_integration/reporting/index.ts index 75e8e3e70b5a5..1b0ab8bb3ef3c 100644 --- a/x-pack/test/reporting/api/chromium_tests.ts +++ b/x-pack/test/reporting_api_integration/reporting/index.ts @@ -5,6 +5,7 @@ */ import { OSS_DATA_ARCHIVE_PATH, OSS_KIBANA_ARCHIVE_PATH } from './constants'; +import { ReportingUsageStats } from '../services'; import { FtrProviderContext } from '../ftr_provider_context'; // eslint-disable-next-line import/no-default-export @@ -12,7 +13,7 @@ export default function({ loadTestFile, getService }: FtrProviderContext) { const esArchiver = getService('esArchiver'); const kibanaServer = getService('kibanaServer'); - describe('chromium', function() { + describe('Reporting APIs', function() { this.tags('ciGroup2'); before(async () => { @@ -29,6 +30,8 @@ export default function({ loadTestFile, getService }: FtrProviderContext) { await esArchiver.unload(OSS_DATA_ARCHIVE_PATH); }); + 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 98% rename from x-pack/test/reporting/api/usage.ts rename to x-pack/test/reporting_api_integration/reporting/usage.ts index e3ebcf9d3bab0..9362d041a10f4 100644 --- a/x-pack/test/reporting/api/usage.ts +++ b/x-pack/test/reporting_api_integration/reporting/usage.ts @@ -6,8 +6,8 @@ import expect from '@kbn/expect'; import { FtrProviderContext } from '../ftr_provider_context'; -import { ReportingUsageStats } from '../services/reporting_api'; -import * as GenerationUrls from './generation_urls'; +import { ReportingUsageStats } from '../services'; +import * as GenerationUrls from '../generation_urls'; interface UsageStats { reporting: ReportingUsageStats; diff --git a/x-pack/test/reporting/services/reporting_api.ts b/x-pack/test/reporting_api_integration/services.ts similarity index 93% rename from x-pack/test/reporting/services/reporting_api.ts rename to x-pack/test/reporting_api_integration/services.ts index 1fa5fd7135708..b773d2a4e98b4 100644 --- a/x-pack/test/reporting/services/reporting_api.ts +++ b/x-pack/test/reporting_api_integration/services.ts @@ -6,8 +6,9 @@ import expect from '@kbn/expect'; // @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 { FtrProviderContext } from './ftr_provider_context'; +import { services as xpackServices } from '../functional/services'; interface PDFAppCounts { app: { @@ -158,3 +159,10 @@ export function ReportingAPIProvider({ getService }: FtrProviderContext) { }, }; } + +export const services = { + ...xpackServices, + reportingAPI: ReportingAPIProvider, +}; + +export { ReportingAPIProvider }; From a499f88b26bbdb70a92f248a66bf30a2a7734a30 Mon Sep 17 00:00:00 2001 From: Timothy Sullivan Date: Thu, 14 May 2020 13:58:38 -0700 Subject: [PATCH 02/21] fix test isolation --- x-pack/test/reporting_api_integration/services.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/x-pack/test/reporting_api_integration/services.ts b/x-pack/test/reporting_api_integration/services.ts index b773d2a4e98b4..77274e523b8d9 100644 --- a/x-pack/test/reporting_api_integration/services.ts +++ b/x-pack/test/reporting_api_integration/services.ts @@ -123,7 +123,10 @@ export function ReportingAPIProvider({ getService }: FtrProviderContext) { async deleteAllReportingIndexes() { log.debug('ReportingAPI.deleteAllReportingIndexes'); - await esSupertest.delete('/.reporting*').expect(200); + await esSupertest + .post('/.reporting*/_delete_by_query') + .send({ query: { match_all: {} } }) + .expect(200); }, expectRecentPdfAppStats(stats: UsageStats, app: string, count: number) { From 7e510e8651df62b483528fd2330fb7b3db1869e8 Mon Sep 17 00:00:00 2001 From: Timothy Sullivan Date: Thu, 14 May 2020 14:12:25 -0700 Subject: [PATCH 03/21] tweak --- x-pack/test/reporting_api_integration/reporting/usage.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/x-pack/test/reporting_api_integration/reporting/usage.ts b/x-pack/test/reporting_api_integration/reporting/usage.ts index 9362d041a10f4..7a5fe30f6329a 100644 --- a/x-pack/test/reporting_api_integration/reporting/usage.ts +++ b/x-pack/test/reporting_api_integration/reporting/usage.ts @@ -100,9 +100,7 @@ export default function({ getService }: FtrProviderContext) { describe('from new jobs posted', () => { it('csv', async () => { await reportingAPI.expectAllJobsToFinishSuccessfully( - await Promise.all([ - reportingAPI.postJob(GenerationUrls.CSV_DISCOVER_KUERY_AND_FILTER_6_3), - ]) + await reportingAPI.postJob(GenerationUrls.CSV_DISCOVER_KUERY_AND_FILTER_6_3) ); const usage = await usageAPI.getUsageStats(); From 72037e696ed481317739f34fda3a72c99711d72e Mon Sep 17 00:00:00 2001 From: Timothy Sullivan Date: Fri, 15 May 2020 10:23:42 -0700 Subject: [PATCH 04/21] import order --- .../plugins/reporting/server/routes/lib/make_request_facade.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/legacy/plugins/reporting/server/routes/lib/make_request_facade.ts b/x-pack/legacy/plugins/reporting/server/routes/lib/make_request_facade.ts index fb8a2dbbff17b..d5270bb6cd0ea 100644 --- a/x-pack/legacy/plugins/reporting/server/routes/lib/make_request_facade.ts +++ b/x-pack/legacy/plugins/reporting/server/routes/lib/make_request_facade.ts @@ -7,10 +7,10 @@ import { RequestQuery } from 'hapi'; import { Legacy } from 'kibana'; import { - RequestFacade, ReportingRequestPayload, ReportingRequestPre, ReportingRequestQuery, + RequestFacade, } from '../../../types'; export function makeRequestFacade(request: Legacy.Request): RequestFacade { From 37bd652c316d808a1af4de675007b0a48d19322c Mon Sep 17 00:00:00 2001 From: Timothy Sullivan Date: Fri, 15 May 2020 12:11:01 -0700 Subject: [PATCH 05/21] fix ts refactor ish --- x-pack/test/reporting_api_integration/reporting/index.ts | 3 +-- x-pack/test/reporting_api_integration/services.ts | 8 ++++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/x-pack/test/reporting_api_integration/reporting/index.ts b/x-pack/test/reporting_api_integration/reporting/index.ts index 1b0ab8bb3ef3c..9cdb1f0e4fa9a 100644 --- a/x-pack/test/reporting_api_integration/reporting/index.ts +++ b/x-pack/test/reporting_api_integration/reporting/index.ts @@ -4,9 +4,8 @@ * 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 { ReportingUsageStats } from '../services'; import { FtrProviderContext } from '../ftr_provider_context'; +import { OSS_DATA_ARCHIVE_PATH, OSS_KIBANA_ARCHIVE_PATH } from './constants'; // eslint-disable-next-line import/no-default-export export default function({ loadTestFile, getService }: FtrProviderContext) { diff --git a/x-pack/test/reporting_api_integration/services.ts b/x-pack/test/reporting_api_integration/services.ts index 77274e523b8d9..66883e656c79b 100644 --- a/x-pack/test/reporting_api_integration/services.ts +++ b/x-pack/test/reporting_api_integration/services.ts @@ -7,8 +7,8 @@ import expect from '@kbn/expect'; // @ts-ignore no module definition import { indexTimestamp } from '../../legacy/plugins/reporting/server/lib/esqueue/helpers/index_timestamp'; -import { FtrProviderContext } from './ftr_provider_context'; import { services as xpackServices } from '../functional/services'; +import { FtrProviderContext } from './ftr_provider_context'; interface PDFAppCounts { app: { @@ -19,7 +19,7 @@ interface PDFAppCounts { }; } -export interface ReportingUsageStats { +interface ReportingUsageStats { available: boolean; enabled: boolean; total: number; @@ -41,7 +41,7 @@ function removeWhitespace(str: string) { return str.replace(/\s/g, ''); } -export function ReportingAPIProvider({ getService }: FtrProviderContext) { +function ReportingAPIProvider({ getService }: FtrProviderContext) { const log = getService('log'); const supertest = getService('supertest'); const esSupertest = getService('esSupertest'); @@ -168,4 +168,4 @@ export const services = { reportingAPI: ReportingAPIProvider, }; -export { ReportingAPIProvider }; +export { ReportingUsageStats, ReportingAPIProvider }; From ecee2228ca57f8a87570a3275944e218bdd89212 Mon Sep 17 00:00:00 2001 From: Timothy Sullivan Date: Fri, 15 May 2020 13:39:15 -0700 Subject: [PATCH 06/21] fix a test bug --- x-pack/test/reporting_api_integration/reporting/usage.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/x-pack/test/reporting_api_integration/reporting/usage.ts b/x-pack/test/reporting_api_integration/reporting/usage.ts index 7a5fe30f6329a..92294bd3b11cd 100644 --- a/x-pack/test/reporting_api_integration/reporting/usage.ts +++ b/x-pack/test/reporting_api_integration/reporting/usage.ts @@ -100,7 +100,9 @@ export default function({ getService }: FtrProviderContext) { describe('from new jobs posted', () => { it('csv', async () => { await reportingAPI.expectAllJobsToFinishSuccessfully( - await reportingAPI.postJob(GenerationUrls.CSV_DISCOVER_KUERY_AND_FILTER_6_3) + await Promise.all([ + await reportingAPI.postJob(GenerationUrls.CSV_DISCOVER_KUERY_AND_FILTER_6_3), + ]) ); const usage = await usageAPI.getUsageStats(); From 8267e04d143813252e35306bd047648ef8047dcc Mon Sep 17 00:00:00 2001 From: Timothy Sullivan Date: Fri, 15 May 2020 14:07:44 -0700 Subject: [PATCH 07/21] fix test --- .../printable_pdf/server/execute_job/index.test.ts | 4 ++-- x-pack/test/reporting_api_integration/reporting/usage.ts | 7 +++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/x-pack/legacy/plugins/reporting/export_types/printable_pdf/server/execute_job/index.test.ts b/x-pack/legacy/plugins/reporting/export_types/printable_pdf/server/execute_job/index.test.ts index ae18c0f4f9f4b..78f417ba686cb 100644 --- a/x-pack/legacy/plugins/reporting/export_types/printable_pdf/server/execute_job/index.test.ts +++ b/x-pack/legacy/plugins/reporting/export_types/printable_pdf/server/execute_job/index.test.ts @@ -4,6 +4,8 @@ * you may not use this file except in compliance with the Elastic License. */ +jest.mock('../lib/generate_pdf', () => ({ generatePdfObservableFactory: jest.fn() })); + import * as Rx from 'rxjs'; import { createMockReportingCore } from '../../../../test_helpers'; import { cryptoFactory } from '../../../../server/lib/crypto'; @@ -14,8 +16,6 @@ import { generatePdfObservableFactory } from '../lib/generate_pdf'; import { JobDocPayloadPDF } from '../../types'; import { executeJobFactory } from './index'; -jest.mock('../lib/generate_pdf', () => ({ generatePdfObservableFactory: jest.fn() })); - let mockReporting: ReportingCore; const cancellationToken = ({ diff --git a/x-pack/test/reporting_api_integration/reporting/usage.ts b/x-pack/test/reporting_api_integration/reporting/usage.ts index 92294bd3b11cd..d6d8e2351658e 100644 --- a/x-pack/test/reporting_api_integration/reporting/usage.ts +++ b/x-pack/test/reporting_api_integration/reporting/usage.ts @@ -20,7 +20,6 @@ export default function({ getService }: FtrProviderContext) { const usageAPI = getService('usageAPI' as any); // NOTE Usage API service is not Typescript describe('reporting usage', () => { - before(() => reportingAPI.deleteAllReportingIndexes()); afterEach(() => reportingAPI.deleteAllReportingIndexes()); describe('initial state', () => { @@ -98,7 +97,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([ await reportingAPI.postJob(GenerationUrls.CSV_DISCOVER_KUERY_AND_FILTER_6_3), @@ -114,7 +113,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 +130,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), From cbea3571c50b8c8b75bbe8dca41abc76ca27cf3a Mon Sep 17 00:00:00 2001 From: Timothy Sullivan Date: Fri, 15 May 2020 14:40:37 -0700 Subject: [PATCH 08/21] --wip-- [skip ci] --- x-pack/test/reporting_api_integration/reporting/usage.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/x-pack/test/reporting_api_integration/reporting/usage.ts b/x-pack/test/reporting_api_integration/reporting/usage.ts index d6d8e2351658e..fb168a47d545b 100644 --- a/x-pack/test/reporting_api_integration/reporting/usage.ts +++ b/x-pack/test/reporting_api_integration/reporting/usage.ts @@ -20,6 +20,7 @@ export default function({ getService }: FtrProviderContext) { const usageAPI = getService('usageAPI' as any); // NOTE Usage API service is not Typescript describe('reporting usage', () => { + before(() => reportingAPI.deleteAllReportingIndexes()); afterEach(() => reportingAPI.deleteAllReportingIndexes()); describe('initial state', () => { @@ -100,7 +101,7 @@ export default function({ getService }: FtrProviderContext) { it('should handle csv', async () => { await reportingAPI.expectAllJobsToFinishSuccessfully( await Promise.all([ - await reportingAPI.postJob(GenerationUrls.CSV_DISCOVER_KUERY_AND_FILTER_6_3), + await reportingAPI.postJob(GenerationUrls.CSV_DISCOVER_KUERY_AND_FILTER_6_3), // depends on loaded archive ]) ); From 7590bbc240742c0d7856885d9584c0bd7bdfa7e7 Mon Sep 17 00:00:00 2001 From: Timothy Sullivan Date: Fri, 15 May 2020 15:22:51 -0700 Subject: [PATCH 09/21] revision --- x-pack/test/reporting_api_integration/reporting/usage.ts | 2 +- x-pack/test/reporting_api_integration/services.ts | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/x-pack/test/reporting_api_integration/reporting/usage.ts b/x-pack/test/reporting_api_integration/reporting/usage.ts index fb168a47d545b..319ebb07191d6 100644 --- a/x-pack/test/reporting_api_integration/reporting/usage.ts +++ b/x-pack/test/reporting_api_integration/reporting/usage.ts @@ -101,7 +101,7 @@ export default function({ getService }: FtrProviderContext) { it('should handle csv', async () => { await reportingAPI.expectAllJobsToFinishSuccessfully( await Promise.all([ - await reportingAPI.postJob(GenerationUrls.CSV_DISCOVER_KUERY_AND_FILTER_6_3), // depends on loaded archive + reportingAPI.postJob(GenerationUrls.CSV_DISCOVER_KUERY_AND_FILTER_6_3), ]) ); diff --git a/x-pack/test/reporting_api_integration/services.ts b/x-pack/test/reporting_api_integration/services.ts index 66883e656c79b..67b6a29ffbeb9 100644 --- a/x-pack/test/reporting_api_integration/services.ts +++ b/x-pack/test/reporting_api_integration/services.ts @@ -19,7 +19,7 @@ interface PDFAppCounts { }; } -interface ReportingUsageStats { +export interface ReportingUsageStats { available: boolean; enabled: boolean; total: number; @@ -41,7 +41,7 @@ function removeWhitespace(str: string) { return str.replace(/\s/g, ''); } -function ReportingAPIProvider({ getService }: FtrProviderContext) { +export function ReportingAPIProvider({ getService }: FtrProviderContext) { const log = getService('log'); const supertest = getService('supertest'); const esSupertest = getService('esSupertest'); @@ -167,5 +167,3 @@ export const services = { ...xpackServices, reportingAPI: ReportingAPIProvider, }; - -export { ReportingUsageStats, ReportingAPIProvider }; From d0beba7f7e3b82e920c6ea97c6ea5b2c2f68ee36 Mon Sep 17 00:00:00 2001 From: Timothy Sullivan Date: Fri, 15 May 2020 15:24:28 -0700 Subject: [PATCH 10/21] undo bad cherrypick --- .../printable_pdf/server/execute_job/index.test.ts | 4 ++-- .../reporting/server/routes/lib/make_request_facade.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/x-pack/legacy/plugins/reporting/export_types/printable_pdf/server/execute_job/index.test.ts b/x-pack/legacy/plugins/reporting/export_types/printable_pdf/server/execute_job/index.test.ts index 78f417ba686cb..ae18c0f4f9f4b 100644 --- a/x-pack/legacy/plugins/reporting/export_types/printable_pdf/server/execute_job/index.test.ts +++ b/x-pack/legacy/plugins/reporting/export_types/printable_pdf/server/execute_job/index.test.ts @@ -4,8 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ -jest.mock('../lib/generate_pdf', () => ({ generatePdfObservableFactory: jest.fn() })); - import * as Rx from 'rxjs'; import { createMockReportingCore } from '../../../../test_helpers'; import { cryptoFactory } from '../../../../server/lib/crypto'; @@ -16,6 +14,8 @@ import { generatePdfObservableFactory } from '../lib/generate_pdf'; import { JobDocPayloadPDF } from '../../types'; import { executeJobFactory } from './index'; +jest.mock('../lib/generate_pdf', () => ({ generatePdfObservableFactory: jest.fn() })); + let mockReporting: ReportingCore; const cancellationToken = ({ diff --git a/x-pack/legacy/plugins/reporting/server/routes/lib/make_request_facade.ts b/x-pack/legacy/plugins/reporting/server/routes/lib/make_request_facade.ts index d5270bb6cd0ea..fb8a2dbbff17b 100644 --- a/x-pack/legacy/plugins/reporting/server/routes/lib/make_request_facade.ts +++ b/x-pack/legacy/plugins/reporting/server/routes/lib/make_request_facade.ts @@ -7,10 +7,10 @@ import { RequestQuery } from 'hapi'; import { Legacy } from 'kibana'; import { + RequestFacade, ReportingRequestPayload, ReportingRequestPre, ReportingRequestQuery, - RequestFacade, } from '../../../types'; export function makeRequestFacade(request: Legacy.Request): RequestFacade { From dfdabfbe5517eedade88a12f3fc911e65bcae366 Mon Sep 17 00:00:00 2001 From: Timothy Sullivan Date: Fri, 15 May 2020 15:28:54 -0700 Subject: [PATCH 11/21] fix delete reports --- x-pack/test/reporting_api_integration/services.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/test/reporting_api_integration/services.ts b/x-pack/test/reporting_api_integration/services.ts index 67b6a29ffbeb9..90cb6577a88b2 100644 --- a/x-pack/test/reporting_api_integration/services.ts +++ b/x-pack/test/reporting_api_integration/services.ts @@ -126,7 +126,7 @@ export function ReportingAPIProvider({ getService }: FtrProviderContext) { await esSupertest .post('/.reporting*/_delete_by_query') .send({ query: { match_all: {} } }) - .expect(200); + .expect(({ status }) => status === 200 || status === 404); }, expectRecentPdfAppStats(stats: UsageStats, app: string, count: number) { From 981d6b2a98fc86334ab218602538b69b5506e656 Mon Sep 17 00:00:00 2001 From: Timothy Sullivan Date: Fri, 15 May 2020 15:38:49 -0700 Subject: [PATCH 12/21] log tweak --- x-pack/test/reporting_api_integration/services.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/x-pack/test/reporting_api_integration/services.ts b/x-pack/test/reporting_api_integration/services.ts index 90cb6577a88b2..cc2011260d276 100644 --- a/x-pack/test/reporting_api_integration/services.ts +++ b/x-pack/test/reporting_api_integration/services.ts @@ -57,7 +57,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); From 77a44f74580aeb321af153dec4f668dec1a9b816 Mon Sep 17 00:00:00 2001 From: Timothy Sullivan Date: Fri, 15 May 2020 15:48:53 -0700 Subject: [PATCH 13/21] fix default index pattern --- x-pack/test/reporting_api_integration/reporting/usage.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/x-pack/test/reporting_api_integration/reporting/usage.ts b/x-pack/test/reporting_api_integration/reporting/usage.ts index 319ebb07191d6..bc8d67f0bebe6 100644 --- a/x-pack/test/reporting_api_integration/reporting/usage.ts +++ b/x-pack/test/reporting_api_integration/reporting/usage.ts @@ -16,11 +16,17 @@ 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()); + before(async () => { + await kibanaServer.uiSettings.update({ + defaultIndex: '0bf35f60-3dc9-11e8-8660-4d65aa086b3c', + }); + await reportingAPI.deleteAllReportingIndexes(); + }); afterEach(() => reportingAPI.deleteAllReportingIndexes()); describe('initial state', () => { From 7536c951070354e386770fed9c57f9d048d4d2f8 Mon Sep 17 00:00:00 2001 From: Timothy Sullivan Date: Fri, 15 May 2020 15:53:28 -0700 Subject: [PATCH 14/21] fix the test --- .../reporting_api_integration/reporting/usage.ts | 13 +++++++++++-- x-pack/test/reporting_api_integration/services.ts | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/x-pack/test/reporting_api_integration/reporting/usage.ts b/x-pack/test/reporting_api_integration/reporting/usage.ts index bc8d67f0bebe6..52d058d461292 100644 --- a/x-pack/test/reporting_api_integration/reporting/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'; 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; @@ -22,12 +23,20 @@ export default function({ getService }: FtrProviderContext) { describe('reporting usage', () => { before(async () => { + await reportingAPI.deleteAllReportingIndexes(); + + await esArchiver.load(OSS_KIBANA_ARCHIVE_PATH); + await esArchiver.load(OSS_DATA_ARCHIVE_PATH); + await kibanaServer.uiSettings.update({ defaultIndex: '0bf35f60-3dc9-11e8-8660-4d65aa086b3c', }); + }); + afterEach(async () => { await reportingAPI.deleteAllReportingIndexes(); + await esArchiver.unload(OSS_KIBANA_ARCHIVE_PATH); + await esArchiver.unload(OSS_DATA_ARCHIVE_PATH); }); - afterEach(() => reportingAPI.deleteAllReportingIndexes()); describe('initial state', () => { let usage: UsageStats; diff --git a/x-pack/test/reporting_api_integration/services.ts b/x-pack/test/reporting_api_integration/services.ts index cc2011260d276..d9a60e7947791 100644 --- a/x-pack/test/reporting_api_integration/services.ts +++ b/x-pack/test/reporting_api_integration/services.ts @@ -132,7 +132,7 @@ export function ReportingAPIProvider({ getService }: FtrProviderContext) { await esSupertest .post('/.reporting*/_delete_by_query') .send({ query: { match_all: {} } }) - .expect(({ status }) => status === 200 || status === 404); + .expect(200); }, expectRecentPdfAppStats(stats: UsageStats, app: string, count: number) { From 00649506dc9a28068cb4e44d8d02a1f7833b83fa Mon Sep 17 00:00:00 2001 From: Timothy Sullivan Date: Fri, 15 May 2020 16:00:17 -0700 Subject: [PATCH 15/21] revert --- .../reporting_api_integration/reporting/constants.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/x-pack/test/reporting_api_integration/reporting/constants.ts b/x-pack/test/reporting_api_integration/reporting/constants.ts index 590ef6325dd51..2e4a264d77afd 100644 --- a/x-pack/test/reporting_api_integration/reporting/constants.ts +++ b/x-pack/test/reporting_api_integration/reporting/constants.ts @@ -4,14 +4,13 @@ * 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( - REPO_ROOT, - 'test/functional/fixtures/es_archiver/dashboard/current/kibana' + __dirname, + '../../../../test/functional/fixtures/es_archiver/dashboard/current/kibana' ); export const OSS_DATA_ARCHIVE_PATH = path.resolve( - REPO_ROOT, - 'test/functional/fixtures/es_archiver/dashboard/current/data' + __dirname, + '../../../../test/functional/fixtures/es_archiver/dashboard/current/data' ); From c7e11f9f366194140c06de9312c0cf3e61a15567 Mon Sep 17 00:00:00 2001 From: Timothy Sullivan Date: Fri, 15 May 2020 16:05:11 -0700 Subject: [PATCH 16/21] --wip-- [skip ci] --- .../reporting/index.ts | 21 +------------------ .../reporting/usage.ts | 6 ++++-- 2 files changed, 5 insertions(+), 22 deletions(-) diff --git a/x-pack/test/reporting_api_integration/reporting/index.ts b/x-pack/test/reporting_api_integration/reporting/index.ts index 9cdb1f0e4fa9a..abfdb735d1dc7 100644 --- a/x-pack/test/reporting_api_integration/reporting/index.ts +++ b/x-pack/test/reporting_api_integration/reporting/index.ts @@ -5,30 +5,11 @@ */ import { FtrProviderContext } from '../ftr_provider_context'; -import { OSS_DATA_ARCHIVE_PATH, OSS_KIBANA_ARCHIVE_PATH } from './constants'; // eslint-disable-next-line import/no-default-export -export default function({ loadTestFile, getService }: FtrProviderContext) { - const esArchiver = getService('esArchiver'); - const kibanaServer = getService('kibanaServer'); - +export default function({ loadTestFile }: FtrProviderContext) { describe('Reporting APIs', 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('./csv_job_params')); loadTestFile(require.resolve('./csv_saved_search')); loadTestFile(require.resolve('./usage')); diff --git a/x-pack/test/reporting_api_integration/reporting/usage.ts b/x-pack/test/reporting_api_integration/reporting/usage.ts index 52d058d461292..ec71d1e50e0e1 100644 --- a/x-pack/test/reporting_api_integration/reporting/usage.ts +++ b/x-pack/test/reporting_api_integration/reporting/usage.ts @@ -32,11 +32,13 @@ export default function({ getService }: FtrProviderContext) { defaultIndex: '0bf35f60-3dc9-11e8-8660-4d65aa086b3c', }); }); - afterEach(async () => { - await reportingAPI.deleteAllReportingIndexes(); + after(async () => { await esArchiver.unload(OSS_KIBANA_ARCHIVE_PATH); await esArchiver.unload(OSS_DATA_ARCHIVE_PATH); }); + afterEach(async () => { + await reportingAPI.deleteAllReportingIndexes(); + }); describe('initial state', () => { let usage: UsageStats; From 778db3ac380cf392668060d67d48c376febc5df4 Mon Sep 17 00:00:00 2001 From: Timothy Sullivan Date: Fri, 15 May 2020 16:10:43 -0700 Subject: [PATCH 17/21] unrevert --- .../reporting_api_integration/reporting/constants.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/x-pack/test/reporting_api_integration/reporting/constants.ts b/x-pack/test/reporting_api_integration/reporting/constants.ts index 2e4a264d77afd..590ef6325dd51 100644 --- a/x-pack/test/reporting_api_integration/reporting/constants.ts +++ b/x-pack/test/reporting_api_integration/reporting/constants.ts @@ -4,13 +4,14 @@ * 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' ); From 133bcf9152c8b4618bfd333d55a9f04d85720d86 Mon Sep 17 00:00:00 2001 From: Timothy Sullivan Date: Mon, 18 May 2020 08:22:35 -0700 Subject: [PATCH 18/21] harden the deleteAllReportingIndexes function --- .../reporting/csv_job_params.ts | 11 +++++++--- .../reporting/csv_saved_search.ts | 13 ++++++++--- .../reporting/usage.ts | 3 +-- .../reporting_api_integration/services.ts | 22 +++++++++++++++---- 4 files changed, 37 insertions(+), 12 deletions(-) diff --git a/x-pack/test/reporting_api_integration/reporting/csv_job_params.ts b/x-pack/test/reporting_api_integration/reporting/csv_job_params.ts index c9ff7d649268e..005f4fdaf43e3 100644 --- a/x-pack/test/reporting_api_integration/reporting/csv_job_params.ts +++ b/x-pack/test/reporting_api_integration/reporting/csv_job_params.ts @@ -7,11 +7,14 @@ import expect from '@kbn/expect'; import supertest from 'supertest'; 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.deleteAllReportingIndexes(); + }); it('Rejects bogus jobParams', async () => { const { status: resStatus, text: resText } = (await generateAPI.getCsvFromParamsInPayload({ diff --git a/x-pack/test/reporting_api_integration/reporting/csv_saved_search.ts b/x-pack/test/reporting_api_integration/reporting/csv_saved_search.ts index de1c431803ee6..905fe62e5e939 100644 --- a/x-pack/test/reporting_api_integration/reporting/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'; +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', () => { + afterEach(async () => { + await reportingAPI.deleteAllReportingIndexes(); + }); + 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_integration/reporting/usage.ts b/x-pack/test/reporting_api_integration/reporting/usage.ts index ec71d1e50e0e1..1bf307b66e99e 100644 --- a/x-pack/test/reporting_api_integration/reporting/usage.ts +++ b/x-pack/test/reporting_api_integration/reporting/usage.ts @@ -23,14 +23,13 @@ export default function({ getService }: FtrProviderContext) { describe('reporting usage', () => { before(async () => { - await reportingAPI.deleteAllReportingIndexes(); - 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.deleteAllReportingIndexes(); }); after(async () => { await esArchiver.unload(OSS_KIBANA_ARCHIVE_PATH); diff --git a/x-pack/test/reporting_api_integration/services.ts b/x-pack/test/reporting_api_integration/services.ts index d9a60e7947791..127584d523d00 100644 --- a/x-pack/test/reporting_api_integration/services.ts +++ b/x-pack/test/reporting_api_integration/services.ts @@ -5,6 +5,8 @@ */ import expect from '@kbn/expect'; +import * as Rx from 'rxjs'; +import { filter, first, switchMap, timeout } from 'rxjs/operators'; // @ts-ignore no module definition import { indexTimestamp } from '../../legacy/plugins/reporting/server/lib/esqueue/helpers/index_timestamp'; import { services as xpackServices } from '../functional/services'; @@ -128,11 +130,23 @@ export function ReportingAPIProvider({ getService }: FtrProviderContext) { }, async deleteAllReportingIndexes() { + // 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), + first(), + timeout(5000) + ); + + const reportsDeleted = await deleted$.toPromise(); + expect(reportsDeleted).to.be(true); + log.debug('ReportingAPI.deleteAllReportingIndexes'); - await esSupertest - .post('/.reporting*/_delete_by_query') - .send({ query: { match_all: {} } }) - .expect(200); }, expectRecentPdfAppStats(stats: UsageStats, app: string, count: number) { From aa4108bda5858458fd52a7884d4a09db7c9d11e6 Mon Sep 17 00:00:00 2001 From: Timothy Sullivan Date: Mon, 18 May 2020 10:07:43 -0700 Subject: [PATCH 19/21] fix tests --- .../reporting_api_integration/reporting/csv_job_params.ts | 2 +- .../reporting/csv_saved_search.ts | 4 ++-- x-pack/test/reporting_api_integration/reporting/usage.ts | 6 ++++-- x-pack/test/reporting_api_integration/services.ts | 7 ++++--- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/x-pack/test/reporting_api_integration/reporting/csv_job_params.ts b/x-pack/test/reporting_api_integration/reporting/csv_job_params.ts index 005f4fdaf43e3..0cee0308e7489 100644 --- a/x-pack/test/reporting_api_integration/reporting/csv_job_params.ts +++ b/x-pack/test/reporting_api_integration/reporting/csv_job_params.ts @@ -38,7 +38,7 @@ export default function({ getService }: FtrProviderContext) { after(async () => { await esArchiver.unload('reporting/logs'); await esArchiver.unload('logstash_functional'); - await reportingAPI.deleteAllReportingIndexes(); + await reportingAPI.deleteAllReports(); }); it('Rejects bogus jobParams', async () => { diff --git a/x-pack/test/reporting_api_integration/reporting/csv_saved_search.ts b/x-pack/test/reporting_api_integration/reporting/csv_saved_search.ts index 905fe62e5e939..96d3f0f28c22b 100644 --- a/x-pack/test/reporting_api_integration/reporting/csv_saved_search.ts +++ b/x-pack/test/reporting_api_integration/reporting/csv_saved_search.ts @@ -48,8 +48,8 @@ export default function({ getService }: FtrProviderContext) { describe('Generation from Saved Search ID', () => { describe('Saved Search Features', () => { - afterEach(async () => { - await reportingAPI.deleteAllReportingIndexes(); + after(async () => { + await reportingAPI.deleteAllReports(); }); it('With filters and timebased data', async () => { diff --git a/x-pack/test/reporting_api_integration/reporting/usage.ts b/x-pack/test/reporting_api_integration/reporting/usage.ts index 1bf307b66e99e..dc0144f74912c 100644 --- a/x-pack/test/reporting_api_integration/reporting/usage.ts +++ b/x-pack/test/reporting_api_integration/reporting/usage.ts @@ -29,14 +29,16 @@ export default function({ getService }: FtrProviderContext) { await kibanaServer.uiSettings.update({ defaultIndex: '0bf35f60-3dc9-11e8-8660-4d65aa086b3c', }); - await reportingAPI.deleteAllReportingIndexes(); + await reportingAPI.deleteAllReports(); }); + after(async () => { await esArchiver.unload(OSS_KIBANA_ARCHIVE_PATH); await esArchiver.unload(OSS_DATA_ARCHIVE_PATH); }); + afterEach(async () => { - await reportingAPI.deleteAllReportingIndexes(); + await reportingAPI.deleteAllReports(); }); describe('initial state', () => { diff --git a/x-pack/test/reporting_api_integration/services.ts b/x-pack/test/reporting_api_integration/services.ts index 127584d523d00..3e8ade11e7f81 100644 --- a/x-pack/test/reporting_api_integration/services.ts +++ b/x-pack/test/reporting_api_integration/services.ts @@ -6,7 +6,7 @@ import expect from '@kbn/expect'; import * as Rx from 'rxjs'; -import { filter, first, switchMap, timeout } from 'rxjs/operators'; +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 { services as xpackServices } from '../functional/services'; @@ -129,7 +129,7 @@ export function ReportingAPIProvider({ getService }: FtrProviderContext) { }; }, - async deleteAllReportingIndexes() { + async deleteAllReports() { // ignores 409 errs and keeps retrying const deleted$ = Rx.interval(100).pipe( switchMap(() => @@ -139,6 +139,7 @@ export function ReportingAPIProvider({ getService }: FtrProviderContext) { .then(({ status }) => status) ), filter(status => status === 200), + mapTo(true), first(), timeout(5000) ); @@ -146,7 +147,7 @@ export function ReportingAPIProvider({ getService }: FtrProviderContext) { const reportsDeleted = await deleted$.toPromise(); expect(reportsDeleted).to.be(true); - log.debug('ReportingAPI.deleteAllReportingIndexes'); + log.debug('ReportingAPI.deleteAllReports'); }, expectRecentPdfAppStats(stats: UsageStats, app: string, count: number) { From 62ff1aa62d5ab3db4877aa1bee33ac998e804303 Mon Sep 17 00:00:00 2001 From: Timothy Sullivan Date: Mon, 18 May 2020 13:01:00 -0700 Subject: [PATCH 20/21] move the log.debug line --- x-pack/test/reporting_api_integration/services.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x-pack/test/reporting_api_integration/services.ts b/x-pack/test/reporting_api_integration/services.ts index 3e8ade11e7f81..ae7b83e2ac81b 100644 --- a/x-pack/test/reporting_api_integration/services.ts +++ b/x-pack/test/reporting_api_integration/services.ts @@ -130,6 +130,8 @@ export function ReportingAPIProvider({ getService }: FtrProviderContext) { }, async deleteAllReports() { + log.debug('ReportingAPI.deleteAllReports'); + // ignores 409 errs and keeps retrying const deleted$ = Rx.interval(100).pipe( switchMap(() => @@ -146,8 +148,6 @@ export function ReportingAPIProvider({ getService }: FtrProviderContext) { const reportsDeleted = await deleted$.toPromise(); expect(reportsDeleted).to.be(true); - - log.debug('ReportingAPI.deleteAllReports'); }, expectRecentPdfAppStats(stats: UsageStats, app: string, count: number) { From 3426c8662a02b1c3400b7f595da94b8eba5d090d Mon Sep 17 00:00:00 2001 From: Timothy Sullivan Date: Mon, 18 May 2020 18:00:10 -0700 Subject: [PATCH 21/21] fix config path --- x-pack/scripts/functional_tests.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/scripts/functional_tests.js b/x-pack/scripts/functional_tests.js index 438bbee616ead..9818d30ac8602 100644 --- a/x-pack/scripts/functional_tests.js +++ b/x-pack/scripts/functional_tests.js @@ -51,7 +51,7 @@ const onlyNotInCoverageTests = [ require.resolve('../test/licensing_plugin/config.public.ts'), require.resolve('../test/licensing_plugin/config.legacy.ts'), require.resolve('../test/endpoint_api_integration_no_ingest/config.ts'), - require.resolve('../test/reporting_api_integration/config.ts'), + require.resolve('../test/reporting_api_integration/config.js'), ]; require('@kbn/plugin-helpers').babelRegister();