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

[Reporting] Test cleanup fixes 2 #191122

Closed
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ export const commonJobsRouteHandlerFactory = (
const reportingSetup = reporting.getPluginSetupDeps();
const logger = reportingSetup.logger.get('delete-report');

logger.debug(`Deleting report ${docId}`);

// An "error" event is emitted if an error is
// passed to the `stream.end` callback from
// the _final method of the ContentStream.
Expand All @@ -121,6 +123,48 @@ export const commonJobsRouteHandlerFactory = (
logger.error(err);
});

// 1. Look for a task in task manager associated with the report job
try {
let taskId: string | undefined;
const { taskManager } = await reporting.getPluginStartDeps();
const result = await taskManager.fetch({
query: {
match: {
'task.taskType': 'report:execute',
},
},
size: 1000, // NOTE: this is an arbitrary size that is likely to include all running and pending reporting tasks in most deployments
});

if (result.docs.length > 0) {
// The task params are stored as a string of JSON. In order to find the task that corresponds to
// the report to delete, we need to check each task's params, look for the report id, and see if it
// matches our docId to delete.
for (const task of result.docs) {
const { params } = task;
if (params.id === docId) {
// found the matching task
taskId = task.id;
logger.debug(
`Found a Task Manager task associated with the report being deleted: ${taskId}. Task status: ${task.status}.`
);
break;
}
}
if (taskId) {
// remove the task that was found
await taskManager.remove(taskId);
logger.debug(`Deleted Task Manager task ${taskId}.`);
}
}
} catch (error) {
logger.error(
'Encountered an error in finding a task associated with the report being deleted'
);
logger.error(error);
}

// 2. Remove the report document
try {
// Overwriting existing content with an
// empty buffer to remove all the chunks.
Expand Down
1 change: 1 addition & 0 deletions x-pack/test/accessibility/apps/group3/reporting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
});

after(async () => {
// FIXME: wait for queued report to finish before clean up
await reporting.teardownLogs();
await deleteReportingUser();
});
Expand Down
2 changes: 1 addition & 1 deletion x-pack/test/functional/apps/discover/reporting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
await PageObjects.discover.selectIndexPattern('ecommerce');
});

it('generates a report with single timefilter', async () => {
it('exposes a POST URL for a report with single timefilter', async () => {
await PageObjects.discover.clickNewSearchButton();
await PageObjects.timePicker.setCommonlyUsedTime('Last_24 hours');
await PageObjects.discover.saveSearch('single-timefilter-search');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@ export default function ({ getService }: FtrProviderContext) {
describe('Data Stream', () => {
before(async () => {
await reportingAPI.initEcommerce();

// for this test, we don't need to wait for the job to finish or verify the result
await reportingAPI.postJob(
`/api/reporting/generate/csv_searchsource?jobParams=%28browserTimezone%3AUTC%2Ccolumns%3A%21%28%29%2CobjectType%3Asearch%2CsearchSource%3A%28fields%3A%21%28%28field%3A%27%2A%27%2Cinclude_unmapped%3Atrue%29%29%2Cfilter%3A%21%28%28meta%3A%28field%3A%27%40timestamp%27%2Cindex%3A%27logstash-%2A%27%2Cparams%3A%28%29%29%2Cquery%3A%28range%3A%28%27%40timestamp%27%3A%28format%3Astrict_date_optional_time%2Cgte%3A%272015-09-22T09%3A17%3A53.728Z%27%2Clte%3A%272015-09-22T09%3A30%3A50.786Z%27%29%29%29%29%2C%28%27%24state%27%3A%28store%3AappState%29%2Cmeta%3A%28alias%3A%21n%2Cdisabled%3A%21f%2Cindex%3A%27logstash-%2A%27%2Ckey%3Aquery%2Cnegate%3A%21f%2Ctype%3Acustom%2Cvalue%3A%27%7B%22bool%22%3A%7B%22minimum_should_match%22%3A1%2C%22should%22%3A%5B%7B%22match_phrase%22%3A%7B%22%40tags%22%3A%22info%22%7D%7D%5D%7D%7D%27%29%2Cquery%3A%28bool%3A%28minimum_should_match%3A1%2Cshould%3A%21%28%28match_phrase%3A%28%27%40tags%27%3Ainfo%29%29%29%29%29%29%29%2Cindex%3A%27logstash-%2A%27%2Cquery%3A%28language%3Akuery%2Cquery%3A%27%27%29%2Csort%3A%21%28%28%27%40timestamp%27%3A%28format%3Astrict_date_optional_time%2Corder%3Adesc%29%29%29%29%2Ctitle%3A%27A%20saved%20search%20with%20match_phrase%20filter%20and%20no%20columns%20selected%27%2Cversion%3A%278.15.0%27%29`
);
});

after(async () => {
// FIXME wait for report to complete before cleanup
await reportingAPI.deleteAllReports();
await reportingAPI.teardownEcommerce();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export default function ({ getService }: FtrProviderContext) {
});

after(async () => {
// FIXME wait for reports to complete before teardown
await reportingAPI.teardownLogs();
await reportingAPI.makeAllReportingIndicesUnmanaged(); // ensure that a delete phase does not remove the index while future tests are running
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export default function ({ getService }: FtrProviderContext) {
});

after(async () => {
// FIXME wait for reports to complete before teardown
await reportingAPI.teardownLogs();
await esArchiver.unload('x-pack/test/functional/es_archives/logstash_functional');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ export function createScenarios({ getService }: Pick<FtrProviderContext, 'getSer
return job?.output?.error_code;
};

// FIXME: remove this and use the delete API for each report created during testing
const deleteAllReports = async () => {
log.debug('ReportingAPI.deleteAllReports');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export default ({ getService, getPageObjects }: FtrProviderContext) => {
await reportingFunctional.initEcommerce();
});
after(async () => {
// FIXME: wait for the report job to finish before clean up
await reportingFunctional.teardownEcommerce();
});

Expand All @@ -47,7 +48,6 @@ export default ({ getService, getPageObjects }: FtrProviderContext) => {
await PageObjects.common.navigateToApp('reporting');
await PageObjects.common.sleep(3000); // Wait an amount of time for auto-polling to refresh the jobs

// We do not need to wait for the report to finish generating
await (await testSubjects.find('euiCollapsedItemActionsButton')).click();
await (await testSubjects.find('reportOpenInKibanaApp')).click();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export default function ({ getService }: FtrProviderContext) {
await esArchiver.load(archives.ecommerce.data);
await kibanaServer.importExport.load(archives.ecommerce.savedObjects);

// for this test, we don't need to wait for the job to finish or verify the result
await reportingAPI.createReportJobInternal(
'csv_searchsource',
{
Expand All @@ -54,6 +53,7 @@ export default function ({ getService }: FtrProviderContext) {
});

after(async () => {
// FIXME wait for job to finish before clean up
await reportingAPI.deleteAllReports(roleAuthc, internalReqHeader);
await esArchiver.unload(archives.ecommerce.data);
await kibanaServer.importExport.unload(archives.ecommerce.savedObjects);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export default ({ getService }: FtrProviderContext) => {
internalReqHeader = svlCommonApi.getInternalRequestHeader();
});
after(async () => {
// FIXME wait for job to finish before invalidating user
await svlUserManager.invalidateM2mApiKeyWithRoleScope(adminUser);
});

Expand Down Expand Up @@ -63,7 +64,6 @@ export default ({ getService }: FtrProviderContext) => {
});

it(`user can delete a report they've created`, async () => {
// for this test, we don't need to wait for the job to finish or verify the result
const response = await supertestWithoutAuth
.delete(`${INTERNAL_ROUTES.JOBS.DELETE_PREFIX}/${reportJob.id}`)
.set(...API_HEADER)
Expand Down