From 2d259559587c0b92dc8b2546291cc3923471982e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Zaffarano?= Date: Fri, 13 Sep 2024 13:31:11 -0300 Subject: [PATCH] [Telemetry][Security Solution] Fix integration tests on branch 9.0 (#192842) ## Summary Follow up of https://github.com/elastic/kibana/pull/192040 and https://github.com/elastic/kibana/issues/192624 The issue was while installing the agent policy because the `endpoint` package is not listed in the EPR for kibana 9+. The fix is to disable `kibanaVersionCheck`. --- .../lib/telemetry_helpers.ts | 38 +++++++++++++---- .../integration_tests/telemetry.test.ts | 41 +++++++++++-------- 2 files changed, 53 insertions(+), 26 deletions(-) diff --git a/x-pack/plugins/security_solution/server/integration_tests/lib/telemetry_helpers.ts b/x-pack/plugins/security_solution/server/integration_tests/lib/telemetry_helpers.ts index 2b1b5f2809dde9d..d83ff1e910ca5fe 100644 --- a/x-pack/plugins/security_solution/server/integration_tests/lib/telemetry_helpers.ts +++ b/x-pack/plugins/security_solution/server/integration_tests/lib/telemetry_helpers.ts @@ -16,6 +16,7 @@ import type { ExceptionListSchema, } from '@kbn/securitysolution-io-ts-list-types'; import { asyncForEach } from '@kbn/std'; +import { ToolingLog } from '@kbn/tooling-log'; import { createExceptionList, @@ -54,6 +55,11 @@ const endpointMetricsMetadataIndex = '.ds-metrics-endpoint.metadata-1'; const endpointMetricsPolicyIndex = '.ds-metrics-endpoint.policy-1'; const prebuiltRulesIndex = '.alerts-security.alerts'; +const logger = new ToolingLog({ + level: 'info', + writeTo: process.stdout, +}); + export function getTelemetryTasks( spy: jest.SpyInstance< SecuritySolutionPluginStart, @@ -259,7 +265,7 @@ export async function createAgentPolicy( enabled: true, policy_id: 'policy-elastic-agent-on-cloud', policy_ids: ['policy-elastic-agent-on-cloud'], - package: { name: 'endpoint', title: 'Elastic Endpoint', version: '9.0.0' }, + package: { name: 'endpoint', title: 'Elastic Endpoint', version: '8.15.1' }, inputs: [ { config: { @@ -282,14 +288,28 @@ export async function createAgentPolicy( ], }; - await soClient.create(LEGACY_AGENT_POLICY_SAVED_OBJECT_TYPE, {}, { id }).catch(() => {}); - await packagePolicyService - .create(soClient, esClient, packagePolicy, { - id, - spaceId: 'default', - bumpRevision: false, - }) - .catch(() => {}); + await soClient.get(LEGACY_AGENT_POLICY_SAVED_OBJECT_TYPE, id).catch(async (e) => { + try { + return await soClient.create(LEGACY_AGENT_POLICY_SAVED_OBJECT_TYPE, {}, { id }); + } catch { + logger.error(`>> Error searching for agent: ${e}`); + throw Error(`>> Error searching for agent: ${e}`); + } + }); + + await packagePolicyService.get(soClient, id).catch(async () => { + try { + return await packagePolicyService.create(soClient, esClient, packagePolicy, { + id, + spaceId: 'default', + bumpRevision: false, + force: true, + }); + } catch (e) { + logger.error(`>> Error creating package policy: ${e}`); + throw Error(`>> Error creating package policy: ${e}`); + } + }); } export async function createMockedExceptionList(so: SavedObjectsServiceStart) { diff --git a/x-pack/plugins/security_solution/server/integration_tests/telemetry.test.ts b/x-pack/plugins/security_solution/server/integration_tests/telemetry.test.ts index e4899f06eeb31bc..801926adbf9482f 100644 --- a/x-pack/plugins/security_solution/server/integration_tests/telemetry.test.ts +++ b/x-pack/plugins/security_solution/server/integration_tests/telemetry.test.ts @@ -85,7 +85,20 @@ describe('telemetry tasks', () => { beforeAll(async () => { await removeFile(logFilePath); - const servers = await setupTestServers(logFilePath); + const servers = await setupTestServers(logFilePath, { + xpack: { + fleet: { + internal: { + registry: { + // Since `endpoint` is not available in EPR yet for + // kibana 9 (e.g., https://epr.elastic.co/search?package=endpoint&kibana.version=9.0.0) + // we need to ignore version checks + kibanaVersionCheckEnabled: false, + }, + }, + }, + }, + }); esServer = servers.esServer; kibanaServer = servers.kibanaServer; @@ -311,9 +324,8 @@ describe('telemetry tasks', () => { expect(body.endpoint_metrics).toStrictEqual(endpointMetaTelemetryRequest.endpoint_metrics); expect(body.endpoint_meta).toStrictEqual(endpointMetaTelemetryRequest.endpoint_meta); - // TODO(szaffarano) Failing 9.0 version update: https://github.com/elastic/kibana/issues/192624 - // expect(body.policy_config).toStrictEqual(endpointMetaTelemetryRequest.policy_config); - // expect(body.policy_response).toStrictEqual(endpointMetaTelemetryRequest.policy_response); + expect(body.policy_config).toStrictEqual(endpointMetaTelemetryRequest.policy_config); + expect(body.policy_response).toStrictEqual(endpointMetaTelemetryRequest.policy_response); }); it('should manage runtime errors searching endpoint metrics', async () => { @@ -509,8 +521,7 @@ describe('telemetry tasks', () => { expect(body.endpoint_metrics).toStrictEqual(endpointMetaTelemetryRequest.endpoint_metrics); expect(body.endpoint_meta).toStrictEqual(endpointMetaTelemetryRequest.endpoint_meta); - // TODO(szaffarano) Failing 9.0 version update: https://github.com/elastic/kibana/issues/192624 - // expect(body.policy_config).toStrictEqual(endpointMetaTelemetryRequest.policy_config); + expect(body.policy_config).toStrictEqual(endpointMetaTelemetryRequest.policy_config); expect(body.policy_response).toStrictEqual({}); const requests = await getTaskMetricsRequests(task, started); @@ -542,8 +553,7 @@ describe('telemetry tasks', () => { expect(body.endpoint_metrics).toStrictEqual(endpointMetaTelemetryRequest.endpoint_metrics); expect(body.endpoint_meta).toStrictEqual(endpointMetaTelemetryRequest.endpoint_meta); - // TODO(szaffarano) Failing 9.0 version update: https://github.com/elastic/kibana/issues/192624 - // expect(body.policy_config).toStrictEqual(endpointMetaTelemetryRequest.policy_config); + expect(body.policy_config).toStrictEqual(endpointMetaTelemetryRequest.policy_config); expect(body.policy_response).toStrictEqual({}); const requests = await getTaskMetricsRequests(task, started); @@ -579,9 +589,8 @@ describe('telemetry tasks', () => { ...endpointMetaTelemetryRequest.endpoint_meta, capabilities: [], }); - // TODO(szaffarano) Failing 9.0 version update: https://github.com/elastic/kibana/issues/192624 - // expect(body.policy_config).toStrictEqual(endpointMetaTelemetryRequest.policy_config); - // expect(body.policy_response).toStrictEqual(endpointMetaTelemetryRequest.policy_response); + expect(body.policy_config).toStrictEqual(endpointMetaTelemetryRequest.policy_config); + expect(body.policy_response).toStrictEqual(endpointMetaTelemetryRequest.policy_response); const requests = await getTaskMetricsRequests(task, started); @@ -615,9 +624,8 @@ describe('telemetry tasks', () => { ...endpointMetaTelemetryRequest.endpoint_meta, capabilities: [], }); - // TODO(szaffarano) Failing 9.0 version update: https://github.com/elastic/kibana/issues/192624 - // expect(body.policy_config).toStrictEqual(endpointMetaTelemetryRequest.policy_config); - // expect(body.policy_response).toStrictEqual(endpointMetaTelemetryRequest.policy_response); + expect(body.policy_config).toStrictEqual(endpointMetaTelemetryRequest.policy_config); + expect(body.policy_response).toStrictEqual(endpointMetaTelemetryRequest.policy_response); const requests = await getTaskMetricsRequests(task, started); @@ -661,9 +669,8 @@ describe('telemetry tasks', () => { expect(body.endpoint_metrics).toStrictEqual(endpointMetaTelemetryRequest.endpoint_metrics); expect(body.endpoint_meta).toStrictEqual(endpointMetaTelemetryRequest.endpoint_meta); - // TODO(szaffarano) Failing 9.0 version update: https://github.com/elastic/kibana/issues/192624 - // expect(body.policy_config).toStrictEqual(endpointMetaTelemetryRequest.policy_config); - // expect(body.policy_response).toStrictEqual(endpointMetaTelemetryRequest.policy_response); + expect(body.policy_config).toStrictEqual(endpointMetaTelemetryRequest.policy_config); + expect(body.policy_response).toStrictEqual(endpointMetaTelemetryRequest.policy_response); const requests = await getTaskMetricsRequests(task, started);