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/Tests] Improvements for task stability in serverless tests #195841

Merged
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
11351b7
fix "management: deletion" test by loading necessary archives
tsullivan Oct 10, 2024
2c3ae7b
Merge branch 'main' into reporting/tests-serverless-improvements-ii
tsullivan Oct 17, 2024
d7a2995
Merge branch 'main' into reporting/tests-serverless-improvements-ii
tsullivan Oct 17, 2024
4402169
Merge branch 'main' into reporting/tests-serverless-improvements-ii
tsullivan Oct 18, 2024
a3ae988
use samlAuth service and cookieHeader for internal API
dmlemeshko Oct 18, 2024
a2a8e1b
Merge branch 'main' into reporting/tests-serverless-improvements-ii
dmlemeshko Oct 18, 2024
46ba5d8
Merge branch 'main' into reporting/tests-serverless-improvements-ii
tsullivan Oct 21, 2024
dce635b
unload es archive and delete saved objects after the test run
tsullivan Oct 21, 2024
11a32e1
Use cookie credentials for internal requests
tsullivan Oct 21, 2024
a5fb38a
Use cookie credentials instead of role credentials
tsullivan Oct 21, 2024
4a4f9c2
Merge branch 'main' into reporting/tests-serverless-improvements-ii
tsullivan Oct 22, 2024
0bea1a5
use api key credentials for datastream management api
tsullivan Oct 22, 2024
2d2c790
Merge branch 'main' into reporting/tests-serverless-improvements-ii
tsullivan Oct 22, 2024
db3fa48
invalidate the api key in the after() block of test
tsullivan Oct 23, 2024
f530496
Merge branch 'main' into reporting/tests-serverless-improvements-ii
tsullivan Oct 23, 2024
b3f9765
Getting the internalReqHeader is not async
tsullivan Oct 23, 2024
5305cdd
Ensure the functional test job is allowed to finish
tsullivan Oct 23, 2024
631e9f1
Fix internalReqHeader
tsullivan Oct 23, 2024
c795446
Fix an instance of waiting for the job to finish
tsullivan Oct 23, 2024
03c5617
Merge branch 'main' into reporting/tests-serverless-improvements-ii
tsullivan Oct 23, 2024
dd877b2
fix a broken test
tsullivan Oct 23, 2024
ab5a79e
Merge branch 'reporting/tests-serverless-improvements-ii' of github.c…
tsullivan Oct 23, 2024
97d4836
Merge branch 'main' into reporting/tests-serverless-improvements-ii
tsullivan Oct 23, 2024
8e4ee0f
remove inessential differences
tsullivan Oct 23, 2024
ba8a7a0
Merge branch 'main' into reporting/tests-serverless-improvements-ii
tsullivan Oct 24, 2024
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

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');
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NOTE: cookie credentials do not need to be invalidated after the test

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);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test was BROKEN since the original PR. The snapshot showed a 404 error. This is now fixed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh no :( typical for snapshot tests in a hidden file

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