Skip to content

Commit

Permalink
[Telemetry][Security Solution] Fix integration tests on branch 9.0 (#…
Browse files Browse the repository at this point in the history
…192842)

## Summary

Follow up of #192040 and
#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`.
  • Loading branch information
szaffarano authored Sep 13, 2024
1 parent 3d4b362 commit 9681b9d
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 26 deletions.
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

0 comments on commit 9681b9d

Please sign in to comment.