Skip to content

Commit

Permalink
[Reporting/Tests] Improvements for task stability in serverless tests (
Browse files Browse the repository at this point in the history
…#195841)

## Summary

Continuation of #192417. This PR
attempts to further improve task stability of the reporting task. The
original goals were:

1. Ensure the test data that is needed for the report gets loaded
2. Wait for report jobs to finish before the test completes. Errors in
task success metrics also occur if the task triggers after resources for
the report, such as a saved search, are removed before the task
triggers.

During development of this PR, more issues were discovered:

3. Requests to internal endpoints should use cookie credentials
4. The CSV export from ES|QL test was hitting a 404 error when it tried
to download the CSV. That error was included in the test. In other
words, that test was fundamentaly broken.

## Testing locally
1. Run the serverless functional tests:
1. **Reporting management app**: `node scripts/functional_tests.js
--config=x-pack/test_serverless/functional/test_suites/observability/common_configs/config.group1.ts
--grep=Reporting`
1. **CSV export in Discover**: `node scripts/functional_tests.js
--config=x-pack/test_serverless/functional/test_suites/observability/common_configs/config.group6.ts
--grep=CSV`
1. **Reporting API integration tests**: `node
scripts/functional_tests.js
--config=x-pack/test_serverless/api_integration/test_suites/search/common_configs/config.group1.ts
--grep=Reporting`
3. Ensure that there are no error logs from Task Manager regarding task
failure

---------

Co-authored-by: Dzmitry Lemechko <[email protected]>
  • Loading branch information
tsullivan and dmlemeshko authored Oct 24, 2024
1 parent 8f36175 commit 4c0b5c5
Show file tree
Hide file tree
Showing 7 changed files with 191 additions and 154 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ import expect from '@kbn/expect';
import request from 'supertest';

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

export default ({ getService }: FtrProviderContext) => {
const es = getService('es');
const supertest = getService('supertest');
const supertestWithoutAuth = getService('supertestWithoutAuth');
const esArchiver = getService('esArchiver');
const log = getService('log');
const reportingAPI = getService('svlReportingApi');
const svlCommonApi = getService('svlCommonApi');
const svlUserManager = getService('svlUserManager');
let roleAuthc: RoleCredentials;
const samlAuth = getService('samlAuth');
let cookieCredentials: CookieCredentials;
let internalReqHeader: InternalRequestHeader;

// Helper function
Expand All @@ -38,7 +38,12 @@ export default ({ getService }: FtrProviderContext) => {
};
log.info(`sending request for query: ${JSON.stringify(job.locatorParams[0].params.query)}`);

return await reportingAPI.createReportJobInternal('csv_v2', job, roleAuthc, internalReqHeader);
return await reportingAPI.createReportJobInternal(
'csv_v2',
job,
cookieCredentials,
internalReqHeader
);
};

describe('CSV Generation from ES|QL', () => {
Expand Down Expand Up @@ -84,7 +89,7 @@ export default ({ getService }: FtrProviderContext) => {
};
before(async () => {
await loadTimelessData();
roleAuthc = await svlUserManager.createM2mApiKeyWithRoleScope('admin');
cookieCredentials = await samlAuth.getM2MApiCookieCredentialsWithRoleScope('admin');
internalReqHeader = svlCommonApi.getInternalRequestHeader();
});

Expand Down Expand Up @@ -112,8 +117,8 @@ export default ({ getService }: FtrProviderContext) => {
},
],
}));
await reportingAPI.waitForJobToFinish(path, roleAuthc, internalReqHeader);
response = await supertest.get(path);
await reportingAPI.waitForJobToFinish(path, cookieCredentials, internalReqHeader);
response = await supertestWithoutAuth.get(path).set(cookieCredentials);
csvFile = response.text;
});

Expand Down Expand Up @@ -184,8 +189,8 @@ export default ({ getService }: FtrProviderContext) => {
],
title: 'Untitled discover search',
}));
await reportingAPI.waitForJobToFinish(path, roleAuthc, internalReqHeader);
response = await supertest.get(path);
await reportingAPI.waitForJobToFinish(path, cookieCredentials, internalReqHeader);
response = await supertestWithoutAuth.get(path).set(cookieCredentials);
csvFile = response.text;
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@
*/

import { expect } from 'expect';
import {
CookieCredentials,
InternalRequestHeader,
RoleCredentials,
} from '@kbn/ftr-common-functional-services';
import { FtrProviderContext } from '../../../ftr_provider_context';
import { InternalRequestHeader, RoleCredentials } from '../../../../shared/services';

export default function ({ getService }: FtrProviderContext) {
const esArchiver = getService('esArchiver');
Expand All @@ -16,7 +20,9 @@ export default function ({ getService }: FtrProviderContext) {
const svlCommonApi = getService('svlCommonApi');
const supertestWithoutAuth = getService('supertestWithoutAuth');
const svlUserManager = getService('svlUserManager');
const samlAuth = getService('samlAuth');
let roleAuthc: RoleCredentials;
let cookieCredentials: CookieCredentials;
let internalReqHeader: InternalRequestHeader;

const archives: Record<string, { data: string; savedObjects: string }> = {
Expand All @@ -30,12 +36,13 @@ export default function ({ getService }: FtrProviderContext) {
const generatedReports = new Set<string>();
before(async () => {
roleAuthc = await svlUserManager.createM2mApiKeyWithRoleScope('admin');
cookieCredentials = await samlAuth.getM2MApiCookieCredentialsWithRoleScope('admin');
internalReqHeader = svlCommonApi.getInternalRequestHeader();

await esArchiver.load(archives.ecommerce.data);
await kibanaServer.importExport.load(archives.ecommerce.savedObjects);

const { job } = await reportingAPI.createReportJobInternal(
const { job, path } = await reportingAPI.createReportJobInternal(
'csv_searchsource',
{
browserTimezone: 'UTC',
Expand All @@ -48,16 +55,17 @@ export default function ({ getService }: FtrProviderContext) {
title: 'Ecommerce Data',
version: '8.15.0',
},
roleAuthc,
cookieCredentials,
internalReqHeader
);
await reportingAPI.waitForJobToFinish(path, cookieCredentials, internalReqHeader);

generatedReports.add(job.id);
});

after(async () => {
for (const reportId of generatedReports) {
await reportingAPI.deleteReport(reportId, roleAuthc, internalReqHeader);
await reportingAPI.deleteReport(reportId, cookieCredentials, internalReqHeader);
}

await esArchiver.unload(archives.ecommerce.data);
Expand All @@ -69,7 +77,7 @@ export default function ({ getService }: FtrProviderContext) {
const { status, body } = await supertestWithoutAuth
.get(`/api/index_management/data_streams/.kibana-reporting`)
.set(internalReqHeader)
.set(roleAuthc.apiKeyHeader);
.set(roleAuthc.apiKeyHeader); // use API key since the datastream management API is a public endpoint

svlCommonApi.assertResponseStatusCode(200, status, body);

Expand Down
Loading

0 comments on commit 4c0b5c5

Please sign in to comment.