From b2dc03f7b84590a62de0a038809bfe16a7b4eada Mon Sep 17 00:00:00 2001 From: Ashokaditya Date: Tue, 26 Sep 2023 10:45:26 +0200 Subject: [PATCH 1/5] unskip metadata API ftr test fixes elastic/kibana/issues/151854 --- .../apis/index.ts | 8 ++++++-- .../apis/metadata.ts | 19 +++++++++---------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/x-pack/test/security_solution_endpoint_api_int/apis/index.ts b/x-pack/test/security_solution_endpoint_api_int/apis/index.ts index e68db8182da20..06d54f0aaac45 100644 --- a/x-pack/test/security_solution_endpoint_api_int/apis/index.ts +++ b/x-pack/test/security_solution_endpoint_api_int/apis/index.ts @@ -7,7 +7,7 @@ import { getRegistryUrl as getRegistryUrlFromIngest } from '@kbn/fleet-plugin/server'; import { FtrProviderContext } from '../ftr_provider_context'; -import { isRegistryEnabled, getRegistryUrlFromTestEnv } from '../registry'; +import { getRegistryUrlFromTestEnv, isRegistryEnabled } from '../registry'; import { ROLE } from '../services/roles_users'; export default function endpointAPIIntegrationTests(providerContext: FtrProviderContext) { @@ -28,7 +28,11 @@ export default function endpointAPIIntegrationTests(providerContext: FtrProvider const roles = Object.values(ROLE); before(async () => { - await ingestManager.setup(); + try { + await ingestManager.setup(); + } catch (err) { + log.warning(`Error setting up ingestManager: ${err}`); + } // create role/user for (const role of roles) { diff --git a/x-pack/test/security_solution_endpoint_api_int/apis/metadata.ts b/x-pack/test/security_solution_endpoint_api_int/apis/metadata.ts index c4778f7039a91..86cc747ea855f 100644 --- a/x-pack/test/security_solution_endpoint_api_int/apis/metadata.ts +++ b/x-pack/test/security_solution_endpoint_api_int/apis/metadata.ts @@ -9,14 +9,14 @@ import { v4 as uuidv4 } from 'uuid'; import expect from '@kbn/expect'; import { TransformGetTransformStatsTransformStats } from '@elastic/elasticsearch/lib/api/types'; import { - METADATA_DATASTREAM, + ENDPOINT_DEFAULT_SORT_DIRECTION, + ENDPOINT_DEFAULT_SORT_FIELD, HOST_METADATA_LIST_ROUTE, + METADATA_DATASTREAM, + METADATA_TRANSFORMS_STATUS_ROUTE, METADATA_UNITED_INDEX, METADATA_UNITED_TRANSFORM, - METADATA_TRANSFORMS_STATUS_ROUTE, metadataTransformPrefix, - ENDPOINT_DEFAULT_SORT_FIELD, - ENDPOINT_DEFAULT_SORT_DIRECTION, } from '@kbn/security-solution-plugin/common/endpoint/constants'; import { AGENTS_INDEX } from '@kbn/fleet-plugin/common'; import { indexFleetEndpointPolicy } from '@kbn/security-solution-plugin/common/endpoint/data_loaders/index_fleet_endpoint_policy'; @@ -29,13 +29,13 @@ import { } from '@kbn/security-solution-plugin/common/endpoint/types'; import { generateAgentDocs, generateMetadataDocs } from './metadata.fixtures'; import { + bulkIndex, + deleteAllDocsFromFleetAgents, + deleteAllDocsFromIndex, deleteAllDocsFromMetadataCurrentIndex, deleteAllDocsFromMetadataDatastream, - stopTransform, startTransform, - deleteAllDocsFromFleetAgents, - deleteAllDocsFromIndex, - bulkIndex, + stopTransform, } from './data_stream_helper'; import { FtrProviderContext } from '../ftr_provider_context'; @@ -43,8 +43,7 @@ export default function ({ getService }: FtrProviderContext) { const supertest = getService('supertest'); const endpointTestResources = getService('endpointTestResources'); - // Failing: See https://github.com/elastic/kibana/issues/151854 - describe.skip('test metadata apis', () => { + describe('test metadata apis', () => { describe('list endpoints GET route', () => { const numberOfHostsInFixture = 2; let agent1Timestamp: number; From 7f24195503d748a564f0b97276ff842c3055c9d0 Mon Sep 17 00:00:00 2001 From: Ashokaditya Date: Tue, 26 Sep 2023 11:08:57 +0200 Subject: [PATCH 2/5] set api version --- x-pack/test/common/services/ingest_manager.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/x-pack/test/common/services/ingest_manager.ts b/x-pack/test/common/services/ingest_manager.ts index 1ef80be40d803..c3187213d905d 100644 --- a/x-pack/test/common/services/ingest_manager.ts +++ b/x-pack/test/common/services/ingest_manager.ts @@ -5,7 +5,8 @@ * 2.0. */ -import { fleetSetupRouteService } from '@kbn/fleet-plugin/common'; +import { API_VERSIONS, fleetSetupRouteService } from '@kbn/fleet-plugin/common'; +import { ELASTIC_HTTP_VERSION_HEADER } from '@kbn/core-http-common'; import { FtrProviderContext } from '../ftr_provider_context'; export function IngestManagerProvider({ getService }: FtrProviderContext) { @@ -18,6 +19,7 @@ export function IngestManagerProvider({ getService }: FtrProviderContext) { await retry.try(async () => { await supertest .post(fleetSetupRouteService.postFleetSetupPath()) + .set(ELASTIC_HTTP_VERSION_HEADER, API_VERSIONS.public.v1) .set(headers) .send({ forceRecreate: true }) .expect(200); From 00c52a59f48ff35d0c7aabfad56f17a76080b9e0 Mon Sep 17 00:00:00 2001 From: Ashokaditya Date: Tue, 26 Sep 2023 12:33:34 +0200 Subject: [PATCH 3/5] update deprecated --- .../apis/data_stream_helper.ts | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/x-pack/test/security_solution_endpoint_api_int/apis/data_stream_helper.ts b/x-pack/test/security_solution_endpoint_api_int/apis/data_stream_helper.ts index 1caef61bec80c..67115c1610157 100644 --- a/x-pack/test/security_solution_endpoint_api_int/apis/data_stream_helper.ts +++ b/x-pack/test/security_solution_endpoint_api_int/apis/data_stream_helper.ts @@ -8,14 +8,14 @@ import { Client } from '@elastic/elasticsearch'; import { AGENTS_INDEX } from '@kbn/fleet-plugin/common'; import { - metadataIndexPattern, - eventsIndexPattern, alertsIndexPattern, - policyIndexPattern, + eventsIndexPattern, + METADATA_DATASTREAM, + METADATA_UNITED_INDEX, metadataCurrentIndexPattern, + metadataIndexPattern, + policyIndexPattern, telemetryIndexPattern, - METADATA_UNITED_INDEX, - METADATA_DATASTREAM, } from '@kbn/security-solution-plugin/common/endpoint/constants'; export function deleteDataStream(getService: (serviceName: 'es') => Client, index: string) { @@ -38,10 +38,8 @@ export async function deleteAllDocsFromIndex( const client = getService('es'); await client.deleteByQuery( { - body: { - query: { - match_all: {}, - }, + query: { + match_all: {}, }, index, wait_for_completion: true, @@ -132,12 +130,12 @@ export function bulkIndex( index: string, docs: unknown[] ) { - const body = docs.flatMap((doc) => [{ create: { _index: index } }, doc]); + const operations = docs.flatMap((doc) => [{ create: { _index: index } }, doc]); const client = getService('es'); return client.bulk({ index, refresh: 'wait_for', - body, + operations, }); } From 8f569279bf699793102810466984e3770162f483 Mon Sep 17 00:00:00 2001 From: Ashokaditya Date: Tue, 26 Sep 2023 14:10:18 +0200 Subject: [PATCH 4/5] log delete docs from metadata index --- .../security_solution_endpoint_api_int/apis/metadata.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/x-pack/test/security_solution_endpoint_api_int/apis/metadata.ts b/x-pack/test/security_solution_endpoint_api_int/apis/metadata.ts index 86cc747ea855f..a015cf693895e 100644 --- a/x-pack/test/security_solution_endpoint_api_int/apis/metadata.ts +++ b/x-pack/test/security_solution_endpoint_api_int/apis/metadata.ts @@ -42,6 +42,7 @@ import { FtrProviderContext } from '../ftr_provider_context'; export default function ({ getService }: FtrProviderContext) { const supertest = getService('supertest'); const endpointTestResources = getService('endpointTestResources'); + const log = getService('log'); describe('test metadata apis', () => { describe('list endpoints GET route', () => { @@ -54,7 +55,11 @@ export default function ({ getService }: FtrProviderContext) { await deleteAllDocsFromFleetAgents(getService); await deleteAllDocsFromMetadataDatastream(getService); await deleteAllDocsFromMetadataCurrentIndex(getService); - await deleteAllDocsFromIndex(getService, METADATA_UNITED_INDEX); + try { + await deleteAllDocsFromIndex(getService, METADATA_UNITED_INDEX); + } catch (err) { + log.warning(`Unable to delete index: ${err}`); + } const customIndexFn = async (): Promise => { // generate an endpoint policy and attach id to agents since From dff886adfe11a0437044dc90dc50f3ced7b30918 Mon Sep 17 00:00:00 2001 From: Ashokaditya Date: Thu, 28 Sep 2023 10:56:00 +0200 Subject: [PATCH 5/5] fix check types commit diff error --- .../functional/page_objects/infra_hosts_view.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/x-pack/test/functional/page_objects/infra_hosts_view.ts b/x-pack/test/functional/page_objects/infra_hosts_view.ts index 1cd0cf15996ec..152440d349067 100644 --- a/x-pack/test/functional/page_objects/infra_hosts_view.ts +++ b/x-pack/test/functional/page_objects/infra_hosts_view.ts @@ -4,7 +4,12 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ -import { AlertStatus, ALERT_STATUS_ACTIVE, ALERT_STATUS_RECOVERED } from '@kbn/rule-data-utils'; +import { + ALERT_STATUS_ACTIVE, + ALERT_STATUS_RECOVERED, + ALERT_STATUS_UNTRACKED, + AlertStatus, +} from '@kbn/rule-data-utils'; import { WebElementWrapper } from '../../../../test/functional/services/lib/web_element_wrapper'; import { FtrProviderContext } from '../ftr_provider_context'; @@ -200,8 +205,10 @@ export function InfraHostsViewProvider({ getService }: FtrProviderContext) { await alertsTab.click(); }, - setAlertStatusFilter(alertStatus?: AlertStatus) { - const buttons = { + setAlertStatusFilter(alertStatus?: Exclude) { + const buttons: { + [key in Exclude | 'all']: string; + } = { [ALERT_STATUS_ACTIVE]: 'hostsView-alert-status-filter-active-button', [ALERT_STATUS_RECOVERED]: 'hostsView-alert-status-filter-recovered-button', all: 'hostsView-alert-status-filter-show-all-button',