diff --git a/x-pack/platform/test/fleet_api_integration/apis/epm/get.ts b/x-pack/platform/test/fleet_api_integration/apis/epm/get.ts index 431417962de0f..5876b74634061 100644 --- a/x-pack/platform/test/fleet_api_integration/apis/epm/get.ts +++ b/x-pack/platform/test/fleet_api_integration/apis/epm/get.ts @@ -9,7 +9,6 @@ import expect from '@kbn/expect'; import type { PackageInfo } from '@kbn/fleet-plugin/common/types/models/epm'; import fs from 'fs'; import path from 'path'; -import pRetry from 'p-retry'; import type { FtrProviderContext } from '../../../api_integration/ftr_provider_context'; import { skipIfNoDockerRegistry } from '../../helpers'; import { testUsers } from '../test_users'; @@ -37,75 +36,6 @@ export default function (providerContext: FtrProviderContext) { .send({ force: true }); }; - // Helper function to clean up knowledge base content - const cleanupKnowledgeBase = async (name: string) => { - await es.deleteByQuery({ - index: '.integration_knowledge', - query: { - term: { 'package_name.keyword': name }, - }, - refresh: true, - ignore_unavailable: true, - }); - }; - - // Helper function to wait for knowledge base content to be available - const waitForKnowledgeBaseContent = async (packageName: string) => { - await pRetry( - async () => { - const res = await supertest - .get(`/internal/fleet/epm/packages/${packageName}/knowledge_base`) - .set('kbn-xsrf', 'xxxx') - .set('elastic-api-version', '1'); - - if (res.status !== 200) { - throw new Error(`Knowledge base not ready yet, status: ${res.status}`); - } - - // Ensure we have the expected content structure - if (!res.body?.items || !Array.isArray(res.body.items) || res.body.items.length === 0) { - throw new Error('Knowledge base content not yet available'); - } - }, - { - retries: 12, // 12 retries * 5 seconds = 60 seconds max - minTimeout: 5000, // 5 seconds between retries - maxTimeout: 5000, - } - ); - }; - - // Helper function to wait for knowledge base items to appear in package info - const waitForKnowledgeBaseInPackageInfo = async (packageName: string, packageVersion: string) => { - await pRetry( - async () => { - const res = await supertest.get(`/api/fleet/epm/packages/${packageName}/${packageVersion}`); - - if (res.status !== 200) { - throw new Error(`Package info not ready yet, status: ${res.status}`); - } - - const packageInfo = res.body.item; - if (!packageInfo?.installationInfo?.installed_es) { - throw new Error('Package installation info not yet available'); - } - - const knowledgeBaseItems = packageInfo.installationInfo.installed_es.filter( - (item: any) => item.type === 'knowledge_base' - ); - - if (knowledgeBaseItems.length === 0) { - throw new Error('Knowledge base items not yet available in package info'); - } - }, - { - retries: 12, // 12 retries * 5 seconds = 60 seconds max - minTimeout: 5000, // 5 seconds between retries - maxTimeout: 5000, - } - ); - }; - const testPkgArchiveZip = path.join( path.dirname(__filename), '../fixtures/direct_upload_packages/apache_0.1.4.zip' @@ -373,154 +303,5 @@ export default function (providerContext: FtrProviderContext) { ); expect(dataStream?.elasticsearch?.source_mode).equal(undefined); }); - - // Re-enable when feature flag is on by default - // https://github.com/elastic/kibana/issues/239796 - describe.skip('Knowledge Base', () => { - const knowledgeBasePkgName = 'knowledge_base_test'; - const knowledgeBasePkgVersion = '1.0.0'; - - afterEach(async () => { - // Clean up knowledge base content after each test to avoid conflicts - await cleanupKnowledgeBase(knowledgeBasePkgName); - // Uninstall the knowledge base test package - try { - await uninstallPackage(knowledgeBasePkgName, knowledgeBasePkgVersion); - } catch (error) { - // Ignore errors if package is not installed - } - }); - - it('returns knowledge base content for an installed package', async function () { - await installPackage(knowledgeBasePkgName, knowledgeBasePkgVersion); - // Since KB indexing is async, wait for it to be ready before trying to fetch - // This is due to the ML model needing to get deployed first which can take a bit - await waitForKnowledgeBaseContent(knowledgeBasePkgName); - - const res = await supertest - .get(`/internal/fleet/epm/packages/${knowledgeBasePkgName}/knowledge_base`) - .set('kbn-xsrf', 'xxxx') - .set('elastic-api-version', '1') - .expect(200); - - expect(res.body).to.have.property('package'); - expect(res.body.package).to.have.property('name'); - expect(res.body).to.have.property('items'); - expect(res.body.package.name).to.equal(knowledgeBasePkgName); - expect(res.body.items).to.be.an('array'); - expect(res.body.items).to.have.length(3); // overview, troubleshooting, configuration - - // Verify the content structure - const overviewDoc = res.body.items.find((item: any) => item.fileName === 'overview.md'); - const troubleshootingDoc = res.body.items.find( - (item: any) => item.fileName === 'troubleshooting.md' - ); - const configurationDoc = res.body.items.find( - (item: any) => item.fileName === 'configuration.md' - ); - - expect(overviewDoc).to.not.be(undefined); - expect(troubleshootingDoc).to.not.be(undefined); - expect(configurationDoc).to.not.be(undefined); - expect(overviewDoc.content).to.contain('Knowledge Base Test Integration Overview'); - expect(troubleshootingDoc.content).to.contain('Troubleshooting Guide'); - expect(configurationDoc.content).to.contain('Configuration Guide'); - }); - - it('returns 404 for knowledge base of non-existent package', async function () { - await supertest - .get(`/internal/fleet/epm/packages/nonexistent/knowledge_base`) - .set('kbn-xsrf', 'xxxx') - .set('elastic-api-version', '1') - .expect(404); - }); - - it('validates knowledge base content structure', async function () { - await installPackage(knowledgeBasePkgName, knowledgeBasePkgVersion); - // Since KB indexing is async, wait for it to be ready before trying to fetch - // This is due to the ML model needing to get deployed first which can take a bit - await waitForKnowledgeBaseContent(knowledgeBasePkgName); - const res = await supertest - .get(`/internal/fleet/epm/packages/${knowledgeBasePkgName}/knowledge_base`) - .set('kbn-xsrf', 'xxxx') - .set('elastic-api-version', '1') - .expect(200); - - // Validate response structure matches schema - expect(res.body.package.name).to.be.a('string'); - expect(res.body.items).to.be.an('array'); - - // Validate knowledge base content items structure - res.body.items.forEach((item: any) => { - expect(item).to.have.property('fileName'); - expect(item).to.have.property('content'); - expect(item).to.have.property('path'); - expect(item).to.have.property('installed_at'); - expect(item).to.have.property('version'); - expect(item.fileName).to.be.a('string'); - expect(item.content).to.be.a('string'); - expect(item.path).to.be.a('string'); - expect(item.installed_at).to.be.a('string'); - expect(item.version).to.be.a('string'); - }); - }); - - it('includes knowledge base information in package info assets when fetching from the info endpoint', async function () { - await installPackage(knowledgeBasePkgName, knowledgeBasePkgVersion); - // Since KB indexing is async, wait for knowledge base items to be ready in package info - // This is due to the ML model needing to get deployed first which can take a bit - await waitForKnowledgeBaseInPackageInfo(knowledgeBasePkgName, knowledgeBasePkgVersion); - const res = await supertest - .get(`/api/fleet/epm/packages/${knowledgeBasePkgName}/${knowledgeBasePkgVersion}`) - .expect(200); - - const packageInfo = res.body.item; - - // Check that the installed_es field contains knowledge_base items - expect(packageInfo.installationInfo).to.have.property('installed_es'); - expect(packageInfo.installationInfo.installed_es).to.be.an('array'); - - const knowledgeBaseItems = packageInfo.installationInfo.installed_es.filter( - (item: any) => item.type === 'knowledge_base' - ); - - // Should have knowledge base items indexed - // Note: ALL .md files from docs/ folder are indexed (including CHANGELOG.md, INSTALL.md, etc.) - expect(knowledgeBaseItems.length).to.be.greaterThan(0); - // Expect: README, CHANGELOG, INSTALL, overview, troubleshooting, configuration - expect(knowledgeBaseItems.length).to.equal(6); - - // Verify knowledge base items have correct structure with packageName-fileName format - // IDs follow the format: packageName-fileName (e.g., "knowledge_base_test-overview.md") - - // Verify all items have the correct type and structure - knowledgeBaseItems.forEach((item: any) => { - expect(item).to.have.property('id'); - expect(item).to.have.property('type'); - expect(item.type).to.equal('knowledge_base'); - expect(item.id).to.be.a('string'); - expect(item.id).to.not.be.empty(); // ID should be a non-empty string - // Verify ID follows packageName-fileName format - expect(item.id).to.match(/^knowledge_base_test-.+\.md$/); - }); - - // Verify that expected core documentation files are present - const expectedCoreDocumentIds = [ - 'knowledge_base_test-README.md', - 'knowledge_base_test-CHANGELOG.md', - 'knowledge_base_test-INSTALL.md', - 'knowledge_base_test-overview.md', - 'knowledge_base_test-troubleshooting.md', - 'knowledge_base_test-configuration.md', - ]; - - const actualDocumentIds = knowledgeBaseItems.map((item: any) => item.id); - - // Check that all expected core docs are present - expectedCoreDocumentIds.forEach((expectedId: string) => { - expect(actualDocumentIds.includes(expectedId)).to.equal(true); - }); - }); - }); }); } diff --git a/x-pack/platform/test/fleet_api_integration/apis/epm/index.ts b/x-pack/platform/test/fleet_api_integration/apis/epm/index.ts index c09fd895d52fc..e1b7be6e13373 100644 --- a/x-pack/platform/test/fleet_api_integration/apis/epm/index.ts +++ b/x-pack/platform/test/fleet_api_integration/apis/epm/index.ts @@ -56,5 +56,6 @@ export default function ({ loadTestFile, getService }: FtrProviderContext) { loadTestFile(require.resolve('./data_views')); loadTestFile(require.resolve('./custom_integrations')); loadTestFile(require.resolve('./rollback')); + loadTestFile(require.resolve('./knowledge_base')); }); } diff --git a/x-pack/platform/test/fleet_api_integration/apis/epm/install_by_upload.ts b/x-pack/platform/test/fleet_api_integration/apis/epm/install_by_upload.ts index 945dd4bd915fa..0664f2b8437a0 100644 --- a/x-pack/platform/test/fleet_api_integration/apis/epm/install_by_upload.ts +++ b/x-pack/platform/test/fleet_api_integration/apis/epm/install_by_upload.ts @@ -111,7 +111,7 @@ export default function (providerContext: FtrProviderContext) { .type('application/zip') .send(buf) .expect(200); - expect(res.body.items.length).to.be(33); + expect(res.body.items.length).to.be.greaterThan(32); expect(res.body.items.some((item: any) => item.id.includes(testPkgNewVersion))); await deletePackage(testPkgName, testPkgNewVersion); diff --git a/x-pack/platform/test/fleet_api_integration/apis/epm/install_remove_assets.ts b/x-pack/platform/test/fleet_api_integration/apis/epm/install_remove_assets.ts index d1addefcd761a..1d981924794d3 100644 --- a/x-pack/platform/test/fleet_api_integration/apis/epm/install_remove_assets.ts +++ b/x-pack/platform/test/fleet_api_integration/apis/epm/install_remove_assets.ts @@ -29,7 +29,6 @@ export default function (providerContext: FtrProviderContext) { const supertest = getService('supertest'); const es: Client = getService('es'); const fleetAndAgents = getService('fleetAndAgents'); - const retry = getService('retry'); const pkgName = 'all_assets'; const pkgVersion = '0.1.0'; const logsTemplateName = `logs-${pkgName}.test_logs`; @@ -48,8 +47,7 @@ export default function (providerContext: FtrProviderContext) { describe('installs and uninstalls all assets', () => { skipIfNoDockerRegistry(providerContext); - // FLAKY: https://github.com/elastic/kibana/issues/246272 - describe.skip('installs all assets when installing a package for the first time', () => { + describe('installs all assets when installing a package for the first time', () => { before(async () => { await fleetAndAgents.setup(); if (!isDockerRegistryEnabledOrSkipped(providerContext)) return; @@ -66,7 +64,6 @@ export default function (providerContext: FtrProviderContext) { pkgName, es, kibanaServer, - retry, }); }); @@ -381,7 +378,6 @@ export default function (providerContext: FtrProviderContext) { pkgName, es, kibanaServer, - retry, }); }); }); @@ -394,7 +390,6 @@ const expectAssetsInstalled = ({ pkgName, es, kibanaServer, - retry, }: { logsTemplateName: string; metricsTemplateName: string; @@ -402,7 +397,6 @@ const expectAssetsInstalled = ({ pkgName: string; es: Client; kibanaServer: any; - retry: any; }) => { it('should have installed the ILM policy', async function () { const resPolicy = await es.transport.request( @@ -746,10 +740,6 @@ const expectAssetsInstalled = ({ id: 'metrics-all_assets.test_metrics-0.1.0', type: 'ingest_pipeline', }, - { - id: 'all_assets-README.md', - type: 'knowledge_base', - }, { id: 'default', type: 'ml_model', @@ -929,12 +919,17 @@ const expectAssetsInstalled = ({ verification_key_id: null, }; - expect(sortedRes).eql(expectedSavedObject); + expectedSavedObject.installed_es.forEach((item) => { + expect( + sortedRes.installed_es.find( + (asset: any) => asset.type === item.type && asset.id === item.id + ) + ).to.not.be(undefined); + }); + expect({ ...sortedRes, installed_es: [] }).eql({ ...expectedSavedObject, installed_es: [] }); } - await retry.tryForTime(10000, async () => { - await verifySO(); - }); + await verifySO(); }); // TODO enable when feature flag is turned on https://github.com/elastic/kibana/issues/244655 diff --git a/x-pack/platform/test/fleet_api_integration/apis/epm/knowledge_base.ts b/x-pack/platform/test/fleet_api_integration/apis/epm/knowledge_base.ts new file mode 100644 index 0000000000000..4d73d61afa157 --- /dev/null +++ b/x-pack/platform/test/fleet_api_integration/apis/epm/knowledge_base.ts @@ -0,0 +1,235 @@ +/* + * 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 expect from '@kbn/expect'; +import type { FtrProviderContext } from '../../../api_integration/ftr_provider_context'; +import { skipIfNoDockerRegistry } from '../../helpers'; + +export default function (providerContext: FtrProviderContext) { + const { getService } = providerContext; + + const supertest = getService('supertest'); + const es = getService('es'); + const fleetAndAgents = getService('fleetAndAgents'); + const retry = getService('retry'); + + const uninstallPackage = async (name: string, version: string) => { + await supertest.delete(`/api/fleet/epm/packages/${name}/${version}`).set('kbn-xsrf', 'xxxx'); + }; + const installPackage = async (name: string, version: string) => { + await supertest + .post(`/api/fleet/epm/packages/${name}/${version}`) + .set('kbn-xsrf', 'xxxx') + .send({ force: true }); + }; + + // Helper function to clean up knowledge base content + const cleanupKnowledgeBase = async (name: string) => { + await es.deleteByQuery({ + index: '.integration_knowledge', + query: { + term: { 'package_name.keyword': name }, + }, + refresh: true, + ignore_unavailable: true, + }); + }; + + // Helper function to wait for knowledge base content to be available + const waitForKnowledgeBaseContent = async (packageName: string) => { + await retry.tryForTime(60000, async () => { + const res = await supertest + .get(`/internal/fleet/epm/packages/${packageName}/knowledge_base`) + .set('kbn-xsrf', 'xxxx') + .set('elastic-api-version', '1'); + + if (res.status !== 200) { + throw new Error(`Knowledge base not ready yet, status: ${res.status}`); + } + + // Ensure we have the expected content structure + if (!res.body?.items || !Array.isArray(res.body.items) || res.body.items.length === 0) { + throw new Error('Knowledge base content not yet available'); + } + }); + }; + + // Helper function to wait for knowledge base items to appear in package info + const waitForKnowledgeBaseInPackageInfo = async (packageName: string, packageVersion: string) => { + await retry.tryForTime(60000, async () => { + const res = await supertest.get(`/api/fleet/epm/packages/${packageName}/${packageVersion}`); + + if (res.status !== 200) { + throw new Error(`Package info not ready yet, status: ${res.status}`); + } + + const packageInfo = res.body.item; + if (!packageInfo?.installationInfo?.installed_es) { + throw new Error('Package installation info not yet available'); + } + + const knowledgeBaseItems = packageInfo.installationInfo.installed_es.filter( + (item: any) => item.type === 'knowledge_base' + ); + + if (knowledgeBaseItems.length === 0) { + throw new Error('Knowledge base items not yet available in package info'); + } + }); + }; + + describe('Knowledge Base', () => { + skipIfNoDockerRegistry(providerContext); + + const knowledgeBasePkgName = 'knowledge_base_test'; + const knowledgeBasePkgVersion = '1.0.0'; + + after(async () => { + // Clean up knowledge base content after each test to avoid conflicts + await cleanupKnowledgeBase(knowledgeBasePkgName); + // Uninstall the knowledge base test package + try { + await uninstallPackage(knowledgeBasePkgName, knowledgeBasePkgVersion); + } catch (error) { + // Ignore errors if package is not installed + } + }); + + before(async () => { + await fleetAndAgents.setup(); + await installPackage(knowledgeBasePkgName, knowledgeBasePkgVersion); + }); + + it('returns knowledge base content for an installed package', async function () { + // Since KB indexing is async, wait for it to be ready before trying to fetch + // This is due to the ML model needing to get deployed first which can take a bit + await waitForKnowledgeBaseContent(knowledgeBasePkgName); + + const res = await supertest + .get(`/internal/fleet/epm/packages/${knowledgeBasePkgName}/knowledge_base`) + .set('kbn-xsrf', 'xxxx') + .set('elastic-api-version', '1') + .expect(200); + + expect(res.body).to.have.property('package'); + expect(res.body.package).to.have.property('name'); + expect(res.body).to.have.property('items'); + expect(res.body.package.name).to.equal(knowledgeBasePkgName); + expect(res.body.items).to.be.an('array'); + expect(res.body.items.length).to.be.greaterThan(3); // overview, troubleshooting, configuration, readme + + // Verify the content structure + const overviewDoc = res.body.items.find((item: any) => item.fileName === 'overview.md'); + const troubleshootingDoc = res.body.items.find( + (item: any) => item.fileName === 'troubleshooting.md' + ); + const configurationDoc = res.body.items.find( + (item: any) => item.fileName === 'configuration.md' + ); + + expect(overviewDoc).to.not.be(undefined); + expect(troubleshootingDoc).to.not.be(undefined); + expect(configurationDoc).to.not.be(undefined); + expect(overviewDoc.content).to.contain('Knowledge Base Test Integration Overview'); + expect(troubleshootingDoc.content).to.contain('Troubleshooting Guide'); + expect(configurationDoc.content).to.contain('Configuration Guide'); + }); + + it('returns 404 for knowledge base of non-existent package', async function () { + await supertest + .get(`/internal/fleet/epm/packages/nonexistent/knowledge_base`) + .set('kbn-xsrf', 'xxxx') + .set('elastic-api-version', '1') + .expect(404); + }); + + it('validates knowledge base content structure', async function () { + // Since KB indexing is async, wait for it to be ready before trying to fetch + // This is due to the ML model needing to get deployed first which can take a bit + await waitForKnowledgeBaseContent(knowledgeBasePkgName); + const res = await supertest + .get(`/internal/fleet/epm/packages/${knowledgeBasePkgName}/knowledge_base`) + .set('kbn-xsrf', 'xxxx') + .set('elastic-api-version', '1') + .expect(200); + + // Validate response structure matches schema + expect(res.body.package.name).to.be.a('string'); + expect(res.body.items).to.be.an('array'); + + // Validate knowledge base content items structure + res.body.items.forEach((item: any) => { + expect(item).to.have.property('fileName'); + expect(item).to.have.property('content'); + expect(item).to.have.property('path'); + expect(item).to.have.property('installed_at'); + expect(item).to.have.property('version'); + expect(item.fileName).to.be.a('string'); + expect(item.content).to.be.a('string'); + expect(item.path).to.be.a('string'); + expect(item.installed_at).to.be.a('string'); + expect(item.version).to.be.a('string'); + }); + }); + + it('includes knowledge base information in package info assets when fetching from the info endpoint', async function () { + // Since KB indexing is async, wait for knowledge base items to be ready in package info + // This is due to the ML model needing to get deployed first which can take a bit + await waitForKnowledgeBaseInPackageInfo(knowledgeBasePkgName, knowledgeBasePkgVersion); + const res = await supertest + .get(`/api/fleet/epm/packages/${knowledgeBasePkgName}/${knowledgeBasePkgVersion}`) + .expect(200); + + const packageInfo = res.body.item; + + // Check that the installed_es field contains knowledge_base items + expect(packageInfo.installationInfo).to.have.property('installed_es'); + expect(packageInfo.installationInfo.installed_es).to.be.an('array'); + + const knowledgeBaseItems = packageInfo.installationInfo.installed_es.filter( + (item: any) => item.type === 'knowledge_base' + ); + + // Should have knowledge base items indexed + // Note: ALL .md files from docs/ folder are indexed (including CHANGELOG.md, INSTALL.md, etc.) + expect(knowledgeBaseItems.length).to.be.greaterThan(0); + // Expect: README, CHANGELOG, INSTALL, overview, troubleshooting, configuration + expect(knowledgeBaseItems.length).to.equal(6); + + // Verify knowledge base items have correct structure with packageName-fileName format + // IDs follow the format: packageName-fileName (e.g., "knowledge_base_test-overview.md") + + // Verify all items have the correct type and structure + knowledgeBaseItems.forEach((item: any) => { + expect(item).to.have.property('id'); + expect(item).to.have.property('type'); + expect(item.type).to.equal('knowledge_base'); + expect(item.id).to.be.a('string'); + expect(item.id).to.not.be.empty(); // ID should be a non-empty string + // Verify ID follows packageName-fileName format + expect(item.id).to.match(/^knowledge_base_test-.+\.md$/); + }); + + // Verify that expected core documentation files are present + const expectedCoreDocumentIds = [ + 'knowledge_base_test-README.md', + 'knowledge_base_test-CHANGELOG.md', + 'knowledge_base_test-INSTALL.md', + 'knowledge_base_test-overview.md', + 'knowledge_base_test-troubleshooting.md', + 'knowledge_base_test-configuration.md', + ]; + + const actualDocumentIds = knowledgeBaseItems.map((item: any) => item.id); + + // Check that all expected core docs are present + expectedCoreDocumentIds.forEach((expectedId: string) => { + expect(actualDocumentIds.includes(expectedId)).to.equal(true); + }); + }); + }); +} diff --git a/x-pack/platform/test/fleet_api_integration/apis/epm/update_assets.ts b/x-pack/platform/test/fleet_api_integration/apis/epm/update_assets.ts index b62f5eed29d2b..aa594c22d16e0 100644 --- a/x-pack/platform/test/fleet_api_integration/apis/epm/update_assets.ts +++ b/x-pack/platform/test/fleet_api_integration/apis/epm/update_assets.ts @@ -24,6 +24,7 @@ export default function (providerContext: FtrProviderContext) { const logsTemplateName = `logs-${pkgName}.test_logs`; const logsTemplateName2 = `logs-${pkgName}.test_logs2`; const metricsTemplateName = `metrics-${pkgName}.test_metrics`; + const retry = getService('retry'); const uninstallPackage = async (pkg: string, version: string) => { await supertest.delete(`/api/fleet/epm/packages/${pkg}/${version}`).set('kbn-xsrf', 'xxxx'); @@ -35,8 +36,7 @@ export default function (providerContext: FtrProviderContext) { .send({ force: true }); }; - // Failing: See https://github.com/elastic/kibana/issues/246213 - describe.skip('updates all assets when updating a package to a different version', () => { + describe('updates all assets when updating a package to a different version', () => { skipIfNoDockerRegistry(providerContext); before(async () => { @@ -333,319 +333,329 @@ export default function (providerContext: FtrProviderContext) { expect(resSearch2.id).equal('sample_search2'); }); it('should have updated the saved object', async function () { - const res = await kibanaServer.savedObjects.get({ - type: 'epm-packages', - id: 'all_assets', - }); + await retry.tryForTime(10000, async () => { + await installPackage(pkgName, pkgUpdateVersion); - expect({ - ...res.attributes, - installed_kibana: sortBy(res.attributes.installed_kibana, ['id']), - package_assets: sortBy(res.attributes.package_assets, ['id']), - installed_es: sortBy(res.attributes.installed_es, ['id']), - }).eql({ - installed_kibana_space_id: 'default', - installed_kibana: sortBy( - [ - { - id: 'sample_alerting_rule_template', - type: 'alerting_rule_template', - }, - { - id: 'sample_dashboard', - type: 'dashboard', - }, - { - id: 'sample_lens', - type: 'lens', - }, + const res = await kibanaServer.savedObjects.get({ + type: 'epm-packages', + id: 'all_assets', + }); + + const expectedSO = { + installed_kibana_space_id: 'default', + installed_kibana: sortBy( + [ + { + id: 'sample_alerting_rule_template', + type: 'alerting_rule_template', + }, + { + id: 'sample_dashboard', + type: 'dashboard', + }, + { + id: 'sample_lens', + type: 'lens', + }, + { + id: 'sample_visualization', + type: 'visualization', + }, + { + id: 'sample_search2', + type: 'search', + }, + { + id: 'sample_ml_module', + type: 'ml-module', + }, + { + id: 'sample_security_rule', + type: 'security-rule', + }, + { + id: 'sample_csp_rule_template2', + type: 'csp-rule-template', + }, + { + id: 'sample_osquery_pack_asset', + type: 'osquery-pack-asset', + }, + { + id: 'sample_osquery_saved_query', + type: 'osquery-saved-query', + }, + { + id: 'sample_security_ai_prompt', + type: 'security-ai-prompt', + }, + { + id: 'sample_tag', + type: 'tag', + }, + ], + 'id' + ), + installed_es: sortBy( + [ + { + id: 'all_assets', + type: 'ilm_policy', + }, + { + id: 'default', + type: 'ml_model', + }, + { + id: 'logs-all_assets.test_logs-all_assets', + type: 'data_stream_ilm_policy', + }, + { + id: 'logs-all_assets.test_logs-0.2.0', + type: 'ingest_pipeline', + }, + { + id: 'logs-all_assets.test_logs-0.2.0-pipeline1', + type: 'ingest_pipeline', + }, + { + id: 'logs-all_assets.test_logs2-0.2.0', + type: 'ingest_pipeline', + }, + { + id: 'metrics-all_assets.test_metrics-0.2.0', + type: 'ingest_pipeline', + }, + { + id: 'logs-all_assets.test_logs', + type: 'index_template', + }, + { + id: 'logs-all_assets.test_logs@package', + type: 'component_template', + }, + { + id: 'logs@custom', + type: 'component_template', + }, + { + id: 'all_assets@custom', + type: 'component_template', + }, + { + id: 'logs-all_assets.test_logs@custom', + type: 'component_template', + }, + { + id: 'logs-all_assets.test_logs2', + type: 'index_template', + }, + { + id: 'logs-all_assets.test_logs2@package', + type: 'component_template', + }, + { + id: 'logs-all_assets.test_logs2@custom', + type: 'component_template', + }, + { + id: 'metrics-all_assets.test_metrics', + type: 'index_template', + }, + { + id: 'metrics-all_assets.test_metrics@package', + type: 'component_template', + }, + { + id: 'metrics@custom', + type: 'component_template', + }, + { + id: 'metrics-all_assets.test_metrics@custom', + type: 'component_template', + }, + ], + 'id' + ), + es_index_patterns: { + test_logs: 'logs-all_assets.test_logs-*', + test_metrics: 'metrics-all_assets.test_metrics-*', + }, + package_assets: [ { - id: 'sample_visualization', - type: 'visualization', + id: '071b5113-4c9f-5ee9-aafe-d098a4c066f6', + path: 'all_assets-0.2.0/data_stream/test_logs2/fields/ecs.yml', + type: 'epm-packages-assets', }, { - id: 'sample_search2', - type: 'search', + id: '0c8c3c6a-90cb-5f0e-8359-d807785b046c', + path: 'all_assets-0.2.0/elasticsearch/ml_model/test/default.json', + type: 'epm-packages-assets', }, { - id: 'sample_ml_module', - type: 'ml-module', + id: '28523a82-1328-578d-84cb-800970560200', + path: 'all_assets-0.2.0/data_stream/test_metrics/fields/fields.yml', + type: 'epm-packages-assets', }, { - id: 'sample_security_rule', - type: 'security-rule', + id: '2e56f08b-1d06-55ed-abee-4708e1ccf0aa', + path: 'all_assets-0.2.0/kibana/search/sample_search2.json', + type: 'epm-packages-assets', }, { - id: 'sample_csp_rule_template2', - type: 'csp-rule-template', + id: '3eb4c54a-638f-51b6-84e2-d53f5a666e37', + path: 'all_assets-0.2.0/data_stream/test_logs/elasticsearch/ilm_policy/all_assets.json', + type: 'epm-packages-assets', }, { - id: 'sample_osquery_pack_asset', - type: 'osquery-pack-asset', + id: '4035007b-9c33-5227-9803-2de8a17523b5', + path: 'all_assets-0.2.0/kibana/security_rule/sample_security_rule.json', + type: 'epm-packages-assets', }, { - id: 'sample_osquery_saved_query', - type: 'osquery-saved-query', + id: '4281a436-45a8-54ab-9724-fda6849f789d', + path: 'all_assets-0.2.0/kibana/ml_module/sample_ml_module.json', + type: 'epm-packages-assets', }, { - id: 'sample_security_ai_prompt', - type: 'security-ai-prompt', + id: '48e582df-b1d2-5f88-b6ea-ba1fafd3a569', + path: 'all_assets-0.2.0/img/logo_overrides_64_color.svg', + type: 'epm-packages-assets', }, { - id: 'sample_tag', - type: 'tag', + id: '498d8215-2613-5399-9a13-fa4f0bf513e2', + path: 'all_assets-0.2.0/data_stream/test_logs2/fields/fields.yml', + type: 'epm-packages-assets', }, - ], - 'id' - ), - installed_es: sortBy( - [ { - id: 'all_assets', - type: 'ilm_policy', + id: '4acfbf69-7a27-5c58-9c99-7c86843d958f', + path: 'all_assets-0.2.0/data_stream/test_logs/elasticsearch/ingest_pipeline/default.yml', + type: 'epm-packages-assets', }, { - id: 'default', - type: 'ml_model', + id: '5a080eba-f482-545c-8695-6ccbd426b2a2', + path: 'all_assets-0.2.0/data_stream/test_metrics/fields/ecs.yml', + type: 'epm-packages-assets', }, { - id: 'logs-all_assets.test_logs-all_assets', - type: 'data_stream_ilm_policy', + id: '5c3aa147-089c-5084-beca-53c00e72ac80', + path: 'all_assets-0.2.0/docs/README.md', + type: 'epm-packages-assets', }, { - id: 'logs-all_assets.test_logs-0.2.0', - type: 'ingest_pipeline', + id: '64239d25-be40-5e10-94b5-f6b74b8c5474', + path: 'all_assets-0.2.0/data_stream/test_logs/manifest.yml', + type: 'epm-packages-assets', }, { - id: 'logs-all_assets.test_logs-0.2.0-pipeline1', - type: 'ingest_pipeline', + id: '6a87d1a5-adf8-5a30-82c4-4c3b8298272b', + path: 'all_assets-0.2.0/kibana/osquery_saved_query/sample_osquery_saved_query.json', + type: 'epm-packages-assets', }, { - id: 'logs-all_assets.test_logs2-0.2.0', - type: 'ingest_pipeline', + id: '7f4c5aca-b4f5-5f0a-95af-051da37513fc', + path: 'all_assets-0.2.0/kibana/lens/sample_lens.json', + type: 'epm-packages-assets', }, { - id: 'metrics-all_assets.test_metrics-0.2.0', - type: 'ingest_pipeline', + id: '7f97600c-d983-53e0-ae2a-a59bf35d7f0d', + path: 'all_assets-0.2.0/kibana/csp_rule_template/sample_csp_rule_template.json', + type: 'epm-packages-assets', }, { - id: 'logs-all_assets.test_logs', - type: 'index_template', + id: '848d7b69-26d1-52c1-8afc-65e627b34812', + path: 'all_assets-0.2.0/kibana/security_ai_prompt/sample_security_ai_prompts.json', + type: 'epm-packages-assets', }, { - id: 'logs-all_assets.test_logs@package', - type: 'component_template', + id: '8c665f28-a439-5f43-b5fd-8fda7b576735', + path: 'all_assets-0.2.0/manifest.yml', + type: 'epm-packages-assets', }, { - id: 'logs@custom', - type: 'component_template', + id: '938655df-b339-523c-a9e4-123c89c0e1e1', + path: 'all_assets-0.2.0/data_stream/test_logs/elasticsearch/ingest_pipeline/pipeline1.yml', + type: 'epm-packages-assets', }, { - id: 'all_assets@custom', - type: 'component_template', + id: 'bf3b0b65-9fdc-53c6-a9ca-e76140e56490', + path: 'all_assets-0.2.0/kibana/dashboard/sample_dashboard.json', + type: 'epm-packages-assets', }, { - id: 'logs-all_assets.test_logs@custom', - type: 'component_template', + id: 'c5eaf69c-2dab-5678-a6e5-e586db4f3728', + path: 'all_assets-0.2.0/kibana/alerting_rule_template/sample_alerting_rule_template.json', + type: 'epm-packages-assets', }, { - id: 'logs-all_assets.test_logs2', - type: 'index_template', + id: 'c7bf1a39-e057-58a0-afde-fb4b48751d8c', + path: 'all_assets-0.2.0/kibana/visualization/sample_visualization.json', + type: 'epm-packages-assets', }, { - id: 'logs-all_assets.test_logs2@package', - type: 'component_template', + id: 'cb0bbdd7-e043-508b-91c0-09e4cc0f5a3c', + path: 'all_assets-0.2.0/kibana/osquery_pack_asset/sample_osquery_pack_asset.json', + type: 'epm-packages-assets', }, { - id: 'logs-all_assets.test_logs2@custom', - type: 'component_template', + id: 'cc1e3e1d-f27b-5d05-86f6-6e4b9a47c7dc', + path: 'all_assets-0.2.0/data_stream/test_metrics/manifest.yml', + type: 'epm-packages-assets', }, { - id: 'metrics-all_assets.test_metrics', - type: 'index_template', + id: 'd2f87071-c866-503a-8fcb-7b23a8c7afbf', + path: 'all_assets-0.2.0/data_stream/test_logs2/manifest.yml', + type: 'epm-packages-assets', }, { - id: 'metrics-all_assets.test_metrics@package', - type: 'component_template', + id: 'e6ae7d31-6920-5408-9219-91ef1662044b', + path: 'all_assets-0.2.0/kibana/tag/sample_tag.json', + type: 'epm-packages-assets', }, { - id: 'metrics@custom', - type: 'component_template', + id: 'eec4606c-dbfa-565b-8e9c-fce1e641f3fc', + path: 'all_assets-0.2.0/data_stream/test_logs/fields/ecs.yml', + type: 'epm-packages-assets', }, { - id: 'metrics-all_assets.test_metrics@custom', - type: 'component_template', + id: 'ef67e7e0-dca3-5a62-a42a-745db5ad7c1f', + path: 'all_assets-0.2.0/data_stream/test_logs/fields/fields.yml', + type: 'epm-packages-assets', }, { - id: 'all_assets-README.md', - type: 'knowledge_base', + id: 'f8da8ce3-77bb-5fa9-ad05-9f362684d494', + path: 'all_assets-0.2.0/elasticsearch/esql_view/test_query.yml', + type: 'epm-packages-assets', }, ], - 'id' - ), - es_index_patterns: { - test_logs: 'logs-all_assets.test_logs-*', - test_metrics: 'metrics-all_assets.test_metrics-*', - }, - package_assets: [ - { - id: '071b5113-4c9f-5ee9-aafe-d098a4c066f6', - path: 'all_assets-0.2.0/data_stream/test_logs2/fields/ecs.yml', - type: 'epm-packages-assets', - }, - { - id: '0c8c3c6a-90cb-5f0e-8359-d807785b046c', - path: 'all_assets-0.2.0/elasticsearch/ml_model/test/default.json', - type: 'epm-packages-assets', - }, - { - id: '28523a82-1328-578d-84cb-800970560200', - path: 'all_assets-0.2.0/data_stream/test_metrics/fields/fields.yml', - type: 'epm-packages-assets', - }, - { - id: '2e56f08b-1d06-55ed-abee-4708e1ccf0aa', - path: 'all_assets-0.2.0/kibana/search/sample_search2.json', - type: 'epm-packages-assets', - }, - { - id: '3eb4c54a-638f-51b6-84e2-d53f5a666e37', - path: 'all_assets-0.2.0/data_stream/test_logs/elasticsearch/ilm_policy/all_assets.json', - type: 'epm-packages-assets', - }, - { - id: '4035007b-9c33-5227-9803-2de8a17523b5', - path: 'all_assets-0.2.0/kibana/security_rule/sample_security_rule.json', - type: 'epm-packages-assets', - }, - { - id: '4281a436-45a8-54ab-9724-fda6849f789d', - path: 'all_assets-0.2.0/kibana/ml_module/sample_ml_module.json', - type: 'epm-packages-assets', - }, - { - id: '48e582df-b1d2-5f88-b6ea-ba1fafd3a569', - path: 'all_assets-0.2.0/img/logo_overrides_64_color.svg', - type: 'epm-packages-assets', - }, - { - id: '498d8215-2613-5399-9a13-fa4f0bf513e2', - path: 'all_assets-0.2.0/data_stream/test_logs2/fields/fields.yml', - type: 'epm-packages-assets', - }, - { - id: '4acfbf69-7a27-5c58-9c99-7c86843d958f', - path: 'all_assets-0.2.0/data_stream/test_logs/elasticsearch/ingest_pipeline/default.yml', - type: 'epm-packages-assets', - }, - { - id: '5a080eba-f482-545c-8695-6ccbd426b2a2', - path: 'all_assets-0.2.0/data_stream/test_metrics/fields/ecs.yml', - type: 'epm-packages-assets', - }, - { - id: '5c3aa147-089c-5084-beca-53c00e72ac80', - path: 'all_assets-0.2.0/docs/README.md', - type: 'epm-packages-assets', - }, - { - id: '64239d25-be40-5e10-94b5-f6b74b8c5474', - path: 'all_assets-0.2.0/data_stream/test_logs/manifest.yml', - type: 'epm-packages-assets', - }, - { - id: '6a87d1a5-adf8-5a30-82c4-4c3b8298272b', - path: 'all_assets-0.2.0/kibana/osquery_saved_query/sample_osquery_saved_query.json', - type: 'epm-packages-assets', - }, - { - id: '7f4c5aca-b4f5-5f0a-95af-051da37513fc', - path: 'all_assets-0.2.0/kibana/lens/sample_lens.json', - type: 'epm-packages-assets', - }, - { - id: '7f97600c-d983-53e0-ae2a-a59bf35d7f0d', - path: 'all_assets-0.2.0/kibana/csp_rule_template/sample_csp_rule_template.json', - type: 'epm-packages-assets', - }, - { - id: '848d7b69-26d1-52c1-8afc-65e627b34812', - path: 'all_assets-0.2.0/kibana/security_ai_prompt/sample_security_ai_prompts.json', - type: 'epm-packages-assets', - }, - { - id: '8c665f28-a439-5f43-b5fd-8fda7b576735', - path: 'all_assets-0.2.0/manifest.yml', - type: 'epm-packages-assets', - }, - { - id: '938655df-b339-523c-a9e4-123c89c0e1e1', - path: 'all_assets-0.2.0/data_stream/test_logs/elasticsearch/ingest_pipeline/pipeline1.yml', - type: 'epm-packages-assets', - }, - { - id: 'bf3b0b65-9fdc-53c6-a9ca-e76140e56490', - path: 'all_assets-0.2.0/kibana/dashboard/sample_dashboard.json', - type: 'epm-packages-assets', - }, - { - id: 'c5eaf69c-2dab-5678-a6e5-e586db4f3728', - path: 'all_assets-0.2.0/kibana/alerting_rule_template/sample_alerting_rule_template.json', - type: 'epm-packages-assets', - }, - { - id: 'c7bf1a39-e057-58a0-afde-fb4b48751d8c', - path: 'all_assets-0.2.0/kibana/visualization/sample_visualization.json', - type: 'epm-packages-assets', - }, - { - id: 'cb0bbdd7-e043-508b-91c0-09e4cc0f5a3c', - path: 'all_assets-0.2.0/kibana/osquery_pack_asset/sample_osquery_pack_asset.json', - type: 'epm-packages-assets', - }, - { - id: 'cc1e3e1d-f27b-5d05-86f6-6e4b9a47c7dc', - path: 'all_assets-0.2.0/data_stream/test_metrics/manifest.yml', - type: 'epm-packages-assets', - }, - { - id: 'd2f87071-c866-503a-8fcb-7b23a8c7afbf', - path: 'all_assets-0.2.0/data_stream/test_logs2/manifest.yml', - type: 'epm-packages-assets', - }, - { - id: 'e6ae7d31-6920-5408-9219-91ef1662044b', - path: 'all_assets-0.2.0/kibana/tag/sample_tag.json', - type: 'epm-packages-assets', - }, - { - id: 'eec4606c-dbfa-565b-8e9c-fce1e641f3fc', - path: 'all_assets-0.2.0/data_stream/test_logs/fields/ecs.yml', - type: 'epm-packages-assets', - }, - { - id: 'ef67e7e0-dca3-5a62-a42a-745db5ad7c1f', - path: 'all_assets-0.2.0/data_stream/test_logs/fields/fields.yml', - type: 'epm-packages-assets', - }, - { - id: 'f8da8ce3-77bb-5fa9-ad05-9f362684d494', - path: 'all_assets-0.2.0/elasticsearch/esql_view/test_query.yml', - type: 'epm-packages-assets', - }, - ], - name: 'all_assets', - version: '0.2.0', - install_version: '0.2.0', - install_status: 'installed', - install_started_at: res.attributes.install_started_at, - install_source: 'registry', - install_format_schema_version: FLEET_INSTALL_FORMAT_VERSION, - latest_install_failed_attempts: [], - rolled_back: false, - verification_status: 'unknown', - verification_key_id: null, - previous_version: '0.1.0', + name: 'all_assets', + version: '0.2.0', + install_version: '0.2.0', + install_status: 'installed', + install_started_at: res.attributes.install_started_at, + install_source: 'registry', + install_format_schema_version: FLEET_INSTALL_FORMAT_VERSION, + latest_install_failed_attempts: [], + rolled_back: false, + verification_status: 'unknown', + verification_key_id: null, + previous_version: '0.1.0', + }; + + expectedSO.installed_es.forEach((item) => { + expect( + res.attributes.installed_es.find( + (asset: any) => asset.type === item.type && asset.id === item.id + ) + ).to.not.be(undefined); + }); + + expect({ + ...res.attributes, + installed_kibana: sortBy(res.attributes.installed_kibana, ['id']), + package_assets: sortBy(res.attributes.package_assets, ['id']), + installed_es: [], + }).eql({ ...expectedSO, installed_es: [] }); }); }); diff --git a/x-pack/platform/test/fleet_api_integration/apis/package_policy/input_package_create_upgrade.ts b/x-pack/platform/test/fleet_api_integration/apis/package_policy/input_package_create_upgrade.ts index 798a8c75463e6..ad40cb6684252 100644 --- a/x-pack/platform/test/fleet_api_integration/apis/package_policy/input_package_create_upgrade.ts +++ b/x-pack/platform/test/fleet_api_integration/apis/package_policy/input_package_create_upgrade.ts @@ -194,12 +194,9 @@ export default function (providerContext: FtrProviderContext) { it('should not have created any ES assets on install', async () => { const installation = await getInstallationInfo(supertest, PACKAGE_NAME, START_VERSION); - expect(installation.installed_es).to.eql([ - { - id: 'input_package_upgrade-README.md', - type: 'knowledge_base', - }, - ]); + expect( + installation.installed_es.filter((item: any) => item.type !== 'knowledge_base') + ).to.eql([]); }); it('should create index templates and update installed_es on package policy creation', async () => { diff --git a/x-pack/platform/test/fleet_api_integration/apis/package_policy/input_package_rollback.ts b/x-pack/platform/test/fleet_api_integration/apis/package_policy/input_package_rollback.ts index 006f048f40bc9..0e349cabfbaba 100644 --- a/x-pack/platform/test/fleet_api_integration/apis/package_policy/input_package_rollback.ts +++ b/x-pack/platform/test/fleet_api_integration/apis/package_policy/input_package_rollback.ts @@ -19,6 +19,7 @@ export default function (providerContext: FtrProviderContext) { const { getService } = providerContext; const supertest = getService('supertest'); const fleetAndAgents = getService('fleetAndAgents'); + const retry = getService('retry'); const uninstallPackage = async (name: string, version: string) => { await supertest.delete(`/api/fleet/epm/packages/${name}/${version}`).set('kbn-xsrf', 'xxxx'); @@ -128,15 +129,15 @@ export default function (providerContext: FtrProviderContext) { await installPackage(PACKAGE_NAME, START_VERSION); await createPackagePolicyWithDataset(agentPolicyId, 'test*', 400); - await new Promise((resolve) => setTimeout(resolve, 1000)); - - const installation = await getInstallationInfo(supertest, PACKAGE_NAME, START_VERSION); - expectIdArraysEqual(installation.installed_es, [ - { - id: 'input_package_upgrade-README.md', - type: 'knowledge_base', - }, - ]); + await retry.tryForTime(10000, async () => { + const installation = await getInstallationInfo(supertest, PACKAGE_NAME, START_VERSION); + expectIdArraysEqual(installation.installed_es, [ + { + id: 'input_package_upgrade-README.md', + type: 'knowledge_base', + }, + ]); + }); await uninstallPackage(PACKAGE_NAME, START_VERSION); }); diff --git a/x-pack/platform/test/fleet_api_integration/apis/package_policy/update.ts b/x-pack/platform/test/fleet_api_integration/apis/package_policy/update.ts index 6af9da093acb4..baf5410ef609c 100644 --- a/x-pack/platform/test/fleet_api_integration/apis/package_policy/update.ts +++ b/x-pack/platform/test/fleet_api_integration/apis/package_policy/update.ts @@ -21,6 +21,7 @@ export default function (providerContext: FtrProviderContext) { const kibanaServer = getService('kibanaServer'); const esArchiver = getService('esArchiver'); const es = getService('es'); + const retry = getService('retry'); const expectIdArraysEqual = (arr1: any[], arr2: any[]) => { expect(sortBy(arr1, 'id')).to.eql(sortBy(arr2, 'id')); @@ -969,22 +970,28 @@ export default function (providerContext: FtrProviderContext) { }) .expect(200); - const installation = await getInstallationInfo(supertest, 'integration_to_input', '2.0.0'); - - expectIdArraysEqual(installation.installed_es, [ - // assets from version 1.0.0 - { id: 'logs-integration_to_input.log', type: 'index_template' }, - { id: 'logs-integration_to_input.log-1.0.0', type: 'ingest_pipeline' }, - { id: 'logs-integration_to_input.log@custom', type: 'component_template' }, - { id: 'logs-integration_to_input.log@package', type: 'component_template' }, - // assets from version 2.0.0 for new package policy - { id: 'logs-somedataset-2.0.0', type: 'ingest_pipeline' }, - { id: 'logs-somedataset', type: 'index_template' }, - { id: 'logs-somedataset@package', type: 'component_template' }, - { id: 'logs-somedataset@custom', type: 'component_template' }, - { id: 'logs@custom', type: 'component_template' }, - { id: 'integration_to_input@custom', type: 'component_template' }, - ]); + await retry.tryForTime(10000, async () => { + const installation = await getInstallationInfo( + supertest, + 'integration_to_input', + '2.0.0' + ); + + expectIdArraysEqual(installation.installed_es, [ + // assets from version 1.0.0 + { id: 'logs-integration_to_input.log', type: 'index_template' }, + { id: 'logs-integration_to_input.log-1.0.0', type: 'ingest_pipeline' }, + { id: 'logs-integration_to_input.log@custom', type: 'component_template' }, + { id: 'logs-integration_to_input.log@package', type: 'component_template' }, + // assets from version 2.0.0 for new package policy + { id: 'logs-somedataset-2.0.0', type: 'ingest_pipeline' }, + { id: 'logs-somedataset', type: 'index_template' }, + { id: 'logs-somedataset@package', type: 'component_template' }, + { id: 'logs-somedataset@custom', type: 'component_template' }, + { id: 'logs@custom', type: 'component_template' }, + { id: 'integration_to_input@custom', type: 'component_template' }, + ]); + }); const dataset3PkgComponentTemplate = await getComponentTemplate('logs-somedataset@package'); expect(dataset3PkgComponentTemplate).not.to.be(null); diff --git a/x-pack/platform/test/fleet_api_integration/apis/package_policy/upgrade.ts b/x-pack/platform/test/fleet_api_integration/apis/package_policy/upgrade.ts index 966cb60de212f..1d81a2189063d 100644 --- a/x-pack/platform/test/fleet_api_integration/apis/package_policy/upgrade.ts +++ b/x-pack/platform/test/fleet_api_integration/apis/package_policy/upgrade.ts @@ -9,15 +9,10 @@ import type { UpgradePackagePolicyDryRunResponse, UpgradePackagePolicyResponse, } from '@kbn/fleet-plugin/common/types'; -import { sortBy } from 'lodash'; import type { FtrProviderContext } from '../../../api_integration/ftr_provider_context'; import { skipIfNoDockerRegistry } from '../../helpers'; import { getInstallationInfo } from './helper'; -const expectIdArraysEqual = (arr1: any[], arr2: any[]) => { - expect(sortBy(arr1, 'id')).to.eql(sortBy(arr2, 'id')); -}; - export default function (providerContext: FtrProviderContext) { const { getService } = providerContext; const supertest = getService('supertest'); @@ -25,6 +20,7 @@ export default function (providerContext: FtrProviderContext) { const kibanaServer = getService('kibanaServer'); const es = getService('es'); const fleetAndAgents = getService('fleetAndAgents'); + const retry = getService('retry'); function withTestPackage(name: string, version: string) { const pkgRoute = `/api/fleet/epm/packages/${name}/${version}`; @@ -51,8 +47,7 @@ export default function (providerContext: FtrProviderContext) { } }; - // Failing: See https://github.com/elastic/kibana/issues/246204 - describe.skip('Package Policy - upgrade', function () { + describe('Package Policy - upgrade', function () { skipIfNoDockerRegistry(providerContext); let agentPolicyId: string; let packagePolicyId: string; @@ -1250,7 +1245,6 @@ export default function (providerContext: FtrProviderContext) { } expectedAssets.push({ id: 'logs@custom', type: 'component_template' }); - expectedAssets.push({ id: 'integration_to_input-README.md', type: 'knowledge_base' }); expectedAssets.push({ id: 'integration_to_input@custom', type: 'component_template' }); }); @@ -1285,12 +1279,20 @@ export default function (providerContext: FtrProviderContext) { }) .expect(200); - const installation = await getInstallationInfo( - supertest, - 'integration_to_input', - '3.0.0' - ); - expectIdArraysEqual(installation.installed_es, expectedAssets); + await retry.tryForTime(10000, async () => { + const installation = await getInstallationInfo( + supertest, + 'integration_to_input', + '3.0.0' + ); + expectedAssets.forEach((item) => { + expect( + installation.installed_es.find( + (asset: any) => asset.type === item.type && asset.id === item.id + ) + ).to.eql(item, `Expected asset not found: ${item.type}:${item.id}`); + }); + }); const expectedComponentTemplates = expectedAssets.filter( (expectedAsset) => diff --git a/x-pack/platform/test/fleet_api_integration/apis/settings/global_settings.ts b/x-pack/platform/test/fleet_api_integration/apis/settings/global_settings.ts index 421e8fe59373a..95858fe510a74 100644 --- a/x-pack/platform/test/fleet_api_integration/apis/settings/global_settings.ts +++ b/x-pack/platform/test/fleet_api_integration/apis/settings/global_settings.ts @@ -18,6 +18,7 @@ export default function (providerContext: FtrProviderContext) { const kibanaServer = getService('kibanaServer'); const fleetAndAgents = getService('fleetAndAgents'); const apiClient = new SpaceTestApiClient(supertest); + const retry = getService('retry'); describe('Global Settings', function () { skipIfNoDockerRegistry(providerContext); @@ -61,17 +62,17 @@ export default function (providerContext: FtrProviderContext) { const updatedSettings = await apiClient.getSettings(); expect(updatedSettings.item.integration_knowledge_enabled).to.be(true); - await new Promise((resolve) => setTimeout(resolve, 3000)); - - const response = await apiClient.getPackage({ - pkgName: 'knowledge_base_test', - pkgVersion: '1.0.0', + await retry.tryForTime(10000, async () => { + const response = await apiClient.getPackage({ + pkgName: 'knowledge_base_test', + pkgVersion: '1.0.0', + }); + expect( + response.item.installationInfo?.installed_es.some( + (esAsset) => esAsset.type === 'knowledge_base' + ) + ).to.be(true); }); - expect( - response.item.installationInfo?.installed_es.some( - (esAsset) => esAsset.type === 'knowledge_base' - ) - ).to.be(true); }); }); }