Skip to content

Commit

Permalink
[Reporting] Unskip and optimize tests that generate test reports (ela…
Browse files Browse the repository at this point in the history
…stic#198207)

## Summary

This PR re-enables test reports that have been consistently failing in
the serverless test environment. Investigation shows the reason for
flakiness _may_ be due to the fact that the reports are exporting a
large amount of data, which causes timeouts, including authentication
tokens to time out.

To speed up the tests, date range filters and field selections have been
added to the report job parameters, which leads to a lower amount of
data being exported. The tests that are updated in this PR now generate
an export with 2 documents, where previously they were exporting up to
4675 documents.
  • Loading branch information
tsullivan authored Oct 30, 2024
1 parent c4301d0 commit 0b87e90
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ export default function ({ getService }: FtrProviderContext) {
};

describe('Data Stream', function () {
// see details: https://github.com/elastic/kibana/issues/197955
this.tags(['failsOnMKI']);

const generatedReports = new Set<string>();
before(async () => {
roleAuthc = await svlUserManager.createM2mApiKeyWithRoleScope('admin');
Expand All @@ -45,15 +42,52 @@ export default function ({ getService }: FtrProviderContext) {
await esArchiver.load(archives.ecommerce.data);
await kibanaServer.importExport.load(archives.ecommerce.savedObjects);

// generate a report that will initialize the Reporting data stream
const { job, path } = await reportingAPI.createReportJobInternal(
'csv_searchsource',
{
browserTimezone: 'UTC',
objectType: 'search',
searchSource: {
fields: [
{ field: 'order_date', include_unmapped: true },
{ field: 'order_id', include_unmapped: true },
{ field: 'products.product_id', include_unmapped: true },
],
filter: [
{
meta: {
field: 'order_date',
index: '5193f870-d861-11e9-a311-0fa548c5f953',
params: {},
},
query: {
range: {
order_date: {
format: 'strict_date_optional_time',
gte: '2019-06-20T23:59:44.609Z',
lte: '2019-06-21T00:01:06.957Z',
},
},
},
},
{
$state: { store: 'appState' },
meta: {
alias: null,
disabled: false,
index: '5193f870-d861-11e9-a311-0fa548c5f953',
key: 'products.product_id',
negate: false,
params: { query: 22599 },
type: 'phrase',
},
query: { match_phrase: { 'products.product_id': 22599 } },
},
],
index: '5193f870-d861-11e9-a311-0fa548c5f953',
query: { language: 'kuery', query: '' },
version: true,
sort: [{ order_date: { format: 'strict_date_optional_time', order: 'desc' } }],
},
title: 'Ecommerce Data',
version: '8.15.0',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,45 @@ export default ({ getService }: FtrProviderContext) => {
browserTimezone: 'UTC',
objectType: 'search',
searchSource: {
fields: [
{ field: 'order_date', include_unmapped: true },
{ field: 'order_id', include_unmapped: true },
{ field: 'products.product_id', include_unmapped: true },
],
filter: [
{
meta: {
field: 'order_date',
index: '5193f870-d861-11e9-a311-0fa548c5f953',
params: {},
},
query: {
range: {
order_date: {
format: 'strict_date_optional_time',
gte: '2019-06-20T23:59:44.609Z',
lte: '2019-06-21T00:01:06.957Z',
},
},
},
},
{
$state: { store: 'appState' },
meta: {
alias: null,
disabled: false,
index: '5193f870-d861-11e9-a311-0fa548c5f953',
key: 'products.product_id',
negate: false,
params: { query: 22599 },
type: 'phrase',
},
query: { match_phrase: { 'products.product_id': 22599 } },
},
],
index: '5193f870-d861-11e9-a311-0fa548c5f953',
query: { language: 'kuery', query: '' },
version: true,
sort: [{ order_date: { format: 'strict_date_optional_time', order: 'desc' } }],
},
title: 'Ecommerce Data',
version: '8.15.0',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,12 @@
* 2.0.
*/

import { DISCOVER_APP_LOCATOR } from '@kbn/discover-plugin/common';
import {
CSV_REPORT_TYPE_V2,
type JobParamsCsvFromSavedObject,
} from '@kbn/reporting-export-types-csv-common';
import type { CookieCredentials, InternalRequestHeader } from '@kbn/ftr-common-functional-services';
import { ReportApiJSON } from '@kbn/reporting-common/types';
import type { FtrProviderContext } from '../../../ftr_provider_context';

export default ({ getPageObjects, getService }: FtrProviderContext) => {
const esArchiver = getService('esArchiver');
const kibanaServer = getService('kibanaServer');
const log = getService('log');
const testSubjects = getService('testSubjects');
Expand All @@ -25,6 +21,13 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
let cookieCredentials: CookieCredentials;
let internalReqHeader: InternalRequestHeader;

const archives: Record<string, { data: string; savedObjects: string }> = {
ecommerce: {
data: 'x-pack/test/functional/es_archives/reporting/ecommerce',
savedObjects: 'x-pack/test/functional/fixtures/kbn_archiver/reporting/ecommerce',
},
};

const navigateToReportingManagement = async () => {
log.debug(`navigating to reporting management app`);
await retry.tryForTime(60 * 1000, async () => {
Expand All @@ -35,56 +38,82 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
});
};

describe('Reporting Management app', function () {
// security_exception: action [indices:admin/create] is unauthorized for user [elastic] with effective roles [superuser] on restricted indices [.reporting-2020.04.19], this action is granted by the index privileges [create_index,manage,all]
this.tags('failsOnMKI');

let reportJob: ReportApiJSON;
describe('Reporting Management app', () => {
let job: ReportApiJSON;
let path: string;

const savedObjectsArchive = 'test/functional/fixtures/kbn_archiver/discover';

const job: JobParamsCsvFromSavedObject = {
browserTimezone: 'UTC',
objectType: 'search',
version: '8.10.0',
locatorParams: [
{
id: DISCOVER_APP_LOCATOR,
version: 'reporting',
// the create job API requires a valid savedSearchId
params: { savedSearchId: 'ab12e3c0-f231-11e6-9486-733b1ac9221a' },
},
],
};

// Kibana CI and MKI use different users
before('initialize saved object archive', async () => {
cookieCredentials = await samlAuth.getM2MApiCookieCredentialsWithRoleScope('admin');
internalReqHeader = samlAuth.getInternalRequestHeader();

// add test saved search object
await kibanaServer.importExport.load(savedObjectsArchive);
await esArchiver.load(archives.ecommerce.data);
await kibanaServer.importExport.load(archives.ecommerce.savedObjects);

// generate a report that can be tested to show in the listing
const result = await reportingAPI.createReportJobInternal(
CSV_REPORT_TYPE_V2,
job,
// generate a test report to ensure the user is able to see it in the listing
({ job, path } = await reportingAPI.createReportJobInternal(
'csv_searchsource',
{
browserTimezone: 'UTC',
objectType: 'search',
searchSource: {
fields: [
{ field: 'order_date', include_unmapped: true },
{ field: 'order_id', include_unmapped: true },
{ field: 'products.product_id', include_unmapped: true },
],
filter: [
{
meta: {
field: 'order_date',
index: '5193f870-d861-11e9-a311-0fa548c5f953',
params: {},
},
query: {
range: {
order_date: {
format: 'strict_date_optional_time',
gte: '2019-06-20T23:59:44.609Z',
lte: '2019-06-21T00:01:06.957Z',
},
},
},
},
{
$state: { store: 'appState' },
meta: {
alias: null,
disabled: false,
index: '5193f870-d861-11e9-a311-0fa548c5f953',
key: 'products.product_id',
negate: false,
params: { query: 22599 },
type: 'phrase',
},
query: { match_phrase: { 'products.product_id': 22599 } },
},
],
index: '5193f870-d861-11e9-a311-0fa548c5f953',
query: { language: 'kuery', query: '' },
sort: [{ order_date: { format: 'strict_date_optional_time', order: 'desc' } }],
},
title: 'Ecommerce Data',
version: '8.15.0',
},
cookieCredentials,
internalReqHeader
);

path = result.path;
reportJob = result.job;
));
});

after('clean up archives', async () => {
await kibanaServer.importExport.unload(savedObjectsArchive);
await reportingAPI.waitForJobToFinish(path, cookieCredentials, internalReqHeader);
await esArchiver.unload(archives.ecommerce.data);
await kibanaServer.importExport.unload(archives.ecommerce.savedObjects);
});

it(`user sees a job they've created`, async () => {
await navigateToReportingManagement();
await testSubjects.existOrFail(`viewReportingLink-${reportJob.id}`);
await testSubjects.existOrFail(`viewReportingLink-${job.id}`);
});
});
};

0 comments on commit 0b87e90

Please sign in to comment.