Skip to content

Commit 7a381af

Browse files
authored
FTR - optimize service initialization (#212421)
## Summary This PR optimizes the FTR service initialization by not loading UI service for API tests and by removing retries during test user setup ## Changes - Remove loading of common UI services from common services (UI services should not be loaded for API tests) - Move `security` service from `@kbn/ftr-common-functional-ui-services` to `@kbn/ftr-common-functional-services` as it should be available to API tests as well - Only try once to delete `testUser` during init (this user usually does not exist on a fresh deployment - and if it does, a single delete request is enough to get rid of it) ## Benchmark results **These changes will reduce FTR CI runtime overall by ~100 minutes** :rocket: Due to parallel workers in CI, the effective runtime of the whole CI job will be less than that. - The removal of UI service loading (which includes starting a browser instance) for API tests reduces init time by ~0.5 seconds. With 313 API configs that are started on CI, this reduces the runtime overall by ~156 seconds / ~2.6 minutes. - The removal of test user delete retries reduces init time by ~10 seconds. With 589 FTR configs that are started on CI, this reduces the runtime overall by ~5890 seconds / ~98 minutes. - These numbers have been taken on a local machine and since CI workers are usually slower, we should see at least this amount of improvement if not more in CI.
1 parent 9726041 commit 7a381af

File tree

20 files changed

+17
-27
lines changed

20 files changed

+17
-27
lines changed

src/platform/packages/shared/kbn-ftr-common-functional-services/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,4 @@ export { IndexPatternsService } from './services/index_patterns';
4646
export { RandomnessService } from './services/randomness';
4747
export { KibanaSupertestProvider, ElasticsearchSupertestProvider } from './services/supertest';
4848
export { retryForSuccess } from './services/retry/retry_for_success';
49+
export { SecurityService } from './services/security';

src/platform/packages/shared/kbn-ftr-common-functional-services/services/all.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { RandomnessService } from './randomness';
2121
import { SupertestWithoutAuthProvider } from './supertest_without_auth';
2222
import { SamlAuthProvider } from './saml_auth';
2323
import { KibanaSupertestProvider, ElasticsearchSupertestProvider } from './supertest';
24+
import { SecurityServiceProvider } from './security';
2425

2526
export const services = {
2627
es: EsProvider,
@@ -38,4 +39,5 @@ export const services = {
3839
supertest: KibanaSupertestProvider,
3940
esSupertest: ElasticsearchSupertestProvider,
4041
supertestWithoutAuth: SupertestWithoutAuthProvider,
42+
security: SecurityServiceProvider,
4143
};
Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
import { format as formatUrl } from 'url';
1111
import supertest from 'supertest';
1212

13-
import type { Browser } from '../browser';
14-
import type { TestSubjects } from '../test_subjects';
1513
import { Role } from './role';
1614
import { User } from './user';
1715
import { FtrService, FtrProviderContext } from '../ftr_provider_context';
@@ -23,15 +21,13 @@ export class TestUser extends FtrService {
2321
private readonly config = this.ctx.getService('config');
2422
private readonly log = this.ctx.getService('log');
2523

26-
private readonly browser: Browser | void =
24+
private readonly browser =
2725
// browser service is not normally available in common.
28-
this.ctx.hasService('browser') ? (this.ctx.getService('browser' as any) as Browser) : undefined;
26+
this.ctx.hasService('browser') ? this.ctx.getService('browser' as any) : undefined;
2927

30-
private readonly testSubjects: TestSubjects | undefined =
28+
private readonly testSubjects =
3129
// testSubject service is not normally available in common.
32-
this.ctx.hasService('testSubjects')
33-
? (this.ctx.getService('testSubjects' as any) as TestSubjects)
34-
: undefined;
30+
this.ctx.hasService('testSubjects') ? this.ctx.getService('testSubjects' as any) : undefined;
3531

3632
constructor(
3733
ctx: FtrProviderContext,
@@ -129,7 +125,7 @@ export async function createTestUserService(ctx: FtrProviderContext, role: Role,
129125

130126
// delete the test_user if present (will it error if the user doesn't exist?)
131127
try {
132-
await user.delete(TEST_USER_NAME);
128+
await user.delete(TEST_USER_NAME, { retries: 1 });
133129
} catch (exception) {
134130
log.debug('no test user to delete');
135131
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,12 @@ export class User {
3232
this.log.debug(`created user ${username}`);
3333
}
3434

35-
public async delete(username: string) {
35+
public async delete(username: string, options?: { retries?: number }) {
3636
this.log.debug(`deleting user ${username}`);
3737
const { data, status, statusText } = await this.kbnClient.request({
3838
path: `/internal/security/users/${username}`,
3939
method: 'DELETE',
40+
retries: options?.retries,
4041
});
4142
if (status !== 204) {
4243
throw new Error(

src/platform/packages/shared/kbn-ftr-common-functional-ui-services/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,3 @@ export {
2323
} from './services/remote/network_profiles';
2424
export type { TimeoutOpt } from './types';
2525
export { TestSubjects } from './services/test_subjects';
26-
export { SecurityService } from './services/security';

0 commit comments

Comments
 (0)