[ska][x-pack] relocate api_integration tests [1] (#218470)

Part of https://github.com/elastic/kibana-team/issues/1503

This PR creates new "test-helper" package
`@kbn/test-suites-xpack-platform` to store Platform functional tests.

It copies few simple FTR services, base config file and context provider
to the new structure.
First chunk of tests is moved as well:
x-pack/**test**/api_integration/apis =>
x-pack/**platform/test**/api_integration/apis

<img width="514" alt="image"
src="https://github.com/user-attachments/assets/ddd84d28-cba4-41fe-bdeb-32a14b4e3f17"
/>

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Dzmitry Lemechko 2025-04-25 18:58:11 +02:00 committed by GitHub
parent 65ec0a44b3
commit d8ff5220f6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
56 changed files with 595 additions and 27 deletions

View file

@ -9,6 +9,7 @@ disabled:
- src/platform/test/server_integration/config.base.js
- x-pack/test/functional_with_es_ssl/config.base.ts
- x-pack/test/api_integration/config.ts
- x-pack/platform/test/api_integration/config.ts
- x-pack/test/fleet_api_integration/config.base.ts
- x-pack/test/functional_basic/apps/ml/config.base.ts
- x-pack/test/functional_basic/apps/transform/config.base.ts
@ -153,11 +154,6 @@ enabled:
- x-pack/test/api_integration/apis/cases/config.ts
- x-pack/test/api_integration/apis/content_management/config.ts
- x-pack/test/api_integration/apis/console/config.ts
- x-pack/test/api_integration/apis/es/config.ts
- x-pack/test/api_integration/apis/features/config.ts
- x-pack/test/api_integration/apis/file_upload/config.ts
- x-pack/test/api_integration/apis/grok_debugger/config.ts
- x-pack/test/api_integration/apis/kibana/config.ts
- x-pack/test/api_integration/apis/lists/config.ts
- x-pack/test/api_integration/apis/logstash/config.ts
- x-pack/test/api_integration/apis/management/config.ts
@ -165,14 +161,10 @@ enabled:
- x-pack/test/api_integration/apis/maps/config.ts
- x-pack/test/api_integration/apis/ml/config.ts
- x-pack/test/api_integration/apis/monitoring/config.ts
- x-pack/test/api_integration/apis/monitoring_collection/config.ts
- x-pack/test/api_integration/apis/search/config.ts
- x-pack/test/api_integration/apis/searchprofiler/config.ts
- x-pack/test/api_integration/apis/search_playground/config.ts
- x-pack/test/api_integration/apis/security/config.ts
- x-pack/test/api_integration/apis/spaces/config.ts
- x-pack/test/api_integration/apis/stats/config.ts
- x-pack/test/api_integration/apis/status/config.ts
- x-pack/test/api_integration/apis/telemetry/config.ts
- x-pack/test/api_integration/apis/transform/config.ts
- x-pack/test/api_integration/apis/upgrade_assistant/config.ts
@ -385,3 +377,13 @@ enabled:
- x-pack/test/api_integration/deployment_agnostic/configs/stateful/platform.stateful.config.ts
- x-pack/test/api_integration/apis/cloud/config.ts
- x-pack/test/api_integration/apis/cloud/saml.config.ts
# configs migrated to the new Kibana architecture
- x-pack/platform/test/api_integration/apis/features/config.ts
- x-pack/platform/test/api_integration/apis/es/config.ts
- x-pack/platform/test/api_integration/apis/grok_debugger/config.ts
- x-pack/platform/test/api_integration/apis/file_upload/config.ts
- x-pack/platform/test/api_integration/apis/kibana/config.ts
- x-pack/platform/test/api_integration/apis/monitoring_collection/config.ts
- x-pack/platform/test/api_integration/apis/searchprofiler/config.ts
- x-pack/platform/test/api_integration/apis/stats/config.ts
- x-pack/platform/test/api_integration/apis/status/config.ts

View file

@ -763,6 +763,8 @@ module.exports = {
'x-pack/test/apm_api_integration/**/*.ts',
'x-pack/test/functional/apps/**/*.js',
'x-pack/solutions/observability/plugins/apm/**/*.js',
'x-pack/platform/test/*/{tests,test_suites,apis,apps,deployment_agnostic}/**/*',
'x-pack/platform/test/*/*config.*ts',
'x-pack/test/*/{tests,test_suites,apis,apps,deployment_agnostic}/**/*',
'x-pack/test/*/*config.*ts',
'x-pack/test/saved_object_api_integration/*/apis/**/*',

28
.github/CODEOWNERS vendored
View file

@ -938,6 +938,7 @@ x-pack/platform/plugins/shared/streams_app @elastic/streams-program-team
x-pack/platform/plugins/shared/task_manager @elastic/response-ops
x-pack/platform/plugins/shared/timelines @elastic/security-threat-hunting-investigations
x-pack/platform/plugins/shared/triggers_actions_ui @elastic/response-ops
x-pack/platform/test
x-pack/solutions/chat/packages/wc-framework-types-browser @elastic/search-kibana
x-pack/solutions/chat/packages/wc-framework-types-common @elastic/search-kibana
x-pack/solutions/chat/packages/wc-framework-types-server @elastic/search-kibana
@ -1136,7 +1137,7 @@ x-pack/test_serverless/api_integration/test_suites/common/platform_security @ela
/src/platform/test/functional/firefox/discover.config.ts @elastic/kibana-data-discovery
/src/platform/test/functional/fixtures/es_archiver/discover @elastic/kibana-data-discovery
/src/platform/test/api_integration/apis/saved_queries @elastic/kibana-data-discovery
/x-pack/test/api_integration/apis/kibana/kql_telemetry @elastic/kibana-data-discovery @elastic/kibana-visualizations
/x-pack/platform/test/api_integration/apis/kibana/kql_telemetry @elastic/kibana-data-discovery @elastic/kibana-visualizations
/x-pack/test_serverless/functional/es_archives/pre_calculated_histogram @elastic/kibana-data-discovery
/x-pack/test_serverless/functional/es_archives/kibana_sample_data_flights_index_pattern @elastic/kibana-data-discovery
/x-pack/test_serverless/functional/test_suites/security/config.examples.ts @elastic/kibana-data-discovery
@ -1427,7 +1428,7 @@ src/platform/plugins/shared/discover/public/context_awareness/profile_providers/
/x-pack/test/functional/services/monitoring @elastic/stack-monitoring
/x-pack/test/functional/apps/monitoring @elastic/stack-monitoring
/x-pack/test/api_integration/apis/monitoring @elastic/stack-monitoring
/x-pack/test/api_integration/apis/monitoring_collection @elastic/stack-monitoring
/x-pack/platform/test/api_integration/apis/monitoring_collection @elastic/stack-monitoring
/x-pack/test/accessibility/apps/group1/kibana_overview.ts @elastic/stack-monitoring
/x-pack/test/accessibility/apps/group3/stack_monitoring.ts @elastic/stack-monitoring
@ -1579,7 +1580,7 @@ src/platform/plugins/shared/discover/public/context_awareness/profile_providers/
# Machine Learning
/x-pack/test/stack_functional_integration/apps/ml @elastic/ml-ui
/x-pack/test/functional/fixtures/kbn_archiver/ml @elastic/ml-ui
/x-pack/test/api_integration/apis/file_upload @elastic/ml-ui
/x-pack/platform/test/api_integration/apis/file_upload @elastic/ml-ui
/x-pack/test/accessibility/apps/group2/ml.ts @elastic/ml-ui
/x-pack/test/accessibility/apps/group2/ml_* @elastic/ml-ui
/x-pack/test/accessibility/apps/group3/ml_embeddables_in_dashboard.ts @elastic/ml-ui
@ -1710,7 +1711,10 @@ src/platform/plugins/shared/discover/public/context_awareness/profile_providers/
/x-pack/test/api_integration/services/index.ts @elastic/appex-qa
/x-pack/test/api_integration/services/es_supertest_without_auth.js @elastic/appex-qa
/x-pack/test/api_integration/config.ts @elastic/appex-qa
/x-pack/test/api_integration/apis/kibana/config.ts @elastic/appex-qa
/x-pack/platform/test/api_integration/config.ts @elastic/appex-qa
/x-pack/platform/test/api_integration/ftr_provider_context.d.ts @elastic/appex-qa
/x-pack/platform/test/api_integration/services @elastic/appex-qa
/x-pack/platform/test/api_integration/apis/kibana/config.ts @elastic/appex-qa
/x-pack/test/tsconfig.json @elastic/appex-qa
/x-pack/test/load @elastic/appex-qa
/src/platform/test/tsconfig.json @elastic/appex-qa
@ -1824,7 +1828,7 @@ src/platform/plugins/shared/discover/public/context_awareness/profile_providers/
/x-pack/test/functional/page_objects/banners_page.ts @elastic/kibana-core
/x-pack/test/common/lib/test_data_loader.ts @elastic/kibana-core
/x-pack/test/api_integration/services/usage_api.ts @elastic/kibana-core
/x-pack/test/api_integration/apis/kibana @elastic/kibana-core
/x-pack/platform/test/api_integration/apis/kibana @elastic/kibana-core
/src/platform/test/api_integration/fixtures/import.ndjson @elastic/kibana-core
/x-pack/test/plugin_api_integration @elastic/kibana-core # Assigned per https://github.com/elastic/kibana/pull/146704
/x-pack/test/localization/ @elastic/kibana-core # Assigned per https://github.com/elastic/kibana/pull/146704
@ -1882,9 +1886,9 @@ src/platform/plugins/shared/discover/public/context_awareness/profile_providers/
/x-pack/test/licensing_plugin @elastic/kibana-core
/x-pack/test/functional_execution_context @elastic/kibana-core
/x-pack/test/api_integration/apis/telemetry @elastic/kibana-core
/x-pack/test/api_integration/apis/status @elastic/kibana-core
/x-pack/test/api_integration/apis/stats @elastic/kibana-core
/x-pack/test/api_integration/apis/kibana/stats @elastic/kibana-core
/x-pack/platform/test/api_integration/apis/status @elastic/kibana-core
/x-pack/platform/test/api_integration/apis/stats @elastic/kibana-core
/x-pack/platform/test/api_integration/apis/kibana/stats @elastic/kibana-core
/x-pack/test/api_integration/deployment_agnostic/apis/core/ @elastic/kibana-core
/x-pack/test/api_integration/deployment_agnostic/apis/saved_objects_management/ @elastic/kibana-core
/x-pack/test_serverless/functional/test_suites/security/config.saved_objects_management.ts @elastic/kibana-core
@ -1920,8 +1924,8 @@ src/platform/plugins/shared/discover/public/context_awareness/profile_providers/
# AppEx Platform Services Security
/x-pack/test_serverless/api_integration/test_suites/common/security_response_headers.ts @elastic/kibana-security
/x-pack/test/api_integration/apis/es @elastic/kibana-security
/x-pack/test/api_integration/apis/features @elastic/kibana-security
/x-pack/platform/test/api_integration/apis/es @elastic/kibana-security
/x-pack/platform/test/api_integration/apis/features @elastic/kibana-security
# Kibana Telemetry
/.telemetryrc.json @elastic/kibana-core
@ -2167,7 +2171,7 @@ x-pack/test/api_integration/apis/management/index_management/inference_endpoints
/x-pack/test/functional/apps/watcher @elastic/kibana-management
/x-pack/test/api_integration/apis/watcher @elastic/kibana-management
/x-pack/test/api_integration/apis/upgrade_assistant @elastic/kibana-core
/x-pack/test/api_integration/apis/searchprofiler @elastic/kibana-management
/x-pack/platform/test/api_integration/apis/searchprofiler @elastic/kibana-management
/x-pack/test/api_integration/apis/console @elastic/kibana-management
/x-pack/test_serverless/**/test_suites/common/index_management/ @elastic/kibana-management
/x-pack/test_serverless/**/test_suites/common/management/index_management/ @elastic/kibana-management
@ -2185,7 +2189,7 @@ x-pack/test/api_integration/apis/management/index_management/inference_endpoints
/x-pack/test/api_integration/deployment_agnostic/apis/management/ @elastic/kibana-management
/x-pack/test/api_integration/deployment_agnostic/apis/painless_lab/ @elastic/kibana-management
/x-pack/test/functional/apps/rollup_job/ @elastic/kibana-management
/x-pack/test/api_integration/apis/grok_debugger @elastic/kibana-management
/x-pack/platform/test/api_integration/apis/grok_debugger @elastic/kibana-management
/x-pack/test/accessibility/apps/group1/advanced_settings.ts @elastic/kibana-management
/x-pack/test/accessibility/apps/**/grok_debugger.ts @elastic/kibana-management
/x-pack/test/accessibility/apps/group1/helpers.ts @elastic/kibana-management

View file

@ -1566,6 +1566,7 @@
"@kbn/test-suites-src": "link:src/platform/test",
"@kbn/test-suites-xpack": "link:x-pack/test",
"@kbn/test-suites-xpack-performance": "link:x-pack/performance",
"@kbn/test-suites-xpack-platform": "link:x-pack/platform/test",
"@kbn/tooling-log": "link:src/platform/packages/shared/kbn-tooling-log",
"@kbn/ts-projects": "link:packages/kbn-ts-projects",
"@kbn/ts-type-check-cli": "link:packages/kbn-ts-type-check-cli",

View file

@ -1974,6 +1974,8 @@
"@kbn/test-suites-xpack/*": ["x-pack/test/*"],
"@kbn/test-suites-xpack-performance": ["x-pack/performance"],
"@kbn/test-suites-xpack-performance/*": ["x-pack/performance/*"],
"@kbn/test-suites-xpack-platform": ["x-pack/platform/test"],
"@kbn/test-suites-xpack-platform/*": ["x-pack/platform/test/*"],
"@kbn/testing-embedded-lens-plugin": ["x-pack/examples/testing_embedded_lens"],
"@kbn/testing-embedded-lens-plugin/*": ["x-pack/examples/testing_embedded_lens/*"],
"@kbn/third-party-lens-navigation-prompt-plugin": ["x-pack/examples/third_party_lens_navigation_prompt"],

View file

@ -5,7 +5,9 @@
* 2.0.
*/
export default function ({ loadTestFile }) {
import type { FtrProviderContext } from '../../ftr_provider_context';
export default function ({ loadTestFile }: FtrProviderContext) {
describe('kibana', () => {
loadTestFile(require.resolve('./stats'));
loadTestFile(require.resolve('./kql_telemetry'));

View file

@ -5,7 +5,9 @@
* 2.0.
*/
export default function ({ loadTestFile }) {
import type { FtrProviderContext } from '../../../ftr_provider_context';
export default function ({ loadTestFile }: FtrProviderContext) {
describe('KQL', () => {
loadTestFile(require.resolve('./kql_telemetry'));
});

View file

@ -8,8 +8,9 @@
import expect from '@kbn/expect';
import { KQL_TELEMETRY_ROUTE_LATEST_VERSION } from '@kbn/data-plugin/common';
import { ELASTIC_HTTP_VERSION_HEADER } from '@kbn/core-http-common';
import type { FtrProviderContext } from '../../../ftr_provider_context';
export default function ({ getService }) {
export default function ({ getService }: FtrProviderContext) {
const supertestNoAuth = getService('supertestWithoutAuth');
const supertest = getService('supertest');

View file

@ -5,7 +5,9 @@
* 2.0.
*/
export default function ({ loadTestFile }) {
import type { FtrProviderContext } from '../../../ftr_provider_context';
export default function ({ loadTestFile }: FtrProviderContext) {
describe('stats', () => {
loadTestFile(require.resolve('./stats'));
});

View file

@ -6,8 +6,9 @@
*/
import expect from '@kbn/expect';
import type { FtrProviderContext } from '../../../ftr_provider_context';
export default function ({ getService }) {
export default function ({ getService }: FtrProviderContext) {
const supertestNoAuth = getService('supertestWithoutAuth');
const supertest = getService('supertest');
const config = getService('config');
@ -15,7 +16,7 @@ export default function ({ getService }) {
describe('/api/stats', () => {
describe('operational stats and usage stats', () => {
// lazy check for uuid for test runs against preexisting services
function isUUID(uuid) {
function isUUID(uuid: string) {
return typeof uuid === 'string' && uuid.length === 36;
}

View file

@ -0,0 +1,49 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { ScoutTestRunConfigCategory } from '@kbn/scout-info';
import { FtrConfigProviderContext } from '@kbn/test';
import { services } from './services';
export async function getApiIntegrationConfig({ readConfigFile }: FtrConfigProviderContext) {
const xPackFunctionalTestsConfig = await readConfigFile(
require.resolve('@kbn/test-suites-xpack/functional/config.base')
);
return {
services,
testConfigCategory: ScoutTestRunConfigCategory.API_TEST,
servers: xPackFunctionalTestsConfig.get('servers'),
security: xPackFunctionalTestsConfig.get('security'),
junit: {
reportName: 'X-Pack API Integration Tests',
},
kbnTestServer: {
...xPackFunctionalTestsConfig.get('kbnTestServer'),
serverArgs: [
...xPackFunctionalTestsConfig.get('kbnTestServer.serverArgs'),
'--xpack.security.session.idleTimeout=3600000', // 1 hour
'--telemetry.optIn=true',
'--xpack.fleet.agents.pollingRequestTimeout=5000', // 5 seconds
'--xpack.ruleRegistry.write.enabled=true',
'--xpack.ruleRegistry.write.enabled=true',
'--xpack.ruleRegistry.write.cache.enabled=false',
'--monitoring_collection.opentelemetry.metrics.prometheus.enabled=true',
],
},
esTestCluster: {
...xPackFunctionalTestsConfig.get('esTestCluster'),
serverArgs: [
...xPackFunctionalTestsConfig.get('esTestCluster.serverArgs'),
'node.attr.name=apiIntegrationTestNode',
`path.repo=/tmp/repo,/tmp/repo_1,/tmp/repo_2,/tmp/cloud-snapshots/`,
],
},
};
}
export default getApiIntegrationConfig;

View file

@ -0,0 +1,12 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { GenericFtrProviderContext } from '@kbn/test';
import { services } from './services';
export type FtrProviderContext = GenericFtrProviderContext<typeof services, {}>;

View file

@ -0,0 +1,52 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { FtrProviderContext } from '../ftr_provider_context';
export function DataViewApiProvider({ getService }: FtrProviderContext) {
const supertest = getService('supertest');
return {
async create({ id, name, title }: { id: string; name: string; title: string }) {
const { body } = await supertest
.post(`/api/content_management/rpc/create`)
.set('kbn-xsrf', 'foo')
.set('x-elastic-internal-origin', 'foo')
.send({
contentTypeId: 'index-pattern',
data: {
fieldAttrs: '{}',
title,
timeFieldName: '@timestamp',
sourceFilters: '[]',
fields: '[]',
fieldFormatMap: '{}',
typeMeta: '{}',
runtimeFieldMap: '{}',
name,
},
options: { id },
version: 1,
});
return body;
},
async delete({ id }: { id: string }) {
const { body } = await supertest
.post(`/api/content_management/rpc/delete`)
.set('kbn-xsrf', 'foo')
.set('x-elastic-internal-origin', 'foo')
.send({
contentTypeId: 'index-pattern',
id,
options: { force: true },
version: 1,
});
return body;
},
};
}

View file

@ -0,0 +1,27 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { format as formatUrl } from 'url';
import supertest from 'supertest';
import { FtrProviderContext } from '../ftr_provider_context';
/**
* Supertest provider that doesn't include user credentials into base URL that is passed
* to the supertest.
*/
export function EsSupertestWithoutAuthProvider({ getService }: FtrProviderContext) {
const config = getService('config');
const elasticsearchServerConfig = config.get('servers.elasticsearch');
return supertest(
formatUrl({
...elasticsearchServerConfig,
auth: false,
})
);
}

View file

@ -0,0 +1,39 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { ELASTIC_HTTP_VERSION_HEADER } from '@kbn/core-http-common';
import { FtrProviderContext } from '../ftr_provider_context';
export async function FleetAndAgents({ getService }: FtrProviderContext) {
const es = getService('es');
const supertestWithoutAuth = getService('supertestWithoutAuth');
return {
async setup() {
// Use elastic/fleet-server service account to execute setup to verify privilege configuration
const { token } = await es.security.createServiceToken({
namespace: 'elastic',
service: 'fleet-server',
});
await supertestWithoutAuth
.post(`/api/fleet/setup`)
.set(ELASTIC_HTTP_VERSION_HEADER, '2023-10-31')
.set('kbn-xsrf', 'xxx')
.set('Authorization', `Bearer ${token.value}`)
.send()
.expect(200);
await supertestWithoutAuth
.post(`/api/fleet/agents/setup`)
.set(ELASTIC_HTTP_VERSION_HEADER, '2023-10-31')
.set('kbn-xsrf', 'xxx')
.set('Authorization', `Bearer ${token.value}`)
.send({ forceRecreate: true })
.expect(200);
},
};
}

View file

@ -0,0 +1,23 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { services as kibanaApiIntegrationServices } from '@kbn/test-suites-src/api_integration/services';
import { EsSupertestWithoutAuthProvider } from './es_supertest_without_auth';
import { UsageAPIProvider } from './usage_api';
import { IngestPipelinesProvider } from './ingest_pipelines';
import { DataViewApiProvider } from './data_view_api';
import { FleetAndAgents } from './fleet_and_agents';
export const services = {
...kibanaApiIntegrationServices,
dataViewApi: DataViewApiProvider,
esSupertestWithoutAuth: EsSupertestWithoutAuthProvider,
usageAPI: UsageAPIProvider,
ingestPipelines: IngestPipelinesProvider,
fleetAndAgents: FleetAndAgents,
};

View file

@ -0,0 +1,6 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

View file

@ -0,0 +1,19 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { FtrProviderContext } from '../../ftr_provider_context';
import { IngestPipelinesAPIProvider, IngestPipelinesFixturesProvider } from './lib';
export function IngestPipelinesProvider(context: FtrProviderContext) {
const api = IngestPipelinesAPIProvider(context);
const fixtures = IngestPipelinesFixturesProvider();
return {
api,
fixtures,
};
}

View file

@ -0,0 +1,89 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { IngestPutPipelineRequest } from '@elastic/elasticsearch/lib/api/types';
import expect from '@kbn/expect';
import { FtrProviderContext } from '../../../ftr_provider_context';
export function IngestPipelinesAPIProvider({ getService }: FtrProviderContext) {
const es = getService('es');
const retry = getService('retry');
const log = getService('log');
return {
async createPipeline(pipeline: IngestPutPipelineRequest) {
log.debug(`Creating pipeline: '${pipeline.id}'`);
const createResponse = await es.ingest.putPipeline(pipeline);
expect(createResponse)
.to.have.property('acknowledged')
.eql(true, 'Response for create pipelines should be acknowledged.');
await this.waitForPipelinesToExist(pipeline.id, `expected ${pipeline.id} to be created`);
},
async waitForPipelinesToExist(pipelineId: string, errorMsg?: string) {
await retry.tryForTime(30 * 1000, async () => {
const pipeline = await es.ingest.getPipeline({ id: pipelineId });
const pipelineNames = Object.keys(pipeline);
if (pipelineNames.length === 1 && pipelineNames[0] === pipelineId) {
return true;
} else {
throw new Error(errorMsg || `pipeline '${pipelineId}' should exist`);
}
});
},
async deletePipelines() {
const pipelines = await es.ingest.getPipeline();
// Assumes all test pipelines will be prefixed with `test-pipeline*`
const pipelineIds = Object.keys(pipelines).filter((pipeline) =>
pipeline.includes('test-pipeline')
);
const deletePipeline = (pipelineId: string) => es.ingest.deletePipeline({ id: pipelineId });
return Promise.all(pipelineIds.map(deletePipeline)).catch((err) => {
log.debug(`[Cleanup error] Error deleting ES resources: ${err.message}`);
});
},
async createIndex(index: { index: string; id: string; body: object }) {
const indexExists = await es.indices.exists({ index: index.index });
// Index should not exist, but in the case that it already does, we bypass the create request
if (indexExists) {
return;
}
log.debug(`Creating index: '${index.index}'`);
return await es.index(index);
},
async deleteIndex(indexName: string) {
log.debug(`Deleting index: '${indexName}'`);
return await es.indices.delete({ index: indexName });
},
async deleteGeoipDatabases() {
const { databases } = await es.ingest.getGeoipDatabase();
// Remove all geoip databases
const databaseIds = databases.map((database: { id: string }) => database.id);
const deleteDatabase = (id: string) =>
es.ingest.deleteGeoipDatabase({
id,
});
return Promise.all(databaseIds.map(deleteDatabase)).catch((err) => {
log.debug(`[Cleanup error] Error deleting ES resources: ${err.message}`);
});
},
};
}

View file

@ -0,0 +1,109 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import {
IngestProcessorContainer,
VersionNumber,
Metadata,
IngestPutPipelineRequest,
} from '@elastic/elasticsearch/lib/api/types';
export interface Pipeline {
name: string;
description?: string;
onFailureProcessors?: IngestProcessorContainer[];
processors: IngestProcessorContainer[];
version?: VersionNumber;
metadata?: Metadata;
}
export interface IngestPutPipelineInternalRequest extends Omit<IngestPutPipelineRequest, 'id'> {
name: string;
}
export function IngestPipelinesFixturesProvider() {
const defaultProcessors: IngestProcessorContainer[] = [
{
script: {
source: 'ctx._type = null',
},
},
];
const defaultOnFailureProcessors: IngestProcessorContainer[] = [
{
set: {
field: 'error.message',
value: '{{ failure_message }}',
},
},
];
const defaultMetadata: Metadata = {
field_1: 'test',
field_2: 10,
};
const apiBasePath = '/api/ingest_pipelines';
const createPipelineBodyWithRequiredFields = (): IngestPutPipelineInternalRequest => {
return {
name: `test-pipeline-required-fields-${Math.random()}`,
processors: defaultProcessors,
};
};
const createPipelineBody = (pipeline?: Pipeline): IngestPutPipelineInternalRequest => {
if (pipeline) {
const { name, description, processors, onFailureProcessors, version, metadata } = pipeline;
return {
name,
description,
processors,
on_failure: onFailureProcessors,
version,
_meta: metadata,
};
}
// Use default payload if none is provided
return {
name: `test-pipeline-${Math.random()}`,
description: 'test pipeline description',
processors: defaultProcessors,
on_failure: defaultOnFailureProcessors,
version: 1,
_meta: defaultMetadata,
};
};
const createDocuments = () => {
return [
{
_index: 'index',
_id: 'id1',
_source: {
foo: 'bar',
},
},
{
_index: 'index',
_id: 'id2',
_source: {
foo: 'rab',
},
},
];
};
return {
createPipelineBodyWithRequiredFields,
createPipelineBody,
createDocuments,
apiBasePath,
};
}

View file

@ -0,0 +1,9 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
export { IngestPipelinesAPIProvider } from './api';
export { IngestPipelinesFixturesProvider } from './fixtures';

View file

@ -0,0 +1,74 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import type { UsageStatsPayload } from '@kbn/telemetry-collection-manager-plugin/server';
import {
ELASTIC_HTTP_VERSION_HEADER,
X_ELASTIC_INTERNAL_ORIGIN_REQUEST,
} from '@kbn/core-http-common';
import type { FtrProviderContext } from '../ftr_provider_context';
export interface UsageStatsPayloadTestFriendly extends UsageStatsPayload {
// Overwriting the `object` type to a more test-friendly type
stack_stats: Record<string, any>;
}
export interface GetTelemetryStatsOpts {
authHeader: Record<string, string>;
}
export function UsageAPIProvider({ getService }: FtrProviderContext) {
const supertest = getService('supertest');
const supertestWithoutAuth = getService('supertestWithoutAuth');
async function getTelemetryStats(
payload: {
unencrypted: true;
refreshCache?: boolean;
},
opts?: GetTelemetryStatsOpts
): Promise<Array<{ clusterUuid: string; stats: UsageStatsPayloadTestFriendly }>>;
async function getTelemetryStats(
payload: {
unencrypted: false;
refreshCache?: boolean;
},
opts?: GetTelemetryStatsOpts
): Promise<Array<{ clusterUuid: string; stats: string }>>;
async function getTelemetryStats(
payload: {
unencrypted?: boolean;
refreshCache?: boolean;
},
opts?: GetTelemetryStatsOpts
): Promise<Array<{ clusterUuid: string; stats: UsageStatsPayloadTestFriendly | string }>> {
const client = opts?.authHeader ? supertestWithoutAuth : supertest;
const request = client
.post('/internal/telemetry/clusters/_stats')
.set('kbn-xsrf', 'xxx')
.set(ELASTIC_HTTP_VERSION_HEADER, '2')
.set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana');
if (opts?.authHeader) {
void request.set(opts.authHeader);
}
const { body } = await request.send({ refreshCache: true, ...payload }).expect(200);
return body;
}
return {
/**
* Retrieve the stats via the private telemetry API:
* It returns the usage in as a string encrypted blob or the plain payload if `unencrypted: false`
*
* @param payload Request parameters to retrieve the telemetry stats
*/
getTelemetryStats,
};
}

View file

@ -0,0 +1,8 @@
{
"type": "test-helper",
"id": "@kbn/test-suites-xpack-platform",
"owner": [],
"group": "platform",
"visibility": "shared",
"devOnly": true
}

View file

@ -0,0 +1,29 @@
{
"extends": "../../../tsconfig.base.json",
"compilerOptions": {
"outDir": "target/types",
"types": [
"node",
"cheerio",
"@emotion/react/types/css-prop",
"@kbn/ambient-ui-types",
"@kbn/ambient-ftr-types"
]
},
"include": [
"**/*",
"../../../typings/**/*",
"../../../src/platform/packages/shared/kbn-test/types/ftr_globals/**/*",
],
"exclude": ["target/**/*", "*/plugins/**/*", "plugins/**/*"],
"kbn_references": [
"@kbn/test-suites-src",
"@kbn/telemetry-collection-manager-plugin",
"@kbn/features-plugin",
"@kbn/test",
"@kbn/expect",
"@kbn/core-http-common",
"@kbn/scout-info",
"@kbn/data-plugin",
]
}

View file

@ -7630,6 +7630,10 @@
version "0.0.0"
uid ""
"@kbn/test-suites-xpack-platform@link:x-pack/platform/test":
version "0.0.0"
uid ""
"@kbn/test-suites-xpack@link:x-pack/test":
version "0.0.0"
uid ""