From 7f2a324e0f3ca65cdbeaef021a948e828dbe60ec Mon Sep 17 00:00:00 2001 From: Miriam <31922082+MiriamAparicio@users.noreply.github.com> Date: Tue, 12 Nov 2024 16:55:15 +0000 Subject: [PATCH] [ObsUX][APM] Migrate APM infra tests to agnostic deployment tests (#199775) ### Summary Closes https://github.com/elastic/kibana/issues/198976 Part of https://github.com/elastic/kibana/issues/193245 This PR contains the changes to migrate infrastructure test folder to Deployment-agnostic testing strategy. #### How to test Serverless ``` node scripts/functional_tests_server --config x-pack/test/api_integration/deployment_agnostic/configs/serverless/oblt.serverless.config.ts node scripts/functional_test_runner --config x-pack/test/api_integration/deployment_agnostic/configs/serverless/oblt.serverless.config.ts --grep="APM" ``` It's recommended to be run against [MKI](https://github.com/crespocarlos/kibana/blob/main/x-pack/test_serverless/README.md#run-tests-on-mki) Stateful ``` node scripts/functional_tests_server --config x-pack/test/api_integration/deployment_agnostic/configs/stateful/oblt.stateful.config.ts node scripts/functional_test_runner --config x-pack/test/api_integration/deployment_agnostic/configs/stateful/oblt.stateful.config.ts --grep="APM" ``` Checks - [ ] (OPTIONAL, only if a test has been unskipped) Run flaky test suite - [x] local run for serverless - [x] local run for stateful - [x] MKI run for serverless --- .../apis/observability/apm/index.ts | 1 + .../apm}/infrastructure/generate_data.ts | 0 .../observability/apm/infrastructure/index.ts | 14 ++++++++++ .../infrastructure_attributes.spec.ts | 28 +++++++++---------- 4 files changed, 28 insertions(+), 15 deletions(-) rename x-pack/test/{apm_api_integration/tests => api_integration/deployment_agnostic/apis/observability/apm}/infrastructure/generate_data.ts (100%) create mode 100644 x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/infrastructure/index.ts rename x-pack/test/{apm_api_integration/tests => api_integration/deployment_agnostic/apis/observability/apm}/infrastructure/infrastructure_attributes.spec.ts (76%) diff --git a/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/index.ts b/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/index.ts index 6c1bd3633c4cc..8cde7cb77bca8 100644 --- a/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/index.ts +++ b/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/index.ts @@ -22,5 +22,6 @@ export default function apmApiIntegrationTests({ loadTestFile(require.resolve('./correlations')); loadTestFile(require.resolve('./entities')); loadTestFile(require.resolve('./cold_start')); + loadTestFile(require.resolve('./infrastructure')); }); } diff --git a/x-pack/test/apm_api_integration/tests/infrastructure/generate_data.ts b/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/infrastructure/generate_data.ts similarity index 100% rename from x-pack/test/apm_api_integration/tests/infrastructure/generate_data.ts rename to x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/infrastructure/generate_data.ts diff --git a/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/infrastructure/index.ts b/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/infrastructure/index.ts new file mode 100644 index 0000000000000..1351a44d41c8e --- /dev/null +++ b/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/infrastructure/index.ts @@ -0,0 +1,14 @@ +/* + * 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 { DeploymentAgnosticFtrProviderContext } from '../../../../ftr_provider_context'; + +export default function ({ loadTestFile }: DeploymentAgnosticFtrProviderContext) { + describe('infrastructure', () => { + loadTestFile(require.resolve('./infrastructure_attributes.spec.ts')); + }); +} diff --git a/x-pack/test/apm_api_integration/tests/infrastructure/infrastructure_attributes.spec.ts b/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/infrastructure/infrastructure_attributes.spec.ts similarity index 76% rename from x-pack/test/apm_api_integration/tests/infrastructure/infrastructure_attributes.spec.ts rename to x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/infrastructure/infrastructure_attributes.spec.ts index 7a79e2f8be4b1..ca70d8d1fa002 100644 --- a/x-pack/test/apm_api_integration/tests/infrastructure/infrastructure_attributes.spec.ts +++ b/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/infrastructure/infrastructure_attributes.spec.ts @@ -5,13 +5,13 @@ * 2.0. */ import expect from '@kbn/expect'; -import { FtrProviderContext } from '../../common/ftr_provider_context'; +import type { ApmSynthtraceEsClient } from '@kbn/apm-synthtrace'; import { generateData } from './generate_data'; +import { DeploymentAgnosticFtrProviderContext } from '../../../../ftr_provider_context'; -export default function ApiTest({ getService }: FtrProviderContext) { - const registry = getService('registry'); - const apmApiClient = getService('apmApiClient'); - const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); +export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderContext) { + const apmApiClient = getService('apmApi'); + const synthtrace = getService('synthtrace'); const start = new Date('2021-01-01T00:00:00.000Z').getTime(); const end = new Date('2021-01-01T00:15:00.000Z').getTime() - 1; @@ -34,10 +34,8 @@ export default function ApiTest({ getService }: FtrProviderContext) { return response; } - registry.when( - 'Infrastructure attributes when data is not loaded', - { config: 'basic', archives: [] }, - () => { + describe('Infrastructure attributes', () => { + describe('Infrastructure attributes when data is not loaded', () => { it('handles the empty state', async () => { const response = await callApi('synth-go'); expect(response.status).to.be(200); @@ -45,17 +43,17 @@ export default function ApiTest({ getService }: FtrProviderContext) { expect(response.body.hostNames.length).to.be(0); expect(response.body.podNames.length).to.be(0); }); - } - ); + }); - // FLAKY: https://github.com/elastic/kibana/issues/177386 - registry.when('Infrastructure attributes', { config: 'basic', archives: [] }, () => { describe('when data is loaded', () => { - beforeEach(async () => { + let apmSynthtraceEsClient: ApmSynthtraceEsClient; + + before(async () => { + apmSynthtraceEsClient = await synthtrace.createApmSynthtraceEsClient(); await generateData({ start, end, apmSynthtraceEsClient }); }); - afterEach(() => apmSynthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); describe('when service runs in container', () => { it('returns arrays of container ids and pod names', async () => {