[8.x] FTR - optimize service initialization (#212421) (#213213)

# Backport

This will backport the following commits from `main` to `8.x`:
- [FTR - optimize service initialization
(#212421)](https://github.com/elastic/kibana/pull/212421)

<!--- Backport version: 9.6.6 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Robert
Oskamp","email":"robert.oskamp@elastic.co"},"sourceCommit":{"committedDate":"2025-02-27T10:35:47Z","message":"FTR
- optimize service initialization (#212421)\n\n## Summary\n\nThis PR
optimizes the FTR service initialization by not loading UI\nservice for
API tests and by removing retries during test user setup\n\n##
Changes\n\n- Remove loading of common UI services from common services
(UI services\nshould not be loaded for API tests)\n- Move `security`
service from `@kbn/ftr-common-functional-ui-services`\nto
`@kbn/ftr-common-functional-services` as it should be available to\nAPI
tests as well\n- Only try once to delete `testUser` during init (this
user usually does\nnot exist on a fresh deployment - and if it does, a
single delete\nrequest is enough to get rid of it)\n\n## Benchmark
results\n\n**These changes will reduce FTR CI runtime overall by ~100
minutes**\n🚀\nDue to parallel workers in CI, the effective
runtime of the whole CI job\nwill be less than that.\n\n- The removal of
UI service loading (which includes starting a browser\ninstance) for API
tests reduces init time by ~0.5 seconds. With 313 API\nconfigs that are
started on CI, this reduces the runtime overall by ~156\nseconds / ~2.6
minutes.\n- The removal of test user delete retries reduces init time by
~10\nseconds. With 589 FTR configs that are started on CI, this reduces
the\nruntime overall by ~5890 seconds / ~98 minutes.\n- These numbers
have been taken on a local machine and since CI workers\nare usually
slower, we should see at least this amount of improvement if\nnot more
in
CI.","sha":"7a381afb177c81ed4d0704cfcec49e6da7179376","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","backport
missing","Team:Fleet","v9.0.0","backport:version","v9.1.0","v8.19.0"],"title":"FTR
- optimize service
initialization","number":212421,"url":"https://github.com/elastic/kibana/pull/212421","mergeCommit":{"message":"FTR
- optimize service initialization (#212421)\n\n## Summary\n\nThis PR
optimizes the FTR service initialization by not loading UI\nservice for
API tests and by removing retries during test user setup\n\n##
Changes\n\n- Remove loading of common UI services from common services
(UI services\nshould not be loaded for API tests)\n- Move `security`
service from `@kbn/ftr-common-functional-ui-services`\nto
`@kbn/ftr-common-functional-services` as it should be available to\nAPI
tests as well\n- Only try once to delete `testUser` during init (this
user usually does\nnot exist on a fresh deployment - and if it does, a
single delete\nrequest is enough to get rid of it)\n\n## Benchmark
results\n\n**These changes will reduce FTR CI runtime overall by ~100
minutes**\n🚀\nDue to parallel workers in CI, the effective
runtime of the whole CI job\nwill be less than that.\n\n- The removal of
UI service loading (which includes starting a browser\ninstance) for API
tests reduces init time by ~0.5 seconds. With 313 API\nconfigs that are
started on CI, this reduces the runtime overall by ~156\nseconds / ~2.6
minutes.\n- The removal of test user delete retries reduces init time by
~10\nseconds. With 589 FTR configs that are started on CI, this reduces
the\nruntime overall by ~5890 seconds / ~98 minutes.\n- These numbers
have been taken on a local machine and since CI workers\nare usually
slower, we should see at least this amount of improvement if\nnot more
in
CI.","sha":"7a381afb177c81ed4d0704cfcec49e6da7179376"}},"sourceBranch":"main","suggestedTargetBranches":["9.0","8.x"],"targetPullRequestStates":[{"branch":"9.0","label":"v9.0.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/212421","number":212421,"mergeCommit":{"message":"FTR
- optimize service initialization (#212421)\n\n## Summary\n\nThis PR
optimizes the FTR service initialization by not loading UI\nservice for
API tests and by removing retries during test user setup\n\n##
Changes\n\n- Remove loading of common UI services from common services
(UI services\nshould not be loaded for API tests)\n- Move `security`
service from `@kbn/ftr-common-functional-ui-services`\nto
`@kbn/ftr-common-functional-services` as it should be available to\nAPI
tests as well\n- Only try once to delete `testUser` during init (this
user usually does\nnot exist on a fresh deployment - and if it does, a
single delete\nrequest is enough to get rid of it)\n\n## Benchmark
results\n\n**These changes will reduce FTR CI runtime overall by ~100
minutes**\n🚀\nDue to parallel workers in CI, the effective
runtime of the whole CI job\nwill be less than that.\n\n- The removal of
UI service loading (which includes starting a browser\ninstance) for API
tests reduces init time by ~0.5 seconds. With 313 API\nconfigs that are
started on CI, this reduces the runtime overall by ~156\nseconds / ~2.6
minutes.\n- The removal of test user delete retries reduces init time by
~10\nseconds. With 589 FTR configs that are started on CI, this reduces
the\nruntime overall by ~5890 seconds / ~98 minutes.\n- These numbers
have been taken on a local machine and since CI workers\nare usually
slower, we should see at least this amount of improvement if\nnot more
in
CI.","sha":"7a381afb177c81ed4d0704cfcec49e6da7179376"}},{"branch":"8.x","label":"v8.19.0","branchLabelMappingKey":"^v8.19.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->
This commit is contained in:
Robert Oskamp 2025-03-05 13:36:38 +01:00 committed by GitHub
parent 72602b16b9
commit 33b3901795
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 17 additions and 27 deletions

View file

@ -45,3 +45,4 @@ export { DeploymentService } from './services/deployment';
export { IndexPatternsService } from './services/index_patterns';
export { RandomnessService } from './services/randomness';
export { KibanaSupertestProvider, ElasticsearchSupertestProvider } from './services/supertest';
export { SecurityService } from './services/security';

View file

@ -21,6 +21,7 @@ import { RandomnessService } from './randomness';
import { SupertestWithoutAuthProvider } from './supertest_without_auth';
import { SamlAuthProvider } from './saml_auth';
import { KibanaSupertestProvider, ElasticsearchSupertestProvider } from './supertest';
import { SecurityServiceProvider } from './security';
export const services = {
es: EsProvider,
@ -38,4 +39,5 @@ export const services = {
supertest: KibanaSupertestProvider,
esSupertest: ElasticsearchSupertestProvider,
supertestWithoutAuth: SupertestWithoutAuthProvider,
security: SecurityServiceProvider,
};

View file

@ -10,8 +10,6 @@
import { format as formatUrl } from 'url';
import supertest from 'supertest';
import type { Browser } from '../browser';
import type { TestSubjects } from '../test_subjects';
import { Role } from './role';
import { User } from './user';
import { FtrService, FtrProviderContext } from '../ftr_provider_context';
@ -23,15 +21,13 @@ export class TestUser extends FtrService {
private readonly config = this.ctx.getService('config');
private readonly log = this.ctx.getService('log');
private readonly browser: Browser | void =
private readonly browser =
// browser service is not normally available in common.
this.ctx.hasService('browser') ? (this.ctx.getService('browser' as any) as Browser) : undefined;
this.ctx.hasService('browser') ? this.ctx.getService('browser' as any) : undefined;
private readonly testSubjects: TestSubjects | undefined =
private readonly testSubjects =
// testSubject service is not normally available in common.
this.ctx.hasService('testSubjects')
? (this.ctx.getService('testSubjects' as any) as TestSubjects)
: undefined;
this.ctx.hasService('testSubjects') ? this.ctx.getService('testSubjects' as any) : undefined;
constructor(
ctx: FtrProviderContext,
@ -129,7 +125,7 @@ export async function createTestUserService(ctx: FtrProviderContext, role: Role,
// delete the test_user if present (will it error if the user doesn't exist?)
try {
await user.delete(TEST_USER_NAME);
await user.delete(TEST_USER_NAME, { retries: 1 });
} catch (exception) {
log.debug('no test user to delete');
}

View file

@ -32,11 +32,12 @@ export class User {
this.log.debug(`created user ${username}`);
}
public async delete(username: string) {
public async delete(username: string, options?: { retries?: number }) {
this.log.debug(`deleting user ${username}`);
const { data, status, statusText } = await this.kbnClient.request({
path: `/internal/security/users/${username}`,
method: 'DELETE',
retries: options?.retries,
});
if (status !== 204) {
throw new Error(

View file

@ -23,4 +23,3 @@ export {
} from './services/remote/network_profiles';
export type { TimeoutOpt } from './types';
export { TestSubjects } from './services/test_subjects';
export { SecurityService } from './services/security';

View file

@ -13,7 +13,6 @@ import { FindProvider } from './find';
import { TestSubjects } from './test_subjects';
import { BrowserProvider } from './browser';
import { ToastsService } from './toasts';
import { SecurityServiceProvider } from './security';
export const services = {
retryOnStale: RetryOnStaleProvider,
@ -22,5 +21,4 @@ export const services = {
testSubjects: TestSubjects,
browser: BrowserProvider,
toasts: ToastsService,
security: SecurityServiceProvider,
};

View file

@ -8,7 +8,6 @@
*/
import { commonFunctionalServices } from '@kbn/ftr-common-functional-services';
import { commonFunctionalUIServices } from '@kbn/ftr-common-functional-ui-services';
// pick only services that work for any FTR config, e.g. 'samlAuth' requires SAML setup in config file
const {
@ -26,11 +25,9 @@ const {
supertest,
esSupertest,
supertestWithoutAuth,
security,
} = commonFunctionalServices;
// pick what was there previously
const { security } = commonFunctionalUIServices;
export const services = {
es,
esArchiver,

View file

@ -9,8 +9,7 @@ import type { Agent as SuperTestAgent } from 'supertest';
import { ELASTIC_HTTP_VERSION_HEADER } from '@kbn/core-http-common';
import { CLOUD_SECURITY_PLUGIN_VERSION } from '@kbn/cloud-security-posture-plugin/common/constants';
import { SecurityService } from '@kbn/ftr-common-functional-ui-services';
import { RoleCredentials } from '@kbn/ftr-common-functional-services';
import { RoleCredentials, SecurityService } from '@kbn/ftr-common-functional-services';
export async function createPackagePolicy(
supertest: SuperTestAgent,

View file

@ -32,7 +32,7 @@ import {
ELASTIC_HTTP_VERSION_HEADER,
X_ELASTIC_INTERNAL_ORIGIN_REQUEST,
} from '@kbn/core-http-common';
import type { SecurityService } from '@kbn/ftr-common-functional-ui-services';
import type { SecurityService } from '@kbn/ftr-common-functional-services';
import basicClusterFixture from './fixtures/basiccluster.json';
import multiClusterFixture from './fixtures/multicluster.json';
import type { FtrProviderContext } from '../../ftr_provider_context';

View file

@ -7,7 +7,6 @@
import { services as kibanaApiIntegrationServices } from '@kbn/test-suites-src/api_integration/services';
import { commonFunctionalServices } from '@kbn/ftr-common-functional-services';
import { commonFunctionalUIServices } from '@kbn/ftr-common-functional-ui-services';
import { InfraLogViewsServiceProvider } from './infra_log_views';
import { SpacesServiceProvider } from './spaces';
import { BsearchSecureService } from './bsearch_secure';
@ -16,7 +15,6 @@ import { InfraSynthtraceKibanaClientProvider } from './infra_synthtrace_kibana_c
export const services = {
...commonFunctionalServices,
...commonFunctionalUIServices,
infraLogViews: InfraLogViewsServiceProvider,
supertest: kibanaApiIntegrationServices.supertest,
spaces: SpacesServiceProvider,

View file

@ -5,7 +5,7 @@
* 2.0.
*/
import type { SecurityService } from '@kbn/ftr-common-functional-ui-services';
import type { SecurityService } from '@kbn/ftr-common-functional-services';
export const testUsers: {
[rollName: string]: { username: string; password: string; permissions?: any };

View file

@ -8,7 +8,7 @@
/* eslint-disable no-console */
import { difference, union } from 'lodash';
import type { SecurityService } from '@kbn/ftr-common-functional-ui-services';
import type { SecurityService } from '@kbn/ftr-common-functional-services';
import { Elasticsearch, Kibana } from '..';
import { callKibana, isAxiosError } from './call_kibana';

View file

@ -5,7 +5,7 @@
* 2.0.
*/
import { asyncForEach } from '@kbn/std';
import type { SecurityService } from '@kbn/ftr-common-functional-ui-services';
import type { SecurityService } from '@kbn/ftr-common-functional-services';
import { ProfilingUsername, profilingUsers } from './authentication';
import { AbortError, callKibana } from './helpers/call_kibana';
import { createOrUpdateUser } from './helpers/create_or_update_user';

View file

@ -5,7 +5,7 @@
* 2.0.
*/
import type { SecurityService } from '@kbn/ftr-common-functional-ui-services';
import type { SecurityService } from '@kbn/ftr-common-functional-services';
export const usersAndRolesFactory = (security: SecurityService) => ({
createRole: async ({ name, privileges }: { name: string; privileges: any }) => {

View file

@ -49,7 +49,6 @@
"@kbn/elastic-assistant-common",
"@kbn/search-types",
"@kbn/security-plugin",
"@kbn/ftr-common-functional-ui-services",
"@kbn/spaces-plugin",
"@kbn/elastic-assistant-plugin",
"@kbn/test-suites-src",