Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Telemetry][Security Solution] Fix integration tests on branch 9.0 #192842

Merged
merged 4 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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: {
Expand All @@ -282,14 +288,28 @@ export async function createAgentPolicy(
],
};

await soClient.create<unknown>(LEGACY_AGENT_POLICY_SAVED_OBJECT_TYPE, {}, { id }).catch(() => {});
await packagePolicyService
.create(soClient, esClient, packagePolicy, {
id,
spaceId: 'default',
bumpRevision: false,
})
.catch(() => {});
await soClient.get<unknown>(LEGACY_AGENT_POLICY_SAVED_OBJECT_TYPE, id).catch(async (e) => {
try {
return await soClient.create<unknown>(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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down